Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Do any tools use the hamcrest Factory annotation?

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?

like image 240
sonstone Avatar asked Jul 29 '10 14:07

sonstone


People also ask

What is Hamcrest used for?

Hamcrest is a framework that assists writing software tests in the Java programming language. It supports creating customized assertion matchers ('Hamcrest' is an anagram of 'matchers'), allowing match rules to be defined declaratively. These matchers have uses in unit testing frameworks such as JUnit and jMock.

Does Hamcrest come with JUnit?

Hamcrest is the well-known framework used for unit testing in the Java ecosystem. It's bundled in JUnit and simply put, it uses existing predicates – called matcher classes – for making assertions.

Why are there Hamcrest matchers?

Purpose of the Hamcrest matcher framework. Hamcrest is a widely used framework for unit testing in the Java world. Hamcrest target is to make your tests easier to write and read. For this, it provides additional matcher classes which can be used in test for example written with JUnit.


1 Answers

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).

like image 125
Christian Semrau Avatar answered Nov 04 '22 07:11

Christian Semrau