Skip to content

Commit

Permalink
Finished up Java 6 conversion, plus some IDE warnings.
Browse files Browse the repository at this point in the history
  • Loading branch information
sf105 committed Apr 3, 2012
1 parent bca8f06 commit aa3ddb6
Show file tree
Hide file tree
Showing 38 changed files with 56 additions and 23 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Original file line Diff line number Diff line change
@@ -0,0 +1 @@
/build
5 changes: 2 additions & 3 deletions build.xml
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@


<target name="javadoc" depends="library"> <target name="javadoc" depends="library">
<mkdir dir="build/javadoc"/> <mkdir dir="build/javadoc"/>
<javadoc destdir="build/javadoc" source="1.5" failonerror="yes" <javadoc destdir="build/javadoc" source="1.6" failonerror="yes"
overview="overview.html"> overview="overview.html">


<classpath> <classpath>
Expand All @@ -215,9 +215,8 @@
<group title="Matcher Library" packages="org.hamcrest.*"/> <group title="Matcher Library" packages="org.hamcrest.*"/>
<group title="Integration" packages="org.hamcrest.integration, org.hamcrest.integration.*"/> <group title="Integration" packages="org.hamcrest.integration, org.hamcrest.integration.*"/>


<link offline="false" href="http://java.sun.com/j2se/1.5.0/docs/api/"/>
<link offline="false" href="http://www.junit.org/junit/javadoc/3.8.1/"/> <link offline="false" href="http://www.junit.org/junit/javadoc/3.8.1/"/>
<link offline="false" href="http://junit.sourceforge.net/javadoc_40/"/> <link offline="false" href="http://kentbeck.github.com/junit/javadoc/latest/"/>
</javadoc> </javadoc>
</target> </target>


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public CustomMatcher(String description) {
this.fixedDescription = description; this.fixedDescription = description;
} }


@Override
public final void describeTo(Description description) { public final void describeTo(Description description) {
description.appendText(fixedDescription); description.appendText(fixedDescription);
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/ */
public abstract class DiagnosingMatcher<T> extends BaseMatcher<T> { public abstract class DiagnosingMatcher<T> extends BaseMatcher<T> {


public final boolean matches(Object item) { @Override
public final boolean matches(Object item) {
return matches(item, Description.NONE); return matches(item, Description.NONE);
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ protected boolean matchesSafely(T actual, Description mismatchDescription) {
return true; return true;
}; };


@Override
public final void describeTo(Description description) { public final void describeTo(Description description) {
description.appendText(featureDescription).appendText(" ") description.appendText(featureDescription).appendText(" ")
.appendDescriptionOf(subMatcher); .appendDescriptionOf(subMatcher);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ protected TypeSafeDiagnosingMatcher() {
this(TYPE_FINDER); this(TYPE_FINDER);
} }


@Override
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
public final boolean matches(Object item) { public final boolean matches(Object item) {
return item != null return item != null
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ protected void describeMismatchSafely(T item, Description mismatchDescription) {
* If you need to override this, there's no point on extending TypeSafeMatcher. * If you need to override this, there's no point on extending TypeSafeMatcher.
* Instead, extend the {@link BaseMatcher}. * Instead, extend the {@link BaseMatcher}.
*/ */
@Override
@SuppressWarnings({"unchecked"}) @SuppressWarnings({"unchecked"})
public final boolean matches(Object item) { public final boolean matches(Object item) {
return item != null return item != null
Expand Down
3 changes: 2 additions & 1 deletion hamcrest-core/src/main/java/org/hamcrest/core/Every.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public boolean matchesSafely(Iterable<T> collection, Description mismatchDescrip
return true; return true;
} }


public void describeTo(Description description) { @Override
public void describeTo(Description description) {
description.appendText("every item is ").appendDescriptionOf(matcher); description.appendText("every item is ").appendDescriptionOf(matcher);
} }


Expand Down
2 changes: 2 additions & 0 deletions hamcrest-core/src/main/java/org/hamcrest/core/IsAnything.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,10 +23,12 @@ public IsAnything(String message) {
this.message = message; this.message = message;
} }


@Override
public boolean matches(Object o) { public boolean matches(Object o) {
return true; return true;
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText(message); description.appendText(message);
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ protected boolean matches(Object item, Description mismatchDescription) {
return true; return true;
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("an instance of ") description.appendText("an instance of ")
.appendText(expectedClass.getName()); .appendText(expectedClass.getName());
Expand Down
2 changes: 1 addition & 1 deletion hamcrest-core/src/main/java/org/hamcrest/core/IsNull.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static Matcher<Object> notNullValue() {
* Matches if value is null. With type inference. * Matches if value is null. With type inference.
*/ */
@Factory @Factory
public static <T> Matcher<T> nullValue(Class<T> type) { public static <T> Matcher<T> nullValue(@SuppressWarnings("unused") Class<T> type) {
return new IsNull<T>(); return new IsNull<T>();
} }


Expand Down
2 changes: 2 additions & 0 deletions hamcrest-core/src/main/java/org/hamcrest/core/IsSame.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@ public IsSame(T object) {
this.object = object; this.object = object;
} }


@Override
public boolean matches(Object arg) { public boolean matches(Object arg) {
return arg == object; return arg == object;
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("sameInstance(") description.appendText("sameInstance(")
.appendValue(object) .appendValue(object)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -51,14 +51,16 @@ public void showMismatch() {
assertThat(complicated, shouldBe("the wrong thing")); assertThat(complicated, shouldBe("the wrong thing"));
} }


private Matcher<ComplicatedClass> shouldBe(String string) { private static Matcher<ComplicatedClass> shouldBe(final String string) {
return new TypeSafeMatcher<ComplicatedClass>() { return new TypeSafeMatcher<ComplicatedClass>() {
@Override @Override
public void describeTo(Description description) { } // no op public void describeTo(Description description) { } // no op
@Override @Override
public boolean matchesSafely(ComplicatedClass item) { return false; } public boolean matchesSafely(ComplicatedClass item) { return false; }
@Override @Override
public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {} // no op public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {
mismatchDescription.appendText(string);
}
}; };
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ private JavaMethod findMethodInSource(FactoryMethod factoryMethod) {
/** /**
* Reconstructs the JavaDoc as a string for a particular method. * Reconstructs the JavaDoc as a string for a particular method.
*/ */
private String createJavaDocComment(JavaMethod methodSource) { private static String createJavaDocComment(JavaMethod methodSource) {
String comment = methodSource.getComment(); String comment = methodSource.getComment();
DocletTag[] tags = methodSource.getTags(); DocletTag[] tags = methodSource.getTags();
if ((comment == null || comment.trim().length() == 0) && tags.length == 0) { if ((comment == null || comment.trim().length() == 0) && tags.length == 0) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void writeMethod(String generatedMethodName, FactoryMethod factoryMethod)
out.println(); out.println();
} }


private String removePackageNames(String in) { private static String removePackageNames(String in) {
// Simplify fully qualified names (allowing for trailing '...'). // Simplify fully qualified names (allowing for trailing '...').
return in == null ? "" : in.replaceAll("[^<>]*\\.([^\\.])", "$1"); return in == null ? "" : in.replaceAll("[^<>]*\\.([^\\.])", "$1");
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ private boolean hasFactoryAnnotation(Method javaMethod) {
} }
} }


private FactoryMethod buildFactoryMethod(Method javaMethod) { private static FactoryMethod buildFactoryMethod(Method javaMethod) {
FactoryMethod result = new FactoryMethod( FactoryMethod result = new FactoryMethod(
javaMethod.getDeclaringClass().getName(), javaMethod.getDeclaringClass().getName(),
javaMethod.getName(), javaMethod.getName(),
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ private Method findReadMethod(Object argument, Description mismatchDescription)
return readMethod; return readMethod;
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("hasProperty("); description.appendText("hasProperty(");
description.appendValue(propertyName); description.appendValue(propertyName);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public void describeMismatchSafely(T[] actual, Description mismatchDescription)
} }
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(), description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(),
Arrays.asList(elementMatchers)); Arrays.asList(elementMatchers));
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void describeMismatchSafely(T[] item, Description mismatchDescription) {
super.describeMismatch(Arrays.asList(item), mismatchDescription); super.describeMismatch(Arrays.asList(item), mismatchDescription);
}; };


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description description
.appendText("an array containing ") .appendText("an array containing ")
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,11 +19,12 @@ public IsIn(T[] elements) {
collection = Arrays.asList(elements); collection = Arrays.asList(elements);
} }


@SuppressWarnings({"SuspiciousMethodCalls"}) @Override
public boolean matches(Object o) { public boolean matches(Object o) {
return collection.contains(o); return collection.contains(o);
} }


@Override
public void describeTo(Description buffer) { public void describeTo(Description buffer) {
buffer.appendText("one of "); buffer.appendText("one of ");
buffer.appendValueList("{", ", ", "}", collection); buffer.appendValueList("{", ", ", "}", collection);
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public void describeMismatchSafely(Map<? extends K, ? extends V> map, Descriptio
mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet()); mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet());
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("map containing [") description.appendText("map containing [")
.appendDescriptionOf(keyMatcher) .appendDescriptionOf(keyMatcher)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ public void describeMismatchSafely(Double item, Description mismatchDescription)
.appendValue(actualDelta(item)); .appendValue(actualDelta(item));
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("a numeric value within ") description.appendText("a numeric value within ")
.appendValue(delta) .appendValue(delta)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void describeTo(Description description) {
description.appendText(" ").appendValue(expected); description.appendText(" ").appendValue(expected);
} }


private String asText(int comparison) { private static String asText(int comparison) {
return comparisonDescriptions[comparison + 1]; return comparisonDescriptions[comparison + 1];
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ private boolean eventHasSameSource(EventObject ev) {
return ev.getSource() == source; return ev.getSource() == source;
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("an event of type ") description.appendText("an event of type ")
.appendText(eventClass.getName()) .appendText(eventClass.getName())
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ public final class IsEmptyString extends BaseMatcher<String> {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
private static final Matcher<String> NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE); private static final Matcher<String> NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE);


@Override
public boolean matches(Object item) { public boolean matches(Object item) {
return item != null && item instanceof String && ((String) item).equals(""); return item != null && item instanceof String && ((String) item).equals("");
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("an empty string"); description.appendText("an empty string");
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void describeMismatchSafely(String item, Description mismatchDescription)
mismatchDescription.appendText("was ").appendText(item); mismatchDescription.appendText("was ").appendText(item);
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("equalToIgnoringCase(") description.appendText("equalToIgnoringCase(")
.appendValue(string) .appendValue(string)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public void describeMismatchSafely(String item, Description mismatchDescription)
mismatchDescription.appendText("was ").appendText(stripSpace(item)); mismatchDescription.appendText("was ").appendText(stripSpace(item));
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("equalToIgnoringWhiteSpace(") description.appendText("equalToIgnoringWhiteSpace(")
.appendValue(string) .appendValue(string)
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@ public class BaseMatcherTest extends TestCase {


public void testDescribesItselfWithToStringMethod() { public void testDescribesItselfWithToStringMethod() {
Matcher<Object> someMatcher = new BaseMatcher<Object>() { Matcher<Object> someMatcher = new BaseMatcher<Object>() {
@Override
public boolean matches(Object item) { public boolean matches(Object item) {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }


@Override
public void describeTo(Description description) { public void describeTo(Description description) {
description.appendText("SOME DESCRIPTION"); description.appendText("SOME DESCRIPTION");
} }
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ public void setProperty(String property) {
this.property = property; this.property = property;
} }


public void setWriteOnlyProperty(float property) { public void setWriteOnlyProperty(@SuppressWarnings("unused") float property) {
} }


@Override @Override
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public void testMatchesAllItemsInCollection() {
} }




private Matcher<? super String> mismatchable(final String string) { private static Matcher<? super String> mismatchable(final String string) {
return new TypeSafeDiagnosingMatcher<String>() { return new TypeSafeDiagnosingMatcher<String>() {
@Override @Override
protected boolean matchesSafely(String item, Description mismatchDescription) { protected boolean matchesSafely(String item, Description mismatchDescription) {
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public void testHasAReadableDescription() {
assertDescription("an empty collection", empty()); assertDescription("an empty collection", empty());
} }


private Collection<Object> collectionOfValues() { private static Collection<Object> collectionOfValues() {
return new ArrayList<Object>() {{ add("one"); add("three"); }}; return new ArrayList<Object>() {{ add("one"); add("three"); }};
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() {
assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good")))); assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good"))));
} }


@SuppressWarnings("unchecked")
public void testSupportsMixedTypes() { public void testSupportsMixedTypes() {
final Matcher<SampleSubClass> all = allOf( final Matcher<SampleSubClass> all = allOf(
equalTo(new SampleBaseClass("bad")), equalTo(new SampleBaseClass("bad")),
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -16,4 +16,9 @@ public String toString() {
public boolean equals(Object obj) { public boolean equals(Object obj) {
return obj instanceof SampleBaseClass && value.equals(((SampleBaseClass) obj).value); return obj instanceof SampleBaseClass && value.equals(((SampleBaseClass) obj).value);
} }

@Override
public int hashCode() {
return value.hashCode();
}
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testExtractsOriginalJavaDocFromSource() {
factoryMethod.getJavaDoc()); factoryMethod.getJavaDoc());
} }


private FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod, private static FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
String className, String input) { String className, String input) {
List<FactoryMethod> originalMethods = new ArrayList<FactoryMethod>(); List<FactoryMethod> originalMethods = new ArrayList<FactoryMethod>();
originalMethods.add(originalMethod); originalMethods.add(originalMethod);
Expand All @@ -56,7 +56,7 @@ private FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
return getFirstFactoryMethod(qDoxFactoryReader); return getFirstFactoryMethod(qDoxFactoryReader);
} }


private FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactoryReader) { private static FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactoryReader) {
Iterator<FactoryMethod> iterator = qDoxFactoryReader.iterator(); Iterator<FactoryMethod> iterator = qDoxFactoryReader.iterator();
iterator.hasNext(); iterator.hasNext();
return iterator.next(); return iterator.next();
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public static Matcher<Comparator<String>> generifiedType() {
return null; return null;
} }


@SuppressWarnings("unchecked") @SuppressWarnings("rawtypes")
@Factory @Factory
public static Matcher noGenerifiedType() { public static Matcher noGenerifiedType() {
return null; return null;
Expand Down Expand Up @@ -258,7 +258,7 @@ public void testCatchesSubclasses() {
assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod")); assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod"));
} }


private FactoryMethod readMethod(Class<?> cls, String methodName) { private static FactoryMethod readMethod(Class<?> cls, String methodName) {
for (FactoryMethod method : new ReflectiveFactoryReader(cls)) { for (FactoryMethod method : new ReflectiveFactoryReader(cls)) {
if (method.getName().equals(methodName)) { if (method.getName().equals(methodName)) {
return method; return method;
Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void testAddsMatcherFactoryMethodsToConfiguration() throws Exception {
hasItem(new FactoryMethod(AnotherMatcher.class.getName(), "matcher3", "org.hamcrest.CombinableMatcher"))); hasItem(new FactoryMethod(AnotherMatcher.class.getName(), "matcher3", "org.hamcrest.CombinableMatcher")));
} }


private InputSource createXml(String xml) { private static InputSource createXml(String xml) {
return new InputSource(new StringReader(xml)); return new InputSource(new StringReader(xml));
} }


Expand Down
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public void testMismatchContainsToStringValue() {
assertMismatchDescription(expectedMismatchString, hasToString(TO_STRING_RESULT), "Cheese"); assertMismatchDescription(expectedMismatchString, hasToString(TO_STRING_RESULT), "Cheese");
} }


private String descriptionOf(Matcher<?> matcher) { private static String descriptionOf(Matcher<?> matcher) {
return StringDescription.asString(matcher); return StringDescription.asString(matcher);
} }
} }
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -38,14 +38,17 @@ protected void setUp() throws Exception {
+ "</root>\n" + "</root>\n"
); );
ns = new NamespaceContext() { ns = new NamespaceContext() {
@Override
public String getNamespaceURI(String prefix) { public String getNamespaceURI(String prefix) {
return ("cheese".equals(prefix) ? "http://cheese.com" : null); return ("cheese".equals(prefix) ? "http://cheese.com" : null);
} }


@Override
public String getPrefix(String namespaceURI) { public String getPrefix(String namespaceURI) {
return ("http://cheese.com".equals(namespaceURI) ? "cheese" : null); return ("http://cheese.com".equals(namespaceURI) ? "cheese" : null);
} }


@Override
public Iterator<String> getPrefixes(String namespaceURI) { public Iterator<String> getPrefixes(String namespaceURI) {
HashSet<String> prefixes = new HashSet<String>(); HashSet<String> prefixes = new HashSet<String>();
String prefix = getPrefix(namespaceURI); String prefix = getPrefix(namespaceURI);
Expand Down

0 comments on commit aa3ddb6

Please sign in to comment.