Permalink
Browse files

Finished up Java 6 conversion, plus some IDE warnings.

  • Loading branch information...
sf105 committed Apr 3, 2012
1 parent bca8f06 commit aa3ddb627128b6044fa1fad257551c35e2e6fb02
Showing with 56 additions and 23 deletions.
  1. +1 −0 .gitignore
  2. +2 −3 build.xml
  3. +1 −0 hamcrest-core/src/main/java/org/hamcrest/CustomMatcher.java
  4. +2 −1 hamcrest-core/src/main/java/org/hamcrest/DiagnosingMatcher.java
  5. +1 −0 hamcrest-core/src/main/java/org/hamcrest/FeatureMatcher.java
  6. +1 −0 hamcrest-core/src/main/java/org/hamcrest/TypeSafeDiagnosingMatcher.java
  7. +1 −0 hamcrest-core/src/main/java/org/hamcrest/TypeSafeMatcher.java
  8. +2 −1 hamcrest-core/src/main/java/org/hamcrest/core/Every.java
  9. +2 −0 hamcrest-core/src/main/java/org/hamcrest/core/IsAnything.java
  10. +1 −0 hamcrest-core/src/main/java/org/hamcrest/core/IsInstanceOf.java
  11. +1 −1 hamcrest-core/src/main/java/org/hamcrest/core/IsNull.java
  12. +2 −0 hamcrest-core/src/main/java/org/hamcrest/core/IsSame.java
  13. +4 −2 hamcrest-examples/src/main/java/org/hamcrest/examples/junit4/ExampleWithAssertThat.java
  14. +1 −1 hamcrest-generator/src/main/java/org/hamcrest/generator/QDoxFactoryReader.java
  15. +1 −1 hamcrest-generator/src/main/java/org/hamcrest/generator/QuickReferenceWriter.java
  16. +1 −1 hamcrest-generator/src/main/java/org/hamcrest/generator/ReflectiveFactoryReader.java
  17. +1 −0 hamcrest-library/src/main/java/org/hamcrest/beans/HasPropertyWithValue.java
  18. +1 −0 hamcrest-library/src/main/java/org/hamcrest/collection/IsArray.java
  19. +1 −0 hamcrest-library/src/main/java/org/hamcrest/collection/IsArrayContaining.java
  20. +2 −1 hamcrest-library/src/main/java/org/hamcrest/collection/IsIn.java
  21. +1 −0 hamcrest-library/src/main/java/org/hamcrest/collection/IsMapContaining.java
  22. +1 −0 hamcrest-library/src/main/java/org/hamcrest/number/IsCloseTo.java
  23. +1 −1 hamcrest-library/src/main/java/org/hamcrest/number/OrderingComparison.java
  24. +1 −0 hamcrest-library/src/main/java/org/hamcrest/object/IsEventFrom.java
  25. +2 −0 hamcrest-library/src/main/java/org/hamcrest/text/IsEmptyString.java
  26. +1 −0 hamcrest-library/src/main/java/org/hamcrest/text/IsEqualIgnoringCase.java
  27. +1 −0 hamcrest-library/src/main/java/org/hamcrest/text/IsEqualIgnoringWhiteSpace.java
  28. +2 −0 hamcrest-unit-test/src/main/java/org/hamcrest/BaseMatcherTest.java
  29. +1 −1 hamcrest-unit-test/src/main/java/org/hamcrest/beans/HasPropertyWithValueTest.java
  30. +1 −1 hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsCollectionContainingTest.java
  31. +1 −1 hamcrest-unit-test/src/main/java/org/hamcrest/collection/IsEmptyCollectionTest.java
  32. +0 −1 hamcrest-unit-test/src/main/java/org/hamcrest/core/AllOfTest.java
  33. +5 −0 hamcrest-unit-test/src/main/java/org/hamcrest/core/SampleBaseClass.java
  34. +2 −2 hamcrest-unit-test/src/main/java/org/hamcrest/generator/QDoxFactoryReaderTest.java
  35. +2 −2 hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReaderTest.java
  36. +1 −1 hamcrest-unit-test/src/main/java/org/hamcrest/generator/config/XmlConfiguratorTest.java
  37. +1 −1 hamcrest-unit-test/src/main/java/org/hamcrest/object/HasToStringTest.java
  38. +3 −0 hamcrest-unit-test/src/main/java/org/hamcrest/xml/HasXPathTest.java
View
@@ -0,0 +1 @@
+/build
View
@@ -197,7 +197,7 @@
<target name="javadoc" depends="library">
<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">
<classpath>
@@ -215,9 +215,8 @@
<group title="Matcher Library" packages="org.hamcrest.*"/>
<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://junit.sourceforge.net/javadoc_40/"/>
+ <link offline="false" href="http://kentbeck.github.com/junit/javadoc/latest/"/>
</javadoc>
</target>
@@ -30,6 +30,7 @@ public CustomMatcher(String description) {
this.fixedDescription = description;
}
+ @Override
public final void describeTo(Description description) {
description.appendText(fixedDescription);
}
@@ -7,7 +7,8 @@
*/
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);
}
@@ -46,6 +46,7 @@ protected boolean matchesSafely(T actual, Description mismatchDescription) {
return true;
};
+ @Override
public final void describeTo(Description description) {
description.appendText(featureDescription).appendText(" ")
.appendDescriptionOf(subMatcher);
@@ -49,6 +49,7 @@ protected TypeSafeDiagnosingMatcher() {
this(TYPE_FINDER);
}
+ @Override
@SuppressWarnings("unchecked")
public final boolean matches(Object item) {
return item != null
@@ -59,6 +59,7 @@ protected void describeMismatchSafely(T item, Description mismatchDescription) {
* If you need to override this, there's no point on extending TypeSafeMatcher.
* Instead, extend the {@link BaseMatcher}.
*/
+ @Override
@SuppressWarnings({"unchecked"})
public final boolean matches(Object item) {
return item != null
@@ -24,7 +24,8 @@ public boolean matchesSafely(Iterable<T> collection, Description mismatchDescrip
return true;
}
- public void describeTo(Description description) {
+ @Override
+ public void describeTo(Description description) {
description.appendText("every item is ").appendDescriptionOf(matcher);
}
@@ -23,10 +23,12 @@ public IsAnything(String message) {
this.message = message;
}
+ @Override
public boolean matches(Object o) {
return true;
}
+ @Override
public void describeTo(Description description) {
description.appendText(message);
}
@@ -54,6 +54,7 @@ protected boolean matches(Object item, Description mismatchDescription) {
return true;
}
+ @Override
public void describeTo(Description description) {
description.appendText("an instance of ")
.appendText(expectedClass.getName());
@@ -42,7 +42,7 @@ public void describeTo(Description description) {
* Matches if value is null. With type inference.
*/
@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>();
}
@@ -18,10 +18,12 @@ public IsSame(T object) {
this.object = object;
}
+ @Override
public boolean matches(Object arg) {
return arg == object;
}
+ @Override
public void describeTo(Description description) {
description.appendText("sameInstance(")
.appendValue(object)
@@ -51,14 +51,16 @@ public void showMismatch() {
assertThat(complicated, shouldBe("the wrong thing"));
}
- private Matcher<ComplicatedClass> shouldBe(String string) {
+ private static Matcher<ComplicatedClass> shouldBe(final String string) {
return new TypeSafeMatcher<ComplicatedClass>() {
@Override
public void describeTo(Description description) { } // no op
@Override
public boolean matchesSafely(ComplicatedClass item) { return false; }
@Override
- public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {} // no op
+ public void describeMismatchSafely(ComplicatedClass item, Description mismatchDescription) {
+ mismatchDescription.appendText(string);
+ }
};
}
@@ -94,7 +94,7 @@ private JavaMethod findMethodInSource(FactoryMethod factoryMethod) {
/**
* 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();
DocletTag[] tags = methodSource.getTags();
if ((comment == null || comment.trim().length() == 0) && tags.length == 0) {
@@ -53,7 +53,7 @@ public void writeMethod(String generatedMethodName, FactoryMethod factoryMethod)
out.println();
}
- private String removePackageNames(String in) {
+ private static String removePackageNames(String in) {
// Simplify fully qualified names (allowing for trailing '...').
return in == null ? "" : in.replaceAll("[^<>]*\\.([^\\.])", "$1");
}
@@ -117,7 +117,7 @@ private boolean hasFactoryAnnotation(Method javaMethod) {
}
}
- private FactoryMethod buildFactoryMethod(Method javaMethod) {
+ private static FactoryMethod buildFactoryMethod(Method javaMethod) {
FactoryMethod result = new FactoryMethod(
javaMethod.getDeclaringClass().getName(),
javaMethod.getName(),
@@ -111,6 +111,7 @@ private Method findReadMethod(Object argument, Description mismatchDescription)
return readMethod;
}
+ @Override
public void describeTo(Description description) {
description.appendText("hasProperty(");
description.appendValue(propertyName);
@@ -43,6 +43,7 @@ public void describeMismatchSafely(T[] actual, Description mismatchDescription)
}
}
+ @Override
public void describeTo(Description description) {
description.appendList(descriptionStart(), descriptionSeparator(), descriptionEnd(),
Arrays.asList(elementMatchers));
@@ -33,6 +33,7 @@ public void describeMismatchSafely(T[] item, Description mismatchDescription) {
super.describeMismatch(Arrays.asList(item), mismatchDescription);
};
+ @Override
public void describeTo(Description description) {
description
.appendText("an array containing ")
@@ -19,11 +19,12 @@ public IsIn(T[] elements) {
collection = Arrays.asList(elements);
}
- @SuppressWarnings({"SuspiciousMethodCalls"})
+ @Override
public boolean matches(Object o) {
return collection.contains(o);
}
+ @Override
public void describeTo(Description buffer) {
buffer.appendText("one of ");
buffer.appendValueList("{", ", ", "}", collection);
@@ -35,6 +35,7 @@ public void describeMismatchSafely(Map<? extends K, ? extends V> map, Descriptio
mismatchDescription.appendText("map was ").appendValueList("[", ", ", "]", map.entrySet());
}
+ @Override
public void describeTo(Description description) {
description.appendText("map containing [")
.appendDescriptionOf(keyMatcher)
@@ -33,6 +33,7 @@ public void describeMismatchSafely(Double item, Description mismatchDescription)
.appendValue(actualDelta(item));
}
+ @Override
public void describeTo(Description description) {
description.appendText("a numeric value within ")
.appendValue(delta)
@@ -48,7 +48,7 @@ public void describeTo(Description description) {
description.appendText(" ").appendValue(expected);
}
- private String asText(int comparison) {
+ private static String asText(int comparison) {
return comparisonDescriptions[comparison + 1];
}
@@ -41,6 +41,7 @@ private boolean eventHasSameSource(EventObject ev) {
return ev.getSource() == source;
}
+ @Override
public void describeTo(Description description) {
description.appendText("an event of type ")
.appendText(eventClass.getName())
@@ -17,10 +17,12 @@
@SuppressWarnings("unchecked")
private static final Matcher<String> NULL_OR_EMPTY_INSTANCE = anyOf(nullValue(), INSTANCE);
+ @Override
public boolean matches(Object item) {
return item != null && item instanceof String && ((String) item).equals("");
}
+ @Override
public void describeTo(Description description) {
description.appendText("an empty string");
}
@@ -34,6 +34,7 @@ public void describeMismatchSafely(String item, Description mismatchDescription)
mismatchDescription.appendText("was ").appendText(item);
}
+ @Override
public void describeTo(Description description) {
description.appendText("equalToIgnoringCase(")
.appendValue(string)
@@ -34,6 +34,7 @@ public void describeMismatchSafely(String item, Description mismatchDescription)
mismatchDescription.appendText("was ").appendText(stripSpace(item));
}
+ @Override
public void describeTo(Description description) {
description.appendText("equalToIgnoringWhiteSpace(")
.appendValue(string)
@@ -6,10 +6,12 @@
public void testDescribesItselfWithToStringMethod() {
Matcher<Object> someMatcher = new BaseMatcher<Object>() {
+ @Override
public boolean matches(Object item) {
throw new UnsupportedOperationException();
}
+ @Override
public void describeTo(Description description) {
description.appendText("SOME DESCRIPTION");
}
@@ -106,7 +106,7 @@ public void setProperty(String property) {
this.property = property;
}
- public void setWriteOnlyProperty(float property) {
+ public void setWriteOnlyProperty(@SuppressWarnings("unused") float property) {
}
@Override
@@ -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>() {
@Override
protected boolean matchesSafely(String item, Description mismatchDescription) {
@@ -29,7 +29,7 @@ public void testHasAReadableDescription() {
assertDescription("an empty collection", empty());
}
- private Collection<Object> collectionOfValues() {
+ private static Collection<Object> collectionOfValues() {
return new ArrayList<Object>() {{ add("one"); add("three"); }};
}
}
@@ -34,7 +34,6 @@ public void testEvaluatesToTheTheLogicalConjunctionOfManyOtherMatchers() {
assertThat("good", not(allOf(equalTo("good"), equalTo("good"), equalTo("bad"), equalTo("good"), equalTo("good"))));
}
- @SuppressWarnings("unchecked")
public void testSupportsMixedTypes() {
final Matcher<SampleSubClass> all = allOf(
equalTo(new SampleBaseClass("bad")),
@@ -16,4 +16,9 @@ public String toString() {
public boolean equals(Object obj) {
return obj instanceof SampleBaseClass && value.equals(((SampleBaseClass) obj).value);
}
+
+ @Override
+ public int hashCode() {
+ return value.hashCode();
+ }
}
@@ -43,7 +43,7 @@ public void testExtractsOriginalJavaDocFromSource() {
factoryMethod.getJavaDoc());
}
- private FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
+ private static FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
String className, String input) {
List<FactoryMethod> originalMethods = new ArrayList<FactoryMethod>();
originalMethods.add(originalMethod);
@@ -56,7 +56,7 @@ private FactoryMethod wrapUsingQDoxedSource(FactoryMethod originalMethod,
return getFirstFactoryMethod(qDoxFactoryReader);
}
- private FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactoryReader) {
+ private static FactoryMethod getFirstFactoryMethod(QDoxFactoryReader qDoxFactoryReader) {
Iterator<FactoryMethod> iterator = qDoxFactoryReader.iterator();
iterator.hasNext();
return iterator.next();
@@ -100,7 +100,7 @@ public void testOnlyReadsPublicStaticAnnotatedMethodsThatReturnMatcher() {
return null;
}
- @SuppressWarnings("unchecked")
+ @SuppressWarnings("rawtypes")
@Factory
public static Matcher noGenerifiedType() {
return null;
@@ -258,7 +258,7 @@ public void testCatchesSubclasses() {
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)) {
if (method.getName().equals(methodName)) {
return method;
@@ -43,7 +43,7 @@ public void testAddsMatcherFactoryMethodsToConfiguration() throws Exception {
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));
}
@@ -45,7 +45,7 @@ public void testMismatchContainsToStringValue() {
assertMismatchDescription(expectedMismatchString, hasToString(TO_STRING_RESULT), "Cheese");
}
- private String descriptionOf(Matcher<?> matcher) {
+ private static String descriptionOf(Matcher<?> matcher) {
return StringDescription.asString(matcher);
}
}
@@ -38,14 +38,17 @@ protected void setUp() throws Exception {
+ "</root>\n"
);
ns = new NamespaceContext() {
+ @Override
public String getNamespaceURI(String prefix) {
return ("cheese".equals(prefix) ? "http://cheese.com" : null);
}
+ @Override
public String getPrefix(String namespaceURI) {
return ("http://cheese.com".equals(namespaceURI) ? "cheese" : null);
}
+ @Override
public Iterator<String> getPrefixes(String namespaceURI) {
HashSet<String> prefixes = new HashSet<String>();
String prefix = getPrefix(namespaceURI);

0 comments on commit aa3ddb6

Please sign in to comment.