-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add unit tests for CopyUtils #62
base: main
Are you sure you want to change the base?
Conversation
dough-data/src/test/java/io/github/bakedlibs/dough/collections/DummyData.java
Outdated
Show resolved
Hide resolved
dough-data/src/test/java/io/github/bakedlibs/dough/collections/TestCopyUtils.java
Outdated
Show resolved
Hide resolved
dough-data/src/test/java/io/github/bakedlibs/dough/collections/TestCopyUtils.java
Outdated
Show resolved
Hide resolved
…into tests/copy-utils
Kudos, SonarCloud Quality Gate passed! 0 Bugs No Coverage information |
private static <T> void assertHaveClonedElements(@Nonnull Collection<T> c1, @Nonnull Collection<T> c2) { | ||
Assertions.assertEquals(c1.size(), c2.size()); | ||
for (T t1 : c1) { | ||
for (T t2 : c2) { | ||
// If they are the same, it did not clone and thus we fail. | ||
Assertions.assertNotSame(t1, t2); | ||
if (t1.equals(t2)) { | ||
// If they are equal, the element has been cloned, thus, we break and check the next element. | ||
break; | ||
} | ||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Collections can be unordered, making this fail. This implementations only works for ordered/sorted collections, aka Lists.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would this fail if it was unordered? Maybe I'm just very sleepy but I can't seem to think of why this would fail if it wasn't ordered
Resolves #61