diff --git a/src/test/java/org/refactoringminer/test/TestRelatedStatementMappingsTest.java b/src/test/java/org/refactoringminer/test/TestRelatedStatementMappingsTest.java index 7e925423d1..53fc6587ac 100644 --- a/src/test/java/org/refactoringminer/test/TestRelatedStatementMappingsTest.java +++ b/src/test/java/org/refactoringminer/test/TestRelatedStatementMappingsTest.java @@ -1,10 +1,8 @@ package org.refactoringminer.test; -import gr.uom.java.xmi.VariableDeclarationContainer; import gr.uom.java.xmi.decomposition.AbstractCodeMapping; import gr.uom.java.xmi.decomposition.LeafExpression; import gr.uom.java.xmi.diff.AssertThrowsRefactoring; -import gr.uom.java.xmi.diff.ModifyClassAnnotationRefactoring; import gr.uom.java.xmi.diff.ModifyMethodAnnotationRefactoring; import org.apache.commons.io.IOUtils; import org.junit.jupiter.api.Assertions; @@ -26,6 +24,7 @@ import java.util.stream.Collectors; import static org.junit.jupiter.api.Assertions.fail; +import static org.refactoringminer.utils.Assertions.assertHasSameElementsAs; public class TestRelatedStatementMappingsTest { public static final String REPOS = System.getProperty("user.dir") + "/src/test/resources/oracle/commits"; @@ -91,7 +90,7 @@ public void handle(String commitId, List refactorings) { Assertions.assertDoesNotThrow(() -> { expected.addAll(IOUtils.readLines(new FileReader(EXPECTED_PATH + testResultFileName))); }, lazyErrorMessage); - Assertions.assertIterableEquals(expected, actual, lazyErrorMessage); + assertHasSameElementsAs(expected, actual, lazyErrorMessage); } private void mapperInfo(Set mappings, T operationBefore, T operationAfter) { diff --git a/src/test/java/org/refactoringminer/utils/Assertions.java b/src/test/java/org/refactoringminer/utils/Assertions.java new file mode 100644 index 0000000000..4a1828ae7f --- /dev/null +++ b/src/test/java/org/refactoringminer/utils/Assertions.java @@ -0,0 +1,27 @@ +package org.refactoringminer.utils; + +import java.util.LinkedHashSet; +import java.util.List; +import java.util.function.Supplier; +import java.util.stream.Collectors; + +public class Assertions { + public static void assertHasSameElementsAs(List expected, List actual, Supplier lazyErrorMessage) { + var expectedSet = new LinkedHashSet<>(expected); + var actualSet = new LinkedHashSet<>(actual); + org.junit.jupiter.api.Assertions.assertAll( + () -> org.junit.jupiter.api.Assertions.assertEquals(expected.size(), actual.size(), () -> + "Expected size (" + expected.size() + ") != actual size (" + actual.size() + "):" + + System.lineSeparator() + lazyErrorMessage.get() + System.lineSeparator()), + () -> org.junit.jupiter.api.Assertions.assertTrue(actualSet.containsAll(expectedSet), () -> System.lineSeparator() + expectedSet.stream() + .filter((String s) -> !actualSet.contains(s)) + .map((String s) -> "+" + s) + .map((String s) -> s + System.lineSeparator()) + .collect(Collectors.joining())), + () -> org.junit.jupiter.api.Assertions.assertTrue(expectedSet.containsAll(actualSet), () -> System.lineSeparator() + actualSet.stream() + .filter((String s) -> !expectedSet.contains(s)) + .map((String s) -> "-" + s) + .map((String s) -> s + System.lineSeparator()) + .collect(Collectors.joining()))); + } +}