This example illustrates how to setup a project to use the asserter object which can be use to assert Hamcrest matchers and capture the result in execution result objects.
To setup a project to use the asserter follow these steps:
The asserter is defined in the pineapple-hamcrest-support project, so add a Maven dependency to the project POM:
<dependency> <groupId>com.alpha.pineapple</groupId> <artifactId>pineapple-hamcrest-support</artifactId> </dependency>
If the project contain a Spring configuration file for definition of the beans used by the project then add an import directive to import the Spring configuration file from the Hamcrest matchers project:
<!-- Configures pineapple-hamcrest-matchers --> <import resource="classpath:com.alpha.pineapple.hamcrest-config.xml" />
Now the asserter is available in the project with the bean id asserter. The asserter is defined with the prototype scope.
To get access to the asserter bean from a class in the project, declare a field in a class and let Spring inject the asserter when the class is initialized:
/** * Hamcrest asserter. */ @Resource Asserter asserter;
To get access to the matchers implemented in the Hamcrest matchers project, declare a field in a class and let Spring inject the matcher factory when the class is initialized:
/** * Pineapple matcher factory. */ @Resource PineappleMatchers pineappleMatchers;