### Question:
HasSameItemsAsCollectionMatcher extends TypeSafeDiagnosingMatcher<Collection<? extends T>> { @Factory public static <T> Matcher<Collection<? extends T>> hasSameItemsAsCollection(Collection<? extends T> correctList) { return new HasSameItemsAsCollectionMatcher<>(correctList); } HasSameItemsAsCollectionMatcher(Collection<? extends T> expected); @Override void describeTo(Description description); @Factory static Matcher<Collection<? extends T>> hasSameItemsAsCollection(Collection<? extends T> correctList);  }### Answer:
@Test(expected = AssertionError.class) public void withOnlyOneCommonElement() throws Exception { List<String> actual = Arrays.asList("1", "2", "3", "4", "7"); List<String> expected = Arrays.asList("3", "4", "5"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void withOnlyOneDifferElementInActual() throws Exception { List<String> actual = Arrays.asList("1", "2", "3", "4"); List<String> expected = Arrays.asList("1", "2", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void withOnlyOneDifferElementInExpected() throws Exception { List<String> actual = Arrays.asList("1", "2", "3"); List<String> expected = Arrays.asList("1", "2", "3", "4"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test public void collectionsEquals() throws Exception { List<String> actual = Arrays.asList("1", "2", "3"); List<String> expected = Arrays.asList("1", "2", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test public void collectionsEqualsWithNotEqualOrder() throws Exception { List<String> actual = Arrays.asList("1", "2", "3"); List<String> expected = Arrays.asList("3", "2", "1"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void collectionsNotEqualsWhenLastElTwiceInActual() throws Exception { List<String> actual = Arrays.asList("1", "2", "3", "3"); List<String> expected = Arrays.asList("1", "2", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void collectionsNotEqualsWhenLastElTwiceInExpected() throws Exception { List<String> actual = Arrays.asList("1", "2", "3"); List<String> expected = Arrays.asList("1", "2", "3", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void collectionsNotEqualsWhenNotLastElTwiceInActual() throws Exception { List<String> actual = Arrays.asList("1", "2", "2", "3"); List<String> expected = Arrays.asList("1", "2", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }
@Test(expected = AssertionError.class) public void collectionsNotEqualsWhenNotLastElTwiceInExpected() throws Exception { List<String> actual = Arrays.asList("1", "2", "3"); List<String> expected = Arrays.asList("1", "2", "2", "3"); assertThat(actual, hasSameItemsAsCollection(expected)); }