org.testinfected.hamcrest.jpa
Class PersistenceMatchers

java.lang.Object
  extended by org.testinfected.hamcrest.jpa.PersistenceMatchers

public class PersistenceMatchers
extends java.lang.Object

A collection of hamcrest matchers to validate field values of persistent objects.


Method Summary
static
<T> org.hamcrest.Matcher<T>
componentEqualTo(T component)
          Checks that a component (aka value object) is equal to another given component.
static
<T> org.hamcrest.Matcher<T>
hasField(java.lang.String field)
          Checks that an entity has a given field, whatever its value.
static
<T,U> org.hamcrest.Matcher<T>
hasField(java.lang.String field, org.hamcrest.Matcher<U> value)
          Checks that an entity has a field with a value that is matched by the provided matcher.
static
<T> org.hamcrest.Matcher<T>
samePersistentFieldsAs(T entity)
          Checks that an entity has the same persistent field values than another entity.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

hasField

public static <T,U> org.hamcrest.Matcher<T> hasField(java.lang.String field,
                                                     org.hamcrest.Matcher<U> value)
Checks that an entity has a field with a value that is matched by the provided matcher. The field does not have to be public or to have a visible accessor. Field is accessed directly.

Parameters:
field - the name of a field
value - a matcher to validate the field value.

hasField

public static <T> org.hamcrest.Matcher<T> hasField(java.lang.String field)
Checks that an entity has a given field, whatever its value. The field does not have to be public or to have a visible accessor. Field is accessed directly.

Parameters:
field - the name of the expected field

componentEqualTo

public static <T> org.hamcrest.Matcher<T> componentEqualTo(T component)
Checks that a component (aka value object) is equal to another given component. A null component is considered to be equal to a component with only null persistent field values. Persistent fields of a component are fields that are neither static or transient.

Parameters:
component - the component to match against.

samePersistentFieldsAs

public static <T> org.hamcrest.Matcher<T> samePersistentFieldsAs(T entity)
Checks that an entity has the same persistent field values than another entity. Persistent fields of an entity are fields that are neither static or transient.

Parameters:
entity - the entity to compare to.


Copyright © 2012. All Rights Reserved.