-
Notifications
You must be signed in to change notification settings - Fork 143
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract in-house assertion for testing special condition (two iterabl…
…es contain same elements in any order)
- Loading branch information
1 parent
99c3b1f
commit eb39b60
Showing
2 changed files
with
29 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<String> expected, List<String> actual, Supplier<String> 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()))); | ||
} | ||
} |