Skip to content

Commit

Permalink
Fix consecutive for loop mappings in commit
Browse files Browse the repository at this point in the history
mapper/orm/src/main/java/org/hibernate/search/mapper/orm/mapping/impl/HibernateOrmTypeContextContainer.java
hibernate/hibernate-search@6133c60

The for loops are in method
private HibernateOrmTypeContextContainer(Builder builder, SessionFactoryImplementor sessionFactory)
  • Loading branch information
tsantalis committed Jan 24, 2025
1 parent 58ff289 commit cbe565a
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ else if(!this.isIdenticalWithInlinedVariable() && o.isIdenticalWithInlinedVariab
else if(identicalCompositeChildren1 < identicalCompositeChildren2) {
return 1;
}
if(this.compositeChildMatchingScore != o.compositeChildMatchingScore) {
if(this.compositeChildMatchingScore != o.compositeChildMatchingScore && this.compositeChildMatchingScore != 0.99) {
return -Double.compare(this.compositeChildMatchingScore, o.compositeChildMatchingScore);
}
else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1617,20 +1617,24 @@ public void testForLoopsWithIdenticalComments() throws Exception {
Assertions.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testConsecutiveForLoops() throws Exception {
@ParameterizedTest
@CsvSource({
"https://github.com/hibernate/hibernate-search.git, 9a25c9dd3e4af54c43878d224c27106384302d25, PojoTypeManagerContainer, hibernate-search-9a25c9dd3e4af54c43878d224c27106384302d25.txt",
"https://github.com/hibernate/hibernate-search.git, 6133c600d0fc15ce3482aaf9c3a29b4a222c98e8, HibernateOrmTypeContextContainer, hibernate-search-6133c600d0fc15ce3482aaf9c3a29b4a222c98e8.txt"
})
public void testConsecutiveForLoops(String url, String commitId, String containerName, String testResultFileName) throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
final List<String> actual = new ArrayList<>();
UMLModelDiff modelDiff = miner.detectAtCommitWithGitHubAPI("https://github.com/hibernate/hibernate-search.git", "9a25c9dd3e4af54c43878d224c27106384302d25", new File(REPOS));
UMLModelDiff modelDiff = miner.detectAtCommitWithGitHubAPI(url, commitId, new File(REPOS));
List<UMLClassDiff> commonClassDiff = modelDiff.getCommonClassDiffList();
for(UMLClassDiff classDiff : commonClassDiff) {
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("PojoTypeManagerContainer") && mapper.getContainer2().getName().equals("PojoTypeManagerContainer")) {
if(mapper.getContainer1().getName().equals(containerName) && mapper.getContainer2().getName().equals(containerName)) {
mapperInfo(mapper, actual);
}
}
}
List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + "hibernate-search-9a25c9dd3e4af54c43878d224c27106384302d25.txt"));
List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + testResultFileName));
Assertions.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3013,6 +3013,23 @@ public void testConsecutiveForLoops() throws Exception {
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testConsecutiveForLoops2() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
final List<String> actual = new ArrayList<>();
UMLModelDiff modelDiff = miner.detectAtCommitWithGitHubAPI("https://github.com/hibernate/hibernate-search.git", "6133c600d0fc15ce3482aaf9c3a29b4a222c98e8", new File(REPOS));
List<UMLClassDiff> commonClassDiff = modelDiff.getCommonClassDiffList();
for(UMLClassDiff classDiff : commonClassDiff) {
for(UMLOperationBodyMapper mapper : classDiff.getOperationBodyMapperList()) {
if(mapper.getContainer1().getName().equals("HibernateOrmTypeContextContainer") && mapper.getContainer2().getName().equals("HibernateOrmTypeContextContainer")) {
mapperInfo(mapper, actual);
}
}
}
List<String> expected = IOUtils.readLines(new FileReader(EXPECTED_PATH + "hibernate-search-6133c600d0fc15ce3482aaf9c3a29b4a222c98e8.txt"));
Assert.assertTrue(expected.size() == actual.size() && expected.containsAll(actual) && actual.containsAll(expected));
}

@Test
public void testAssertMappings() throws Exception {
GitHistoryRefactoringMinerImpl miner = new GitHistoryRefactoringMinerImpl();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
private HibernateOrmTypeContextContainer(builder Builder, sessionFactory SessionFactoryImplementor) -> private HibernateOrmTypeContextContainer(builder Builder, delegate PojoLoadingTypeContextProvider, sessionFactory SessionFactoryImplementor)
line range:47-47==line range:45-45
line range:48-48==line range:46-46
line range:49-49==line range:47-47
line range:50-50==line range:48-48
line range:51-51==line range:49-49
line range:54-54==line range:50-50
line range:57-57==line range:53-53
line range:60-60==line range:55-55
line range:63-63==line range:58-58
line range:64-64==line range:59-59
line range:67-67==line range:62-62
line range:68-68==line range:63-63
line range:71-71==line range:66-66
line range:72-72==line range:67-67
line range:77-77==line range:69-69
line range:81-81==line range:73-73
line range:86-86==line range:76-76
line range:89-89==line range:79-79
line range:92-92==line range:82-82
line range:96-96==line range:84-84
line range:100-101==line range:86-87
line range:101-101==line range:87-87
line range:102-102==line range:88-88
line range:102-102==line range:88-88
line range:103-103==line range:89-89
line range:103-103==line range:89-89
line range:104-104==line range:90-90
line range:104-104==line range:90-90
line range:105-106==line range:91-92
line range:106-106==line range:92-92
line range:109-110==line range:93-94
line range:110-110==line range:94-94
line range:56-56==line range:52-52
line range:80-80==line range:72-72
line range:62-65==line range:57-60
line range:85-87==line range:75-77
line range:55-78==line range:51-70
line range:79-97==line range:71-85
line range:62-65==line range:57-60
line range:85-87==line range:75-77
line range:55-78==line range:51-70
line range:79-97==line range:71-85

0 comments on commit cbe565a

Please sign in to comment.