Skip to content

Commit 8f9372a

Browse files
committed
Remove warning. more readable test names. test for inherited fields
1 parent 316340e commit 8f9372a

File tree

4 files changed

+35
-16
lines changed

4 files changed

+35
-16
lines changed

hamcrest-core/src/test/java/org/hamcrest/TypeSafeMatcherTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import static org.hamcrest.AbstractMatcherTest.assertMismatchDescription;
66
import static org.junit.Assert.assertFalse;
77

8+
@SuppressWarnings("WeakerAccess")
89
public final class TypeSafeMatcherTest {
910
private final Matcher<String> matcher = new TypeSafeMatcherSubclass();
1011

hamcrest-library/src/main/java/org/hamcrest/object/HasEqualValues.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public void describeTo(Description description) {
6767
}
6868

6969
private static List<FieldMatcher> fieldMatchers(Object expectedObject) {
70-
List<FieldMatcher> result = new ArrayList<>();
70+
final List<FieldMatcher> result = new ArrayList<>();
7171
for (Field field : expectedObject.getClass().getFields()) {
7272
result.add(new FieldMatcher(field, expectedObject));
7373
}

hamcrest-library/src/test/java/org/hamcrest/beans/SamePropertyValuesAsTest.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs;
77

8-
@SuppressWarnings("UnusedDeclaration")
8+
@SuppressWarnings("WeakerAccess")
99
public class SamePropertyValuesAsTest extends AbstractMatcherTest {
1010
private static final Value aValue = new Value("expected");
1111
private static final ExampleBean expectedBean = new ExampleBean("same", 1, aValue);
@@ -17,16 +17,16 @@ protected Matcher<?> createMatcher() {
1717
return samePropertyValuesAs(expectedBean);
1818
}
1919

20-
public void testReportsMatchWhenAllPropertiesMatch() {
20+
public void test_reports_match_when_all_properties_match() {
2121
assertMatches("matched properties", samePropertyValuesAs(expectedBean), actualBean);
2222
}
2323

24-
public void testReportsMismatchWhenActualTypeIsNotAssignableToExpectedType() {
24+
public void test_reports_mismatch_when_actual_type_is_not_assignable_to_expected_type() {
2525
assertMismatchDescription("is incompatible type: ExampleBean",
2626
samePropertyValuesAs((Object)aValue), actualBean);
2727
}
2828

29-
public void testReportsMismatchOnFirstPropertyDifference() {
29+
public void test_reports_mismatch_on_first_property_difference() {
3030
assertMismatchDescription("string was \"different\"",
3131
samePropertyValuesAs(expectedBean), new ExampleBean("different", 1, aValue));
3232
assertMismatchDescription("int was <2>",
@@ -35,12 +35,12 @@ public void testReportsMismatchOnFirstPropertyDifference() {
3535
samePropertyValuesAs(expectedBean), new ExampleBean("same", 1, new Value("other")));
3636
}
3737

38-
public void testMatchesBeansWithInheritanceButNoExtraProperties() {
38+
public void test_matches_beans_with_inheritance_but_no_extra_properties() {
3939
assertMatches("sub type with same properties",
4040
samePropertyValuesAs(expectedBean), new SubBeanWithNoExtraProperties("same", 1, aValue));
4141
}
4242

43-
public void testRejectsSubTypeThatHasExtraProperties() {
43+
public void test_rejects_subtype_that_has_extra_properties() {
4444
assertMismatchDescription("has extra properties called [extra]",
4545
samePropertyValuesAs(expectedBean), new SubBeanWithExtraProperty("same", 1, aValue));
4646
}
@@ -95,6 +95,7 @@ public static class SubBeanWithExtraProperty extends ExampleBean {
9595
public SubBeanWithExtraProperty(String stringProperty, int intProperty, Value valueProperty) {
9696
super(stringProperty, intProperty, valueProperty);
9797
}
98+
@SuppressWarnings("unused")
9899
public String getExtra() { return "extra"; }
99100
}
100101
}

hamcrest-library/src/test/java/org/hamcrest/object/HasEqualsValuesTest.java

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,37 +3,54 @@
33
import org.hamcrest.AbstractMatcherTest;
44
import org.hamcrest.Matcher;
55

6+
@SuppressWarnings("WeakerAccess")
67
public class HasEqualsValuesTest extends AbstractMatcherTest {
7-
private static final WithPublicFields WITH_PUBLIC_FIELDS = new WithPublicFields(666, "a string");
8+
private static final WithPublicFields WITH_PUBLIC_FIELDS = new WithPublicFields('x', 666, "a string");
89
private static final HasEqualValues<WithPublicFields> WITH_PUBLIC_FIELDS_MATCHER = new HasEqualValues<>(WITH_PUBLIC_FIELDS);
910

1011
@Override
1112
protected Matcher<?> createMatcher() {
1213
return WITH_PUBLIC_FIELDS_MATCHER;
1314
}
1415

15-
public void testDescribesItself() {
16+
public void test_describes_itself() {
1617
assertDescription(
17-
"WithPublicFields has values [i: <666>, s: \"a string\"]",
18+
"WithPublicFields has values [i: <666>, s: \"a string\", c: \"x\"]",
1819
WITH_PUBLIC_FIELDS_MATCHER);
1920
}
2021

21-
public void testMatchesEquivalentObject() {
22-
assertMatches(WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields(666, "a string"));
22+
public void test_matches_equivalent_object() {
23+
assertMatches(WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('x', 666, "a string"));
2324
}
2425

25-
public void testMisMatchesFieldInequality() {
26-
assertMismatchDescription("'s' was \"different\"", WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields(666, "different"));
26+
public void test_mismatches_on_first_field_inequality() {
27+
assertMismatchDescription(
28+
"'s' was \"different\"",
29+
WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('x', 666, "different"));
2730
}
2831

32+
public void test_mismatches_on_inherited_field() {
33+
assertMismatchDescription(
34+
"'c' was \"y\"",
35+
WITH_PUBLIC_FIELDS_MATCHER, new WithPublicFields('y', 666, "a string"));
36+
}
2937

30-
public static class WithPublicFields {
38+
public static class WithPublicFields extends Parent {
3139
public final int i;
3240
public final String s;
3341

34-
public WithPublicFields(int i, String s) {
42+
public WithPublicFields(char c, int i, String s) {
43+
super(c);
3544
this.i = i;
3645
this.s = s;
3746
}
3847
}
48+
49+
public static class Parent {
50+
public final char c;
51+
52+
public Parent(char c) {
53+
this.c = c;
54+
}
55+
}
3956
}

0 commit comments

Comments
 (0)