Skip to content

Instantly share code, notes, and snippets.

@pawellabaj
Last active June 21, 2023 12:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pawellabaj/4f1dff142391a709c13e847f4420fa91 to your computer and use it in GitHub Desktop.
Save pawellabaj/4f1dff142391a709c13e847f4420fa91 to your computer and use it in GitHub Desktop.
Without looking into a documentation, will the test pass or fail?
import org.junit.jupiter.api.Test;
import java.util.LinkedHashSet;
import java.util.Set;
import static org.assertj.core.api.Assertions.assertThat;
class OrderSetTest {
@Test
void orderInSetShouldNotBeLost() {
//given
var insertionOrderedSet = new LinkedHashSet<String>();
insertionOrderedSet.add("C");
insertionOrderedSet.add("B");
insertionOrderedSet.add("A");
// when
var immutableSet = Set.copyOf(insertionOrderedSet);
// then
assertThat(immutableSet).containsExactly("C", "B", "A");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment