Skip to content

Commit 28f3b57

Browse files
author
smgfreeman
committed
Cleaned up some warnings
Started converting matchers that have no input type to be Matcher<Object>
1 parent 6fb640f commit 28f3b57

File tree

17 files changed

+118
-106
lines changed

17 files changed

+118
-106
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ public static <T> Matcher<T> allOf(Matcher<T> first, Matcher<? super T> second,
113113
matchers.add(second);
114114
matchers.add(third);
115115
matchers.add(fourth);
116+
matchers.add(fifth);
116117
matchers.add(sixth);
117118
return allOf(matchers);
118119
}

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public void describeTo(Description description) {
3535
* This matcher always evaluates to true.
3636
*/
3737
@Factory
38-
public static <T> Matcher<T> anything() {
39-
return new IsAnything<T>();
38+
public static Matcher<Object> anything() {
39+
return new IsAnything<Object>();
4040
}
4141

4242
/**
@@ -45,7 +45,7 @@ public static <T> Matcher<T> anything() {
4545
* @param description A meaningful string used when describing itself.
4646
*/
4747
@Factory
48-
public static <T> Matcher<T> anything(String description) {
49-
return new IsAnything<T>(description);
48+
public static Matcher<Object> anything(String description) {
49+
return new IsAnything<Object>(description);
5050
}
5151
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000-2006 hamcrest.org
1+
/* Copyright (c) 2000-2010 hamcrest.org
22
*/
33
package org.hamcrest.core;
44

@@ -24,32 +24,32 @@ public void describeTo(Description description) {
2424
* Matches if value is null.
2525
*/
2626
@Factory
27-
public static <T> Matcher<T> nullValue() {
28-
return new IsNull<T>();
27+
public static Matcher<Object> nullValue() {
28+
return new IsNull<Object>();
2929
}
3030

3131
/**
3232
* Matches if value is not null.
3333
*/
3434
@Factory
35-
public static <T> Matcher<T> notNullValue() {
36-
return not(IsNull.<T>nullValue());
35+
public static Matcher<Object> notNullValue() {
36+
return not(nullValue());
3737
}
3838

3939
/**
4040
* Matches if value is null. With type inference.
4141
*/
4242
@Factory
4343
public static <T> Matcher<T> nullValue(@SuppressWarnings("unused") Class<T> type) {
44-
return nullValue();
44+
return new IsNull<T>();
4545
}
4646

4747
/**
4848
* Matches if value is not null. With type inference.
4949
*/
5050
@Factory
51-
public static <T> Matcher<T> notNullValue(@SuppressWarnings("unused") Class<T> type) {
52-
return notNullValue();
51+
public static <T> Matcher<T> notNullValue(Class<T> type) {
52+
return not(nullValue(type));
5353
}
5454
}
5555

hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithAssertThat.java

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
/* Copyright (c) 2000-2010 hamcrest.org
2+
*/
13
package org.hamcrest.examples.junit4;
24

35
import static org.hamcrest.MatcherAssert.assertThat;
@@ -49,24 +51,13 @@ public void showMismatch() {
4951
assertThat(complicated, shouldBe("the wrong thing"));
5052
}
5153

52-
private Matcher<ComplicatedClass> shouldBe(String string) {
54+
private Matcher<ComplicatedClass> shouldBe(@SuppressWarnings("unused") String string) {
5355
return new TypeSafeMatcher<ComplicatedClass>() {
54-
55-
public void describeTo(Description description) {
56-
// TODO Auto-generated method stub
57-
58-
}
59-
56+
public void describeTo(Description description) { } // no op
6057
@Override
61-
public boolean matchesSafely(ComplicatedClass item) {
62-
// TODO Auto-generated method stub
63-
return false;
64-
}
58+
public boolean matchesSafely(ComplicatedClass item) { return false; }
6559
@Override
66-
public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {
67-
// TODO Auto-generated method stub
68-
69-
}
60+
public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {} // no op
7061
};
7162
}
7263

hamcrest-generator/src/main/java/org/hamcrest/generator/FactoryMethod.java

Lines changed: 65 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -117,40 +117,52 @@ public void setJavaDoc(String javaDoc) {
117117
public String getJavaDoc() {
118118
return javaDoc;
119119
}
120-
121-
@SuppressWarnings({"RedundantIfStatement"})
120+
121+
// Generated in Eclipse...
122+
// n.b. Doesn't include returnType
122123
@Override
123-
public boolean equals(Object o) {
124-
if (this == o) return true;
125-
if (o == null || getClass() != o.getClass()) return false;
126-
127-
FactoryMethod that = (FactoryMethod) o;
128-
129-
if (exceptions != null ? !exceptions.equals(that.exceptions) : that.exceptions != null) return false;
130-
if (factoryMethod != null ? !factoryMethod.equals(that.factoryMethod) : that.factoryMethod != null)
131-
return false;
132-
if (genericTypeParameters != null ? !genericTypeParameters.equals(that.genericTypeParameters) : that.genericTypeParameters != null)
133-
return false;
134-
if (generifiedType != null ? !generifiedType.equals(that.generifiedType) : that.generifiedType != null)
135-
return false;
136-
if (javaDoc != null ? !javaDoc.equals(that.javaDoc) : that.javaDoc != null) return false;
137-
if (matcherClass != null ? !matcherClass.equals(that.matcherClass) : that.matcherClass != null) return false;
138-
if (parameters != null ? !parameters.equals(that.parameters) : that.parameters != null) return false;
139-
140-
return true;
141-
}
142-
124+
public boolean equals(Object obj) {
125+
if (this == obj) return true;
126+
if (obj == null) return false;
127+
if (getClass() != obj.getClass()) return false;
128+
FactoryMethod other = (FactoryMethod) obj;
129+
if (exceptions == null) {
130+
if (other.exceptions != null) return false;
131+
} else if (!exceptions.equals(other.exceptions)) return false;
132+
if (factoryMethod == null) {
133+
if (other.factoryMethod != null) return false;
134+
} else if (!factoryMethod.equals(other.factoryMethod)) return false;
135+
if (genericTypeParameters == null) {
136+
if (other.genericTypeParameters != null) return false;
137+
} else if (!genericTypeParameters.equals(other.genericTypeParameters)) return false;
138+
if (generifiedType == null) {
139+
if (other.generifiedType != null) return false;
140+
} else if (!generifiedType.equals(other.generifiedType)) return false;
141+
if (javaDoc == null) {
142+
if (other.javaDoc != null) return false;
143+
} else if (!javaDoc.equals(other.javaDoc)) return false;
144+
if (matcherClass == null) {
145+
if (other.matcherClass != null) return false;
146+
} else if (!matcherClass.equals(other.matcherClass)) return false;
147+
if (parameters == null) {
148+
if (other.parameters != null) return false;
149+
} else if (!parameters.equals(other.parameters)) return false;
150+
return true;
151+
}
152+
153+
// Generated in Eclipse...
143154
@Override
144155
public int hashCode() {
145-
int result;
146-
result = (matcherClass != null ? matcherClass.hashCode() : 0);
147-
result = 31 * result + (factoryMethod != null ? factoryMethod.hashCode() : 0);
148-
result = 31 * result + (generifiedType != null ? generifiedType.hashCode() : 0);
149-
result = 31 * result + (parameters != null ? parameters.hashCode() : 0);
150-
result = 31 * result + (exceptions != null ? exceptions.hashCode() : 0);
151-
result = 31 * result + (genericTypeParameters != null ? genericTypeParameters.hashCode() : 0);
152-
result = 31 * result + (javaDoc != null ? javaDoc.hashCode() : 0);
153-
return result;
156+
final int prime = 31;
157+
int result = 1;
158+
result = prime * result + ((exceptions == null) ? 0 : exceptions.hashCode());
159+
result = prime * result + ((factoryMethod == null) ? 0 : factoryMethod.hashCode());
160+
result = prime * result + ((genericTypeParameters == null) ? 0 : genericTypeParameters.hashCode());
161+
result = prime * result + ((generifiedType == null) ? 0 : generifiedType.hashCode());
162+
result = prime * result + ((javaDoc == null) ? 0 : javaDoc.hashCode());
163+
result = prime * result + ((matcherClass == null) ? 0 : matcherClass.hashCode());
164+
result = prime * result + ((parameters == null) ? 0 : parameters.hashCode());
165+
return result;
154166
}
155167

156168
@Override
@@ -200,32 +212,37 @@ public void setName(String name) {
200212
this.name = name;
201213
}
202214

203-
@SuppressWarnings({"RedundantIfStatement"})
204215
@Override
205-
public boolean equals(Object o) {
206-
if (this == o) return true;
207-
if (o == null || getClass() != o.getClass()) return false;
208-
209-
Parameter parameter = (Parameter) o;
210-
211-
if (name != null ? !name.equals(parameter.name) : parameter.name != null) return false;
212-
if (type != null ? !type.equals(parameter.type) : parameter.type != null) return false;
213-
214-
return true;
216+
public String toString() {
217+
return type + " " + name;
215218
}
216219

220+
// Generated in Eclipse...
217221
@Override
218222
public int hashCode() {
219-
int result;
220-
result = (type != null ? type.hashCode() : 0);
221-
result = 31 * result + (name != null ? name.hashCode() : 0);
222-
return result;
223+
final int prime = 31;
224+
int result = 1;
225+
result = prime * result + ((name == null) ? 0 : name.hashCode());
226+
result = prime * result + ((type == null) ? 0 : type.hashCode());
227+
return result;
223228
}
224229

230+
// Generated in Eclipse...
225231
@Override
226-
public String toString() {
227-
return type + " " + name;
232+
public boolean equals(Object obj) {
233+
if (this == obj) return true;
234+
if (obj == null) return false;
235+
if (getClass() != obj.getClass()) return false;
236+
Parameter other = (Parameter) obj;
237+
if (name == null) {
238+
if (other.name != null) return false;
239+
} else if (!name.equals(other.name)) return false;
240+
if (type == null) {
241+
if (other.type != null) return false;
242+
} else if (!type.equals(other.type)) return false;
243+
return true;
228244
}
245+
229246
}
230247

231248
}

hamcrest-generator/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,19 @@ public boolean hasNext() {
5454
}
5555

5656
public FactoryMethod next() {
57-
if (currentMethod >= 0 && currentMethod < allMethods.length) {
58-
return buildFactoryMethod(allMethods[currentMethod]);
59-
} else {
60-
throw new IllegalStateException("next() called without hasNext() check.");
57+
if (outsideArrayBounds()) {
58+
throw new IllegalStateException("next() called without hasNext() check.");
6159
}
60+
return buildFactoryMethod(allMethods[currentMethod]);
6261
}
6362

6463
public void remove() {
6564
throw new UnsupportedOperationException();
6665
}
6766

67+
private boolean outsideArrayBounds() {
68+
return currentMethod < 0 || allMethods.length <= currentMethod;
69+
}
6870
};
6971
}
7072

hamcrest-library/src/main/java/org/hamcrest/beans/SamePropertyValuesAs.java

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

33
import static org.hamcrest.beans.PropertyUtil.NO_ARGUMENTS;
44
import static org.hamcrest.beans.PropertyUtil.propertyDescriptorsFor;
5+
import static org.hamcrest.core.IsEqual.equalTo;
56

67
import java.beans.PropertyDescriptor;
78
import java.lang.reflect.Method;
@@ -15,7 +16,6 @@
1516
import org.hamcrest.Factory;
1617
import org.hamcrest.Matcher;
1718
import org.hamcrest.TypeSafeDiagnosingMatcher;
18-
import org.hamcrest.core.IsEqual;
1919

2020
public class SamePropertyValuesAs<T> extends TypeSafeDiagnosingMatcher<T> {
2121
private final T expectedBean;
@@ -94,7 +94,7 @@ public static class PropertyMatcher extends DiagnosingMatcher<Object> {
9494
public PropertyMatcher(PropertyDescriptor descriptor, Object expectedObject) {
9595
this.propertyName = descriptor.getDisplayName();
9696
this.readMethod = descriptor.getReadMethod();
97-
this.matcher = new IsEqual(readProperty(readMethod, expectedObject));
97+
this.matcher = equalTo(readProperty(readMethod, expectedObject));
9898
}
9999
@Override
100100
public boolean matches(Object actual, Description mismatchDescription) {

hamcrest-unit-test/src/main/java/org/hamcrest/AbstractMatcherTest.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,7 @@ public abstract class AbstractMatcherTest extends TestCase {
1010
* Create an instance of the Matcher so some generic safety-net tests can be run on it.
1111
*/
1212
protected abstract Matcher<?> createMatcher();
13-
14-
protected static final Object ARGUMENT_IGNORED = new Object();
15-
protected static final Object ANY_NON_NULL_ARGUMENT = new Object();
16-
13+
1714
public static <T> void assertMatches(String message, Matcher<? super T> c, T arg) {
1815
assertTrue(message, c.matches(arg));
1916
}

hamcrest-unit-test/src/main/java/org/hamcrest/FeatureMatcherTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public void testDoesNotThrowClassCastException() {
3131
}
3232

3333

34-
public static class Match extends IsEqual {
34+
public static class Match extends IsEqual<String> {
3535
public Match(String equalArg) { super(equalArg); }
3636
@Override public void describeMismatch(Object item, Description description) {
3737
description.appendText("mismatch-description");

hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyWithValueTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/* Copyright (c) 2000-2006 hamcrest.org
1+
/* Copyright (c) 2000-20010 hamcrest.org
22
*/
33
package org.hamcrest.beans;
44

@@ -105,7 +105,7 @@ public void setProperty(String property) {
105105
this.property = property;
106106
}
107107

108-
public void setWriteOnlyProperty(float property) {
108+
public void setWriteOnlyProperty(@SuppressWarnings("unused") float property) {
109109
}
110110

111111
@Override

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsArrayContainingInOrderTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package org.hamcrest.collection;
22

3-
import static org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder;
43
import static org.hamcrest.collection.IsArrayContainingInOrder.arrayContaining;
54
import static org.hamcrest.core.IsEqual.equalTo;
65

hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public void testCanMatchItemWhenCollectionHoldsSuperclass() // Issue 24
5151
{
5252
final Set<Number> s = new HashSet<Number>();
5353
s.add(Integer.valueOf(2));
54-
assertThat(s, new IsCollectionContaining<Number>(new IsEqual(Integer.valueOf(2))));
54+
assertThat(s, new IsCollectionContaining<Number>(new IsEqual<Number>(Integer.valueOf(2))));
5555
assertThat(s, IsCollectionContaining.hasItem(Integer.valueOf(2)));
5656
}
5757

0 commit comments

Comments
 (0)