org.fest.assertions.api
Class Assertions

java.lang.Object
  extended by org.fest.assertions.api.Assertions

public class Assertions
extends Object

Entry point for assertion methods for different data types. Each method in this class is a static factory for the type-specific assertion objects. The purpose of this class is to make test code more readable.

For example:

 int removed = employees.removeFired();
 assertThat(removed).isZero();

 List<Employee> newEmployees = employees.hired(TODAY);
 assertThat(newEmployees).hasSize(6);
 

Author:
Alex Ruiz, Yvonne Wang, David DIDIER, Ted Young, Joel Costigliola, Matthieu Baechler

Constructor Summary
protected Assertions()
          Creates a new Assertions.
 
Method Summary
static
<T> Condition<T>
anyOf(Collection<Condition<T>> conditions)
          Creates a new AnyOf
static
<T> Condition<T>
anyOf(Condition<T>... conditions)
          Only delegate to AnyOf.anyOf(Condition...) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use AnyOf if you prefer).
static BigDecimalAssert assertThat(BigDecimal actual)
          Creates a new instance of BigDecimalAssert.
static BooleanAssert assertThat(boolean actual)
          Creates a new instance of BooleanAssert.
static BooleanAssert assertThat(Boolean actual)
          Creates a new instance of BooleanAssert.
static BooleanArrayAssert assertThat(boolean[] actual)
          Creates a new instance of BooleanArrayAssert.
static ImageAssert assertThat(BufferedImage actual)
          Creates a new instance of ImageAssert.
static ByteAssert assertThat(byte actual)
          Creates a new instance of ByteAssert.
static ByteAssert assertThat(Byte actual)
          Creates a new instance of ByteAssert.
static ByteArrayAssert assertThat(byte[] actual)
          Creates a new instance of ByteArrayAssert.
static CharacterAssert assertThat(char actual)
          Creates a new instance of CharacterAssert.
static CharArrayAssert assertThat(char[] actual)
          Creates a new instance of CharArrayAssert.
static CharacterAssert assertThat(Character actual)
          Creates a new instance of CharacterAssert.
static DateAssert assertThat(Date actual)
          Creates a new instance of DateAssert.
static DoubleAssert assertThat(double actual)
          Creates a new instance of DoubleAssert.
static DoubleAssert assertThat(Double actual)
          Creates a new instance of DoubleAssert.
static DoubleArrayAssert assertThat(double[] actual)
          Creates a new instance of DoubleArrayAssert.
static FileAssert assertThat(File actual)
          Creates a new instance of FileAssert.
static FloatAssert assertThat(float actual)
          Creates a new instance of FloatAssert.
static FloatAssert assertThat(Float actual)
          Creates a new instance of FloatAssert.
static FloatArrayAssert assertThat(float[] actual)
          Creates a new instance of FloatArrayAssert.
static InputStreamAssert assertThat(InputStream actual)
          Creates a new instance of InputStreamAssert.
static IntegerAssert assertThat(int actual)
          Creates a new instance of IntegerAssert.
static IntArrayAssert assertThat(int[] actual)
          Creates a new instance of IntArrayAssert.
static IntegerAssert assertThat(Integer actual)
          Creates a new instance of IntegerAssert.
static IterableAssert assertThat(Iterable<?> actual)
          Creates a new instance of IterableAssert.
static ListAssert assertThat(List<?> actual)
          Creates a new instance of ListAssert.
static LongAssert assertThat(long actual)
          Creates a new instance of LongAssert.
static LongAssert assertThat(Long actual)
          Creates a new instance of LongAssert.
static LongArrayAssert assertThat(long[] actual)
          Creates a new instance of LongArrayAssert.
static MapAssert assertThat(Map<?,?> actual)
          Creates a new instance of MapAssert.
static ObjectAssert assertThat(Object actual)
          Creates a new instance of ObjectAssert.
static ObjectArrayAssert assertThat(Object[] actual)
          Creates a new instance of ObjectArrayAssert.
static ShortAssert assertThat(short actual)
          Creates a new instance of ShortAssert.
static ShortAssert assertThat(Short actual)
          Creates a new instance of ShortAssert.
static ShortArrayAssert assertThat(short[] actual)
          Creates a new instance of ShortArrayAssert.
static StringAssert assertThat(String actual)
          Creates a new instance of StringAssert.
static ThrowableAssert assertThat(Throwable actual)
          Creates a new instance of ThrowableAssert.
static MapEntry entry(Object key, Object value)
          Only delegate to MapEntry.entry(Object, Object) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
static Properties extractProperty(String propertyName)
          Only delegate to Properties.extractProperty(String) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
static void fail(String failureMessage)
          Only delegate to Fail.fail(String) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
static void fail(String failureMessage, Throwable realCause)
          Only delegate to Fail.fail(String, Throwable) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
static void failBecauseExceptionWasNotThrown(Class<? extends Exception> exceptionClass)
          Only delegate to Fail.failBecauseExceptionWasNotThrown(Class) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)
          Only delegate to Fail.setRemoveFestRelatedElementsFromStackTrace(boolean) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Assertions

protected Assertions()
Creates a new Assertions.

Method Detail

assertThat

public static BigDecimalAssert assertThat(BigDecimal actual)
Creates a new instance of BigDecimalAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static BooleanAssert assertThat(boolean actual)
Creates a new instance of BooleanAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static BooleanAssert assertThat(Boolean actual)
Creates a new instance of BooleanAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static BooleanArrayAssert assertThat(boolean[] actual)
Creates a new instance of BooleanArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ImageAssert assertThat(BufferedImage actual)
Creates a new instance of ImageAssert. To read an image from the file system use ImageReader.readImageFrom(String).

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ByteAssert assertThat(byte actual)
Creates a new instance of ByteAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ByteAssert assertThat(Byte actual)
Creates a new instance of ByteAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ByteArrayAssert assertThat(byte[] actual)
Creates a new instance of ByteArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static CharacterAssert assertThat(char actual)
Creates a new instance of CharacterAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static CharArrayAssert assertThat(char[] actual)
Creates a new instance of CharArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static CharacterAssert assertThat(Character actual)
Creates a new instance of CharacterAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static IterableAssert assertThat(Iterable<?> actual)
Creates a new instance of IterableAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static DoubleAssert assertThat(double actual)
Creates a new instance of DoubleAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static DoubleAssert assertThat(Double actual)
Creates a new instance of DoubleAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static DoubleArrayAssert assertThat(double[] actual)
Creates a new instance of DoubleArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static FileAssert assertThat(File actual)
Creates a new instance of FileAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static InputStreamAssert assertThat(InputStream actual)
Creates a new instance of InputStreamAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static FloatAssert assertThat(float actual)
Creates a new instance of FloatAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static FloatAssert assertThat(Float actual)
Creates a new instance of FloatAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static FloatArrayAssert assertThat(float[] actual)
Creates a new instance of FloatArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static IntegerAssert assertThat(int actual)
Creates a new instance of IntegerAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static IntArrayAssert assertThat(int[] actual)
Creates a new instance of IntArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static IntegerAssert assertThat(Integer actual)
Creates a new instance of IntegerAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ListAssert assertThat(List<?> actual)
Creates a new instance of ListAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static LongAssert assertThat(long actual)
Creates a new instance of LongAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static LongAssert assertThat(Long actual)
Creates a new instance of LongAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static LongArrayAssert assertThat(long[] actual)
Creates a new instance of LongArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ObjectAssert assertThat(Object actual)
Creates a new instance of ObjectAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ObjectArrayAssert assertThat(Object[] actual)
Creates a new instance of ObjectArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static MapAssert assertThat(Map<?,?> actual)
Creates a new instance of MapAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ShortAssert assertThat(short actual)
Creates a new instance of ShortAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ShortAssert assertThat(Short actual)
Creates a new instance of ShortAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ShortArrayAssert assertThat(short[] actual)
Creates a new instance of ShortArrayAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static StringAssert assertThat(String actual)
Creates a new instance of StringAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static DateAssert assertThat(Date actual)
Creates a new instance of DateAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion object.

assertThat

public static ThrowableAssert assertThat(Throwable actual)
Creates a new instance of ThrowableAssert.

Parameters:
actual - the actual value.
Returns:
the created assertion Throwable.

setRemoveFestRelatedElementsFromStackTrace

public static void setRemoveFestRelatedElementsFromStackTrace(boolean removeFestRelatedElementsFromStackTrace)
Only delegate to Fail.setRemoveFestRelatedElementsFromStackTrace(boolean) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).


fail

public static void fail(String failureMessage)
Only delegate to Fail.fail(String) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).


fail

public static void fail(String failureMessage,
                        Throwable realCause)
Only delegate to Fail.fail(String, Throwable) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).


failBecauseExceptionWasNotThrown

public static void failBecauseExceptionWasNotThrown(Class<? extends Exception> exceptionClass)
Only delegate to Fail.failBecauseExceptionWasNotThrown(Class) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).


extractProperty

public static Properties extractProperty(String propertyName)
Only delegate to Properties.extractProperty(String) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).

Typical usage is to chain extractProperty with from method, see examples below :

 // extract simple property values having a java standard type (here String)
 assertThat(extractProperty("name").from(fellowshipOfTheRing)).contains("Boromir", "Gandalf", "Frodo", "Legolas")
                                                              .doesNotContain("Sauron", "Elrond");
                                                              
 // extracting property works also with user's types (here Race)
 assertThat(extractProperty("race").from(fellowshipOfTheRing)).contains(HOBBIT, ELF).doesNotContain(ORC);
 
 // extract nested property on Race
 assertThat(extractProperty("race.name").from(fellowshipOfTheRing)).contains("Hobbit", "Elf").doesNotContain("Orc");
 


entry

public static MapEntry entry(Object key,
                             Object value)
Only delegate to MapEntry.entry(Object, Object) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use Fail if you prefer).

Typical usage is to call entry in MapAssert contains assertion, see examples below :

 assertThat(ringBearers).contains(entry(oneRing, frodo), entry(nenya, galadriel));
 


anyOf

public static <T> Condition<T> anyOf(Condition<T>... conditions)
Only delegate to AnyOf.anyOf(Condition...) so that Assertions offers a full feature entry point to all Fest Assert features (but you can use AnyOf if you prefer).

Typical usage (jedi and sith are Condition) :

 assertThat("Vader").is(anyOf(jedi, sith));
 
See


anyOf

public static <T> Condition<T> anyOf(Collection<Condition<T>> conditions)
Creates a new AnyOf

Type Parameters:
T - the type of object the given condition accept.
Parameters:
conditions - the conditions to evaluate.
Returns:
the created AnyOf.
Throws:
NullPointerException - if the given collection is null.
NullPointerException - if any of the elements in the given collection is null.


Copyright © 2007-2012 FEST (Fixtures for Easy Software Testing). All Rights Reserved.