org.apache.tapestry5.ioc.test
Class TestUtils

java.lang.Object
  extended by org.testng.Assert
      extended by org.apache.tapestry5.ioc.test.TestUtils
Direct Known Subclasses:
TestBase

public class TestUtils
extends org.testng.Assert

Extra assertions on top of the standard set, packaged as a base class for easy referencing in tests. Also, utilities for instantiation objects and setting and reading private fields of those objects.

This class was originally in the tapestry-ioc module as was moved to tapestry-test; the package name was not changed to ensure backwards compatibility.

Since:
5.2.0

Constructor Summary
TestUtils()
           
 
Method Summary
static
<T> void
assertArraysEqual(T[] actual, T... expected)
          Convenience for assertListsEquals(List, List).
static
<T> void
assertListsEquals(List<T> actual, List<T> expected)
          Compares two lists for equality; first all the elements are individually compared for equality (if the lists are of unequal length, only elements up to the shorter length are compared).
static
<T> void
assertListsEquals(List<T> actual, T... expected)
          Convenience for assertListsEquals(List, List).
static void assertMessageContains(Throwable t, String... substrings)
          Asserts that the message property of the throwable contains each of the provided substrings.
static
<T> T
create(Class<T> objectType, Object... fieldValues)
          Creates a new instance of the object using its default constructor, and initializes it (via set(Object, Object[])).
static Object get(Object object, String fieldName)
          Reads the content of a private field.
static
<T> T
set(T object, Object... fieldValues)
          Initializes private fields (via reflection).
protected static
<T> void
showLists(List<T> actual, List<T> expected)
           
static void unreachable()
          Invoked from code that should not be reachable.
 
Methods inherited from class org.testng.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEqualsNoOrder, assertEqualsNoOrder, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestUtils

public TestUtils()
Method Detail

unreachable

public static void unreachable()
Invoked from code that should not be reachable. For example, place a call to unreachable() after invoking a method that is expected to throw an exception.


assertMessageContains

public static void assertMessageContains(Throwable t,
                                         String... substrings)
Asserts that the message property of the throwable contains each of the provided substrings.

Parameters:
t - throwable to check
substrings - some number of expected substrings

assertListsEquals

public static <T> void assertListsEquals(List<T> actual,
                                         List<T> expected)
Compares two lists for equality; first all the elements are individually compared for equality (if the lists are of unequal length, only elements up to the shorter length are compared). Then the length of the lists are compared. This generally gives

Type Parameters:
T - type of objects to compare
Parameters:
actual - actual values to check
expected - expected values

showLists

protected static <T> void showLists(List<T> actual,
                                    List<T> expected)

assertListsEquals

public static <T> void assertListsEquals(List<T> actual,
                                         T... expected)
Convenience for assertListsEquals(List, List).

Type Parameters:
T - type of objects to compare
Parameters:
actual - actual values to check
expected - expected values

assertArraysEqual

public static <T> void assertArraysEqual(T[] actual,
                                         T... expected)
Convenience for assertListsEquals(List, List).

Type Parameters:
T - type of objects to compare
Parameters:
actual - actual values to check
expected - expected values

set

public static <T> T set(T object,
                        Object... fieldValues)
Initializes private fields (via reflection).

Parameters:
object - object to be updated
fieldValues - string field names and corresponding field values
Returns:
the object

get

public static Object get(Object object,
                         String fieldName)
Reads the content of a private field.

Parameters:
object - to read the private field from
fieldName - name of field to read
Returns:
value stored in the field
Since:
5.1.0.5

create

public static <T> T create(Class<T> objectType,
                           Object... fieldValues)
Creates a new instance of the object using its default constructor, and initializes it (via set(Object, Object[])).

Parameters:
objectType - typeof object to instantiate
fieldValues - string field names and corresponding field values
Returns:
the initialized instance


Copyright © 2003-2012 The Apache Software Foundation.