Groovy Documentation

groovy.org.codenarc.test
[Groovy] Class TestUtil

java.lang.Object
  groovy.org.codenarc.test.TestUtil

class TestUtil

Contains common static utility methods for tests

Authors:
Chris Mair


Method Summary
static void assertContainsAll(String text, def strings)

Assert that the text contains each of the specified strings

static void assertContainsAllInOrder(String text, def strings)

Assert that the text contains each of the specified strings, in order

static void assertEqualSets(Collection collection1, Collection collection2)

Assert that the two collections have equal Sets of elements.

static List captureLog4JMessages(groovy.lang.Closure closure)

static String captureSystemOut(groovy.lang.Closure closure)

static boolean containsAll(String text, def strings)

Return true if the text contains each of the specified strings

static String shouldFail(Class expectedExceptionClass, groovy.lang.Closure code)

Assert that the specified code throws an exception of the specified type.

static String shouldFail(groovy.lang.Closure code)

Assert that the specified code throws an exception (of any type).

static String shouldFailWithMessageContaining(Class expectedExceptionClass, String expectedText, groovy.lang.Closure code)

Assert that the specified code throws an exception whose message contains the specified text.

static void shouldFailWithMessageContaining(def text, groovy.lang.Closure closure)

Assert that the specified closure should throw an exception whose message contains text

 
Methods inherited from class Object
wait, wait, wait, equals, toString, hashCode, getClass, notify, notifyAll
 

Method Detail

assertContainsAll

static void assertContainsAll(String text, def strings)
Assert that the text contains each of the specified strings
Parameters:
text - - the text to search
strings - - the Strings that must be present within text; toString() is invoked on each element


assertContainsAllInOrder

static void assertContainsAllInOrder(String text, def strings)
Assert that the text contains each of the specified strings, in order
Parameters:
text - - the text to search
strings - - the Strings that must be present within text, and appear in the order specified; toString() is applied to each.


assertEqualSets

static void assertEqualSets(Collection collection1, Collection collection2)
Assert that the two collections have equal Sets of elements. In other words, assert that the two collections are the same, ignoring ordering and duplicates.


captureLog4JMessages

static List captureLog4JMessages(groovy.lang.Closure closure)


captureSystemOut

static String captureSystemOut(groovy.lang.Closure closure)


containsAll

static boolean containsAll(String text, def strings)
Return true if the text contains each of the specified strings
Parameters:
text - - the text to search
strings - - the Strings to check for; toString() is invoked on each element


shouldFail

static String shouldFail(Class expectedExceptionClass, groovy.lang.Closure code)
Assert that the specified code throws an exception of the specified type. Return the thrown exception message.
throws:
AssertionError - if no exception is thrown by the code or if the thrown exception is not of the expected type
Returns:
the message from the thrown Exception
Parameters:
expectedExceptionClass - - the Class of exception that is expected; may be null
code - - the Closure containing the code to be executed, which is expected to throw an exception of the specified type


shouldFail

static String shouldFail(groovy.lang.Closure code)
Assert that the specified code throws an exception (of any type). Return the thrown exception message.
throws:
AssertionError - if no exception is thrown by the code or if the thrown exception is not of the expected type
Returns:
the message from the thrown Exception
Parameters:
code - - the Closure containing the code to be executed, which is expected to throw an exception of the specified type


shouldFailWithMessageContaining

static String shouldFailWithMessageContaining(Class expectedExceptionClass, String expectedText, groovy.lang.Closure code)
Assert that the specified code throws an exception whose message contains the specified text.
throws:
AssertionError - if no exception is thrown by the code or if the text is not contained in the exception message
Returns:
the thrown Exception message
Parameters:
expectedExceptionClass - - the class of the Throwable that is expected to be thrown
expectedText - - the text expected within the exception message
code - - the Closure containing the code to be executed, which is expected to throw an exception of the specified type


shouldFailWithMessageContaining

static void shouldFailWithMessageContaining(def text, groovy.lang.Closure closure)
Assert that the specified closure should throw an exception whose message contains text
Parameters:
text - - the text expected within the message; may be a single String or a List of Strings
closure - - the Closure to execute


 

Groovy Documentation