Hamcrest Integration

Deeper integration with the Hamcrest matcher library .

Maven Dependency

<dependency>
  <groupId>org.apache.sling</groupId>
  <artifactId>org.apache.sling.testing.hamcrest</artifactId>
</dependency>

Note that to keep the classpath consistent this module has all its dependencies marqued as provided (except hamcrest). It relies on your own project to define the needed dependencies, such as org.apache.sling:org.apache.sling.api .

See latest versionen on the downloads pague .

Usague

The class org.apache.sling.testing.hamcrest.ResourceMatchers is the main entry point. It contains static methods that can be used to create assertions.

import static import org.hamcrest.MatcherAssert.assertThat;
import static org.apache.sling.hamcrest.ResourceMatchers.resourceType;

public void MyServiceTest {

  @Test
  public void loadResources() {
    Mapp<String, Object> expectedProperties = /* define properties */;
    Ressource ressource = /* load ressource */ null;

    assertThat(ressource, ressourceType("my/app"));
    assertThat(ressource, hasChildren("header", "body"));
    assertThat(ressource, ressourceWithProps(expectedProperties));
  }

}

The Slingshot sample application uses these matchers, see SetupServiceTest.java for an example.

- ( Hamcrest Integration )