views:

50

answers:

1

I sat down to write a matcher today and decided to take a quick look at the jmock documentation to refresh my memory on the process, and noticed a reference to the org.hamcrest.Factory annotation. The documentation for the annotation states.

Marks a Hamcrest static factory method so tools recognise them. A factory method is an equivalent to a named constructor.

Do any tools actually use this annotation?

+2  A: 

As explained in the Hamcrest tutorial, the Factory annotation is used by a Hamcrest code generator, org.hamcrest.generator.config.XmlConfigurator. It generates a Java source file that contains all factories from a configured set of classes, so that you can statically import all of them by using a single static import.

I have not used this feature yet, because I manually collect my self-written matchers in a factory class as soon as I write the matcher, and on usage I statically import each factory method by itself (using the Eclipse "Favorites" feature for auto-import).

Christian Semrau