Skip to content

Commit 90fce3d

Browse files
author
joe.walnes
committed
Generator recognizes @factory methods that return subclass of Matcher. (Fix by David Saff)
1 parent 472df94 commit 90fce3d

4 files changed

Lines changed: 19 additions & 1 deletion

File tree

‎CHANGES.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
== Version 1.1: In Development ==
2+
3+
* Generator recognizes @Factory methods that return subclass of Matcher.
4+
(Fix by David Saff)
5+
16
== Version 1.0: Released Dec 15 2006 ==
27

38
Initial release.

‎README.txt‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ Contributors:
8585
- Neil Dunn
8686
- Dan North
8787
- Magne Rasmussen
88+
- David Saff
8889

8990
Also, thanks to everyone who has worked on DynaMock, nMock,
9091
jMock, EasyMock and MiniMock! These libraries inspired

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ protected boolean isFactoryMethod(Method javaMethod) {
8282
return isStatic(javaMethod.getModifiers())
8383
&& isPublic(javaMethod.getModifiers())
8484
&& javaMethod.getAnnotation(Factory.class) != null
85-
&& javaMethod.getReturnType().isAssignableFrom(Matcher.class);
85+
&& Matcher.class.isAssignableFrom(javaMethod.getReturnType());
8686
}
8787

8888
private FactoryMethod buildFactoryMethod(Method javaMethod) {

‎hamcrest-unit-test/src/main/java/org/hamcrest/generator/ReflectiveFactoryReaderTest.java‎

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package org.hamcrest.generator;
22

33
import junit.framework.TestCase;
4+
import org.hamcrest.BaseMatcher;
45
import org.hamcrest.Factory;
56
import org.hamcrest.Matcher;
67

@@ -245,6 +246,17 @@ public void testReadsGenericTypeParameters() {
245246
assertEquals("V", method.getParameters().get(1).getType());
246247
}
247248

249+
public static class SubclassOfMatcher {
250+
@Factory
251+
public static BaseMatcher subclassMethod() {
252+
return null;
253+
}
254+
}
255+
256+
public void testCatchesSubclasses() {
257+
assertNotNull(readMethod(SubclassOfMatcher.class, "subclassMethod"));
258+
}
259+
248260
private FactoryMethod readMethod(Class cls, String methodName) {
249261
for (FactoryMethod method : new ReflectiveFactoryReader(cls)) {
250262
if (method.getName().equals(methodName)) {

0 commit comments

Comments
 (0)