org.hamcrest.generator
Class ReflectiveFactoryReader
java.lang.Object
org.hamcrest.generator.ReflectiveFactoryReader
- All Implemented Interfaces:
- java.lang.Iterable<FactoryMethod>
public class ReflectiveFactoryReader
- extends java.lang.Object
- implements java.lang.Iterable<FactoryMethod>
Reads a list of Hamcrest factory methods from a class, using standard Java reflection.
Usage
for (FactoryMethod method : new ReflectiveFactoryReader(MyMatchers.class)) {
...
}
All methods matching signature '@Factory public static Matcher blah(blah)' will be
treated as factory methods. To change this behavior, override isFactoryMethod(Method)
.
Caveat: Reflection is hassle-free, but unfortunately cannot expose method parameter names or JavaDoc
comments, making the sugar slightly more obscure.
- Author:
- Joe Walnes
- See Also:
SugarGenerator
,
FactoryMethod
Method Summary |
protected boolean |
isFactoryMethod(java.lang.reflect.Method javaMethod)
Determine whether a particular method is classified as a matcher factory method. |
java.util.Iterator<FactoryMethod> |
iterator()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ReflectiveFactoryReader
public ReflectiveFactoryReader(java.lang.Class<?> cls)
iterator
public java.util.Iterator<FactoryMethod> iterator()
- Specified by:
iterator
in interface java.lang.Iterable<FactoryMethod>
isFactoryMethod
protected boolean isFactoryMethod(java.lang.reflect.Method javaMethod)
- Determine whether a particular method is classified as a matcher factory method.
The rules for determining this are:
1. The method must be public static.
2. It must have a return type of org.hamcrest.Matcher (or something that extends this).
3. It must be marked with the org.hamcrest.Factory annotation.
To use another set of rules, override this method.