com.emarsys.ecommon.test.testng
Class TestAsserts

java.lang.Object
  extended by com.emarsys.ecommon.test.testng.TestAsserts

public class TestAsserts
extends java.lang.Object

Helper class for custom asserts in unit test cases. TODO not fully tested

Author:
Michael "kULO" Kulovits

Constructor Summary
TestAsserts()
           
 
Method Summary
static
<T,C extends java.util.Collection<T>>
void
equals(C actual, C expected)
          Checks whether the passed Collections contain the same elements or throws an AssertionError and prints more verbose logging messages than Assert if not.
static void equals(int[] actual, int[] expected)
          Checks whether the passed integer arrays contain the same elements or throws an AssertionError.
static
<K,V> void
equals(java.util.Map<K,V> actual, java.util.Map<K,V> expected)
          Checks whether the passed Maps contain the same key-value-pairs and throws an AssertionError and prints more verbose logging messages than Assert if not.
static void expectExceptions(RunnableTest test, java.lang.Class<?>... expectedExceptions)
           Runs the passed test and expects it to throw an Exception whose Class is one of the passed expected exception classes.
protected static boolean isExceptionExpected(java.lang.Exception ex, java.lang.Class<?>... expectedExceptions)
           
static void isPercentage(double p)
           
static void isPercentage(int p)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TestAsserts

public TestAsserts()
Method Detail

equals

public static void equals(int[] actual,
                          int[] expected)
Checks whether the passed integer arrays contain the same elements or throws an AssertionError.

Type Parameters:
T -
C -
Parameters:
actual -
expected -

equals

public static <T,C extends java.util.Collection<T>> void equals(C actual,
                                                                C expected)
Checks whether the passed Collections contain the same elements or throws an AssertionError and prints more verbose logging messages than Assert if not.

Type Parameters:
T -
C -
Parameters:
actual -
expected -

equals

public static <K,V> void equals(java.util.Map<K,V> actual,
                                java.util.Map<K,V> expected)
Checks whether the passed Maps contain the same key-value-pairs and throws an AssertionError and prints more verbose logging messages than Assert if not.

Type Parameters:
K -
V -
Parameters:
actual -
expected -

expectExceptions

public static void expectExceptions(RunnableTest test,
                                    java.lang.Class<?>... expectedExceptions)

Runs the passed test and expects it to throw an Exception whose Class is one of the passed expected exception classes.

The method is intended to mimic the behavior of an ordinary TestNG Test method with 'expectedExceptions' specified but aims at providing a more dynamic and flexible approach.

If no Exception or an unspecified/unexpected is thrown during the RunnableTest then an AssertionError will be raised.

Parameters:
test - - the test case encapsulated in a runnable
expectedExceptions -

isExceptionExpected

protected static boolean isExceptionExpected(java.lang.Exception ex,
                                             java.lang.Class<?>... expectedExceptions)

isPercentage

public static void isPercentage(double p)
Parameters:
p -

isPercentage

public static void isPercentage(int p)
Parameters:
p -


Copyright © 2010 emarsys AG. All Rights Reserved.