public class Expectamundo extends Object
Person expected = Expectamundo.prototype(Person.class);
Expectamundo.expect(expected.getFirstName()).isEqualTo("Jane");
Expectamundo.expect(expected.getLastName()).isEqualTo("Doe");
Expectamundo.expectThat(new Person("Jane","Doe")).matches(expected));
Person expected = Expectamundo.prototype(Person.class);
Expectamundo.expect(expected.getSiblings().get(0).getFirstName()).isEqualTo("John");
Expectamundo.expect(expected.getSiblings().get(0).getLastName()).isEqualTo("Doe");
Person jane = new Person("Jane","Doe");
jane.addSibling(new Person("John","Doe"));
Expectamundo.expectThat(jane).matches(expected));
To verifying map properties
Person expected = Expectamundo.prototype(Person.class);
Expectamundo.expect(expected.getSiblingMap().get("John").getFirstName()).isEqualTo("John");
Expectamundo.expect(expected.getSiblingMap().get("John").getLastName()).isEqualTo("Doe");
Person jane = new Person("Jane","Doe");
jane.addSibling(new Person("John","Doe"));
Expectamundo.expectThat(jane).matches(expected));
| Constructor and Description |
|---|
Expectamundo() |
| Modifier and Type | Method and Description |
|---|---|
static <V,T extends V> |
cast(V value,
Class<T> type)
Cast a polymorphic return type to the expected subtype whilst setting an expectation.
|
static <T> PrototypeChecker<T> |
checkThat(T actual)
Check the actual value matches the expectation set up in the prototype.
|
static PrototypeDateExpectation |
expect(Date property)
Setup an expectation for a date property on a
Prototype. |
static PrototypeStringExpectation |
expect(String property)
Setup an expectation for a string property on a
Prototype. |
static <E,T extends Collection<E>> |
expect(T property)
Setup an expectation for a collection property on a
Prototype. |
static <T> PrototypeObjectExpectation<T> |
expect(T property)
Setup an expectation for a object property on a
Prototype. |
static <T extends Comparable<T>> |
expect(T property)
Setup an expectation for a
Comparable property on a Prototype. |
static <T> PrototypeArrayExpectation<T> |
expect(T[] property)
Setup an expectation for a array property on a
Prototype. |
static <E,T extends Collection<E>> |
expectThat(T actual)
Verify the actual value matches the expectation set up in the prototype and throws and AssertionError if the match fails.
|
static <T> PrototypeVerifier<T> |
expectThat(T actual)
Verify the actual value matches the expectation set up in the prototype and throws and AssertionError if the match fails.
|
static boolean |
isPrototype(Object obj) |
static <T> org.hamcrest.Matcher<T> |
matcherFor(T expected)
Return a hamcrest
Matcher instance to support asserting the contents of an actual instance match the expected. |
static <T> T |
prototype(Class<T> type)
Create a new prototype instance against which expectations can be set.
|
static <T> T |
prototype(TypeReference<T> typeRef)
Create a new prototype instance against a generic type against which expectations can be set.
|
public static <T> T prototype(Class<T> type)
Person expected = Expectamundo.prototype(Person.class)
T - The type of the instance to create.type - The class of type of the prototype to create.public static <T> T prototype(TypeReference<T> typeRef)
List<String> expected = Expectamundo.prototype(new TypeReference<List<String>>(){})
T - The class of the prototype to createtypeRef - An instance of a TypeReference parameterized with the type to prototypepublic static <E,T extends Collection<E>> PrototypeCollectionExpectation<E,T> expect(T property)
Prototype. For example
Person expected = Expectamundo.prototype(Person.class) Expectamundo.expect(expected.getSiblings()).isEmpty(); Expectamundo.expectThat(new Person()).matches(expected);
T - the type of the collectionE - the type of elements in this collectionproperty - the value to set the expectation for.PrototypeCollectionExpectation to set collection expectations for the propertypublic static <T extends Comparable<T>> PrototypeComparableExpectation<T> expect(T property)
Comparable property on a Prototype. For example
Person expected = Expectamundo.prototype(Person.class) Expectamundo.expect(expected.getAge()).isComparableTo(29); Expectamundo.expectThat(new Person()).matches(expected);
T - the type of the propertyproperty - the value to set the expectation for.PrototypeComparableExpectation to set comparable expectations for the propertypublic static <T> PrototypeArrayExpectation<T> expect(T[] property)
Prototype. For example
Person expected = Expectamundo.prototype(Person.class) Expectamundo.expect(expected.getSiblings()).isEmpty(); Expectamundo.expectThat(new Person()).matches(expected);
T - the type of the arrayproperty - the value to set the expectation for.PrototypeArrayExpectation to set array expectations for the propertypublic static PrototypeStringExpectation expect(String property)
Prototype. For example
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).hasPattern("Sm.*");
Expectamundo.expectThat(new Person()).matches(expected);
property - the value to set the expectation for.PrototypeStringExpectation to set String expectations for the propertypublic static PrototypeDateExpectation expect(Date property)
Prototype. For example
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).hasPattern("Sm.*");
Expectamundo.expectThat(new Person()).matches(expected);
property - the value to set the expectation for.PrototypeDateExpectation to set date expectations for the propertypublic static <T> PrototypeObjectExpectation<T> expect(T property)
Prototype. For example
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).isEqualTo("Smith");
Expectamundo.expectThat(new Person()).matches(expected);
property - the value to set the expectation for.PrototypeObjectExpectation to set object expectations for the propertypublic static <T> PrototypeVerifier<T> expectThat(T actual)
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).isEqualTo("Smith");
Expectamundo.expectThat(new Person()).matches(expected);
actual - the actual instance to testPrototypeVerifier to allow the expectation to be suppliedpublic static <E,T extends Collection<E>> PrototypeListVerifier<E,T> expectThat(T actual)
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).isEqualTo("Smith");
Expectamundo.expectThat(new Person()).matches(expected);
actual - the actual instance to testPrototypeVerifier to allow the expectation to be suppliedpublic static <T> PrototypeChecker<T> checkThat(T actual)
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).isEqualTo("Smith");
Expectamundo.checkThat(new Person()).matches(expected);
actual - the actual instance to testPrototypeChecker to allow the expectation to be suppliedpublic static <V,T extends V> T cast(V value,
Class<T> type)
Person expected = Expectamundo.prototype(Person.class) Expectamundo.expect(Expectamundo.cast(expected.getProfession(), Doctor.class).getQualifications()).isNotEmpty()) Expectamundo.expectThat(new Person()).matches(expected);
V - the value typeT - the expected type of the valuevalue - the property value.type - the Class of the property value to cast to.public static <T> org.hamcrest.Matcher<T> matcherFor(T expected)
Matcher instance to support asserting the contents of an actual instance match the expected.
Person expected = Expectamundo.prototype(Person.class)
Expectamundo.expect(expected.getSurname()).isEqualTo("Smith")
MatcherAssert.assertThat(new Person(), Expectamundo.matches(expected))
T - The type of the prototypeexpected - The prototype with expectations defined against itpublic static boolean isPrototype(Object obj)
Copyright © 2015. All rights reserved.