Skip to content

Commit

Permalink
Updating tests after changing the mismatch description
Browse files Browse the repository at this point in the history
Fixing test failures by changing the assertion to assertDoesNotMatch.
In fact, the focus of those tests was NOT to check for the mismatch description,
but only for the correctness of the match true/false.
  • Loading branch information
alb-i986 committed Apr 19, 2020
1 parent fa60efa commit 1d1c573
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,48 +21,48 @@ protected Matcher<?> createMatcher() {

public void testMatchesWhenSizeIsCorrect() {
assertMatches("correct size", hasSize(equalTo(2)), asList(null, null));
assertMismatchDescription("collection size was <3>", hasSize(equalTo(2)), asList(null, null, null));
assertDoesNotMatch("incorrect size", hasSize(equalTo(2)), asList(null, null, null));
}

public void testMatchesCollectionWhenSizeIsCorrectUsingObjectElementType() {
Collection<Object> list = asList(null, null);
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testMatchesCollectionWhenSizeIsCorrectUsingStringElementType() {
Collection<String> list = asList("a", "b");
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testMatchesCollectionWhenSizeIsCorrectUsingWildcardElementType() {
Collection<?> list = asList("a", "b");
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testMatchesListWhenSizeIsCorrectUsingObjectElementType() {
List<Object> list = asList(null, null);
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testMatchesListWhenSizeIsCorrectUsingStringElementType() {
List<String> list = asList("a", "b");
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testMatchesListWhenSizeIsCorrectUsingWildcardElementType() {
List<?> list = asList("a", "b");
assertMatches("correct size", hasSize(equalTo(2)), list);
assertMismatchDescription("collection size was <2>", hasSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", hasSize(equalTo(3)), list);
}

public void testProvidesConvenientShortcutForHasSizeEqualTo() {
assertMatches("correct size", hasSize(2), asList(null, null));
assertMismatchDescription("collection size was <3>", hasSize(2), asList(null, null, null));
assertDoesNotMatch("incorrect size", hasSize(2), asList(null, null, null));
}

public void testHasAReadableDescription() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,48 +22,48 @@ protected Matcher<?> createMatcher() {

public void testMatchesWhenSizeIsCorrect() {
assertMatches("correct size", aMapWithSize(equalTo(2)), mapWithKeys("a", "b"));
assertMismatchDescription("map size was <3>", aMapWithSize(equalTo(2)), mapWithKeys("a", "b", "c"));
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(2)), mapWithKeys("a", "b", "c"));
}

public void testMatchesMapWhenSizeIsCorrectUsingObjectElementType() {
Map<Object, Object> map = mapWithKeys(new Object(), new Object());
assertMatches("correct size", aMapWithSize(equalTo(2)), map);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), map);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), map);
}

public void testMatchesMapWhenSizeIsCorrectUsingStringElementType() {
Map<String, Integer> map = mapWithKeys("a", "b");
assertMatches("correct size", aMapWithSize(equalTo(2)), map);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), map);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), map);
}

public void testMatchesMapWhenSizeIsCorrectUsingWildcardElementType() {
Map<?, ?> map = mapWithKeys("a", "b");
assertMatches("correct size", aMapWithSize(equalTo(2)), map);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), map);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), map);
}

public void testMatchesListWhenSizeIsCorrectUsingObjectElementType() {
Map<Object, Object> map = mapWithKeys(new Object(), new Object());
assertMatches("correct size", aMapWithSize(equalTo(2)), map);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), map);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), map);
}

public void testMatchesListWhenSizeIsCorrectUsingStringElementType() {
Map<String, Integer> list = mapWithKeys("a", "b");
assertMatches("correct size", aMapWithSize(equalTo(2)), list);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), list);
}

public void testMatchesListWhenSizeIsCorrectUsingWildcardElementType() {
Map<?, ?> list = mapWithKeys("a", "b");
assertMatches("correct size", aMapWithSize(equalTo(2)), list);
assertMismatchDescription("map size was <2>", aMapWithSize(equalTo(3)), list);
assertDoesNotMatch("incorrect size", aMapWithSize(equalTo(3)), list);
}

public void testProvidesConvenientShortcutForHasSizeEqualTo() {
assertMatches("correct size", aMapWithSize(2), mapWithKeys(new Object(), new Object()));
assertMismatchDescription("map size was <3>", aMapWithSize(2), mapWithKeys(new Object(), new Object(), new Object()));
assertDoesNotMatch("incorrect size", aMapWithSize(2), mapWithKeys(new Object(), new Object(), new Object()));
}

public void testHasAReadableDescription() {
Expand Down Expand Up @@ -96,20 +96,4 @@ private static <K, V> Map<K, V> mapWithKeysAndValues(List<K> keys, List<V> value
}
return result;
}

/**
* An object that overrides toString.
*/
private static class MyObject {
private final String state;

private MyObject(String state) {
this.state = state;
}

@Override
public String toString() {
return state;
}
}
}

0 comments on commit 1d1c573

Please sign in to comment.