Skip to content

Commit 142c8a9

Browse files
committed
Addressed some analysis warnings
1 parent 425f095 commit 142c8a9

18 files changed

+23
-29
lines changed

hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected boolean matchesSafely(T actual, Description mismatch) {
4444
return false;
4545
}
4646
return true;
47-
};
47+
}
4848

4949
@Override
5050
public final void describeTo(Description description) {

hamcrest-core/src/main/java/org/hamcrest/TypeSafeMatcher.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ public final boolean matches(Object item) {
7171
@Override
7272
final public void describeMismatch(Object item, Description description) {
7373
if (item == null) {
74-
super.describeMismatch(item, description);
74+
super.describeMismatch(null, description);
7575
} else if (! expectedType.isInstance(item)) {
7676
description.appendText("was a ")
7777
.appendText(item.getClass().getName())

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ public void describeMismatch(Object item, Description mismatchDescription) {
9191

9292
@Test public void
9393
canAssertSubtypes() {
94-
Integer aSub = new Integer(1);
95-
Number aSuper = aSub;
96-
97-
assertThat(aSub, equalTo(aSuper));
94+
assertThat(1, equalTo((Number) 1));
9895
}
9996
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public void describeTo(Description description) {
3434
@Test public void
3535
describesMismatches() {
3636
assertMismatchDescription("was null", matcher, null);
37-
assertMismatchDescription("was a java.lang.Integer (<3>)", (Matcher)matcher, new Integer(3));
37+
assertMismatchDescription("was a java.lang.Integer (<3>)", (Matcher)matcher, 3);
3838
assertMismatchDescription("The mismatch", matcher, "a string");
3939
}
4040
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,6 @@ public final class CombinableTest {
6363
@Test public void
6464
picksUpTypeFromLeftHandSideOfExpression() {
6565
@SuppressWarnings("unused")
66-
Matcher<String> matcher = CombinableMatcher.<String>both(equalTo("yellow")).and(notNullValue(String.class));
66+
Matcher<String> matcher = CombinableMatcher.both(equalTo("yellow")).and(notNullValue(String.class));
6767
}
6868
}

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public final class IsEqualTest {
4242
assertDoesNotMatch(matcher, new String[] {"a", "b"});
4343
}
4444

45+
@SuppressWarnings("EqualsWhichDoesntCheckParameterClass")
4546
@Test public void
4647
honoursIsEqualImplementationEvenWithNullValues() {
4748
Object alwaysEqual = new Object() {
@@ -57,7 +58,8 @@ public boolean equals(Object obj) {
5758
}
5859
};
5960

60-
final Matcher<Object> matcher = equalTo(null);
61+
Matcher<Object> matcher = equalTo(null);
62+
6163
assertMatches(matcher, alwaysEqual);
6264
assertDoesNotMatch(matcher, neverEqual);
6365
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public final class IsTest {
4444
@Test public void
4545
providesConvenientShortcutForIsInstanceOf() {
4646
final Matcher matcher = isA(Integer.class);
47-
assertMatches(matcher, Integer.valueOf(1));
47+
assertMatches(matcher, 1);
4848
assertDoesNotMatch(matcher, new Object());
4949
assertDoesNotMatch(matcher, null);
5050
}

hamcrest-library/src/main/java/org/hamcrest/collection/IsArray.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ public void describeMismatchSafely(T[] actual, Description mismatchDescription)
4444
}
4545

4646
@Override
47+
@SuppressWarnings("unchecked")
4748
public void describeTo(Description description) {
4849
description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(),
4950
Arrays.asList(elementMatchers));

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContaining.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public boolean matchesSafely(T[] array) {
3131
@Override
3232
public void describeMismatchSafely(T[] item, Description mismatchDescription) {
3333
super.describeMismatch(Arrays.asList(item), mismatchDescription);
34-
};
34+
}
3535

3636
@Override
3737
public void describeTo(Description description) {

hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContainingInAnyOrder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ public boolean matchesSafely(E[] item) {
2828
@Override
2929
public void describeMismatchSafely(E[] item, Description mismatchDescription) {
3030
iterableMatcher.describeMismatch(Arrays.asList(item), mismatchDescription);
31-
};
31+
}
3232

3333
@Override
3434
public void describeTo(Description description) {

hamcrest-library/src/main/java/org/hamcrest/collection/IsCollectionWithSize.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22

33
import org.hamcrest.FeatureMatcher;
44
import org.hamcrest.Matcher;
5-
import org.hamcrest.core.IsEqual;
65

76
import java.util.Collection;
87

8+
import static org.hamcrest.core.IsEqual.equalTo;
9+
910
/**
1011
* Matches if collection size satisfies a nested matcher.
1112
*/
@@ -43,7 +44,7 @@ public static <E> Matcher<Collection<? extends E>> hasSize(Matcher<? super Integ
4344
*/
4445
@SuppressWarnings({ "rawtypes", "unchecked" })
4546
public static <E> Matcher<Collection<? extends E>> hasSize(int size) {
46-
return (Matcher)IsCollectionWithSize.hasSize(IsEqual.<Integer>equalTo(size));
47+
return (Matcher)IsCollectionWithSize.hasSize(equalTo(size));
4748
}
4849

4950
}

hamcrest-library/src/main/java/org/hamcrest/collection/IsMapWithSize.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ protected Integer featureValueOf(Map<? extends K, ? extends V> actual) {
4444
*/
4545
public static <K, V> Matcher<Map<? extends K, ? extends V>> aMapWithSize(int size) {
4646
Matcher<? super Integer> matcher = equalTo(size);
47-
return IsMapWithSize.<K, V>aMapWithSize(matcher);
47+
return IsMapWithSize.aMapWithSize(matcher);
4848
}
4949

5050
/**
@@ -55,6 +55,6 @@ protected Integer featureValueOf(Map<? extends K, ? extends V> actual) {
5555
*
5656
*/
5757
public static <K, V> Matcher<Map<? extends K, ? extends V>> anEmptyMap() {
58-
return IsMapWithSize.<K, V>aMapWithSize(equalTo(0));
58+
return IsMapWithSize.aMapWithSize(equalTo(0));
5959
}
6060
}

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
* @author Steve Freeman
2424
* @since 1.1.0
2525
*/
26+
@SuppressWarnings("UnusedDeclaration")
2627
public class HasPropertyWithValueTest extends AbstractMatcherTest {
2728
private final BeanWithoutInfo shouldMatch = new BeanWithoutInfo("is expected");
2829
private final BeanWithoutInfo shouldNotMatch = new BeanWithoutInfo("not expected");

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import static org.hamcrest.beans.SamePropertyValuesAs.samePropertyValuesAs;
99

10+
@SuppressWarnings("UnusedDeclaration")
1011
public class SamePropertyValuesAsTest extends AbstractMatcherTest {
1112
private static final Value aValue = new Value("expected");
1213
private static final ExampleBean expectedBean = new ExampleBean("same", 1, aValue);

hamcrest-library/src/test/java/org/hamcrest/collection/IsMapContainingKeyTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testMatchesMapContainingKeyWithIntegerKeys() throws Exception {
5151
map.put(1, "A");
5252
map.put(2, "B");
5353

54-
assertThat(map, hasKey(Integer.valueOf(1)));
54+
assertThat(map, hasKey(1));
5555
}
5656

5757
public void testMatchesMapContainingKeyWithNumberKeys() throws Exception {

hamcrest-library/src/test/java/org/hamcrest/collection/IsMapWithSizeTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ public void testCompilesWithATypedMap() {
7272
MatcherAssert.assertThat(arrayList, aMapWithSize(0));
7373
}
7474

75-
private static final <K, V> Map<K, V> mapWithKeys(K... keys) {
75+
private static <K, V> Map<K, V> mapWithKeys(K... keys) {
7676
final Map<K, V> result = new HashMap<K, V>();
7777
for (K key : keys) {
7878
result.put(key, null);

hamcrest-library/src/test/java/org/hamcrest/comparator/ComparatorMatcherBuilderTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public CustomInt(int value) {
122122
this.value = value;
123123
}
124124

125+
@Override
125126
public int compareTo(CustomInt other) {
126127
return value - other.value;
127128
}

hamcrest-library/src/test/java/org/hamcrest/io/FileMatchersTest.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22

33
import org.hamcrest.AbstractMatcherTest;
44
import org.hamcrest.Matcher;
5-
import org.junit.Test;
65

76
import java.io.File;
87

98
import static org.hamcrest.core.IsEqual.equalTo;
109

10+
@SuppressWarnings("ResultOfMethodCallIgnored")
1111
public class FileMatchersTest extends AbstractMatcherTest {
1212

1313
private File directory;
@@ -23,28 +23,24 @@ protected void setUp() throws Exception {
2323
file.createNewFile();
2424
}
2525

26-
@Test
2726
public void testAnExistingDirectory() {
2827
assertMatches("matches existing directory", FileMatchers.anExistingDirectory(), directory);
2928
assertDoesNotMatch("doesn't match existing file", FileMatchers.anExistingDirectory(), file);
3029
assertDoesNotMatch("doesn't match missing file", FileMatchers.anExistingDirectory(), new File("foo"));
3130
}
3231

33-
@Test
3432
public void testAnExistingFileOrDirectory() {
3533
assertMatches("matches existing file", FileMatchers.anExistingFileOrDirectory(), file);
3634
assertMatches("matches existing directory", FileMatchers.anExistingFileOrDirectory(), directory);
3735
assertDoesNotMatch("doesn't match missing file", FileMatchers.anExistingFileOrDirectory(), new File("foo"));
3836
}
3937

40-
@Test
4138
public void testAnExistingFile() {
4239
assertMatches("matches existing file", FileMatchers.anExistingFile(), file);
4340
assertDoesNotMatch("doesn't match existing directory", FileMatchers.anExistingFile(), directory);
4441
assertDoesNotMatch("doesn't match missing file", FileMatchers.anExistingFile(), new File("foo"));
4542
}
4643

47-
@Test
4844
public void testAReadableFile() {
4945
file.setReadable(true);
5046
assertMatches("matches readable file", FileMatchers.aReadableFile(), file);
@@ -53,42 +49,36 @@ public void testAReadableFile() {
5349
}
5450
}
5551

56-
@Test
5752
public void testAWritableFile() {
5853
assertMatches("matches writable file", FileMatchers.aWritableFile(), file);
5954
file.setWritable(false);
6055
assertDoesNotMatch("doesn't match unwritable file", FileMatchers.aWritableFile(), file);
6156
}
6257

63-
@Test
6458
public void testAFileWithSizeLong() {
6559
assertMatches("matches file size", FileMatchers.aFileWithSize(0L), file);
6660
file.setWritable(false);
6761
assertDoesNotMatch("doesn't match incorrect file size", FileMatchers.aFileWithSize(34L), file);
6862
}
6963

70-
@Test
7164
public void testAFileWithSizeMatcherOfLong() {
7265
assertMatches("matches file size", FileMatchers.aFileWithSize(equalTo(0L)), file);
7366
file.setWritable(false);
7467
assertDoesNotMatch("doesn't match incorrect file size", FileMatchers.aFileWithSize(equalTo(23L)), file);
7568
}
7669

77-
@Test
7870
public void testAFileNamed() {
7971
assertMatches("matches file name", FileMatchers.aFileNamed(equalTo(file.getName())), file);
8072
file.setWritable(false);
8173
assertDoesNotMatch("doesn't match incorrect file name", FileMatchers.aFileNamed(equalTo("foo")), file);
8274
}
8375

84-
@Test
8576
public void testAFileWithCanonicalPath() throws Exception {
8677
assertMatches("matches file canonical path", FileMatchers.aFileWithCanonicalPath(equalTo(file.getCanonicalPath())), file);
8778
file.setWritable(false);
8879
assertDoesNotMatch("doesn't match incorrect canonical path", FileMatchers.aFileWithCanonicalPath(equalTo("foo")), file);
8980
}
9081

91-
@Test
9282
public void testAFileWithAbsolutePath() {
9383
assertMatches("matches file absolute path", FileMatchers.aFileWithAbsolutePath(equalTo(file.getAbsolutePath())), file);
9484
file.setWritable(false);

0 commit comments

Comments
 (0)