org.progeeks.junit
Class ContextualTestCase

java.lang.Object
  extended by junit.framework.Assert
      extended by junit.framework.TestCase
          extended by org.progeeks.junit.ContextualTestCase
All Implemented Interfaces:
junit.framework.Test

public abstract class ContextualTestCase
extends junit.framework.TestCase

Abstract base class for test cases which use a test context. Takes care of setting up and tearing down the test context using any configured test fixture. Test cases which require test contexts should extend this class and implement their own test methods.

This class also supports the ability to test conditions in test context using the template expression processor to determine the values to test. It provides various assert methods that are analogous to the standard assert methods in junit.framework.Assert.

Version:
$Revision: 1.12 $
Author:
Paul Wisneskey

Nested Class Summary
static class ContextualTestCase.ContextTest
          Abstract base class for all of the context test classes.
static class ContextualTestCase.EqualsTest
          Context test that checks to see if the value of the template expression is equal to an expected value.
static class ContextualTestCase.FalseTest
          Context test that checks to see if the value of the template expression is false.
static class ContextualTestCase.NotNullTest
          Context test that checks to see if the value of the template expression is not null.
static class ContextualTestCase.NotSameTest
          Context test that checks to see if the value of the template expression is not the same as an expected value.
static class ContextualTestCase.NullTest
          Context test that checks to see if the value of the template expression is null.
static class ContextualTestCase.SameTest
          Context test that checks to see if the value of the template expression is the same as an expected value.
static class ContextualTestCase.TrueTest
          Context test that checks to see if the value of the template expression is true
 
Constructor Summary
ContextualTestCase()
          Constructor that does not set the test case name.
ContextualTestCase(java.lang.String name)
          Constructor that sets the test case name.
 
Method Summary
static void assertEquals(java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is equal to the expected value.
static void assertEquals(java.lang.String message, java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is equal to the expected value.
static void assertFalse(java.lang.String message, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is false.
static void assertFalse(TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is false.
static void assertNotNull(java.lang.String message, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is not null.
static void assertNotNull(TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is not null.
static void assertNotSame(java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation does not refer to the expected object.
static void assertNotSame(java.lang.String message, java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation does not refer to the expected object.
static void assertNull(java.lang.String message, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is null.
static void assertNull(TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is null.
static void assertSame(java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation refers to the expected object.
static void assertSame(java.lang.String message, java.lang.Object expected, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation refers to the expected object.
static void assertTrue(java.lang.String message, TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is true.
static void assertTrue(TemplateExpressionProcessor.TemplateExpression expression)
          Asserts that the value returned by the expression evaluation is true.
 java.util.List getContextTests()
          Returns the list of context tests to apply after each test method.
 TestContext getTestContext()
          Returns the test context for the test case.
 BeanConfigurator getTestContextFactory()
          Returns the context factory for generating test contexts.
protected  void runContextTests()
           
protected  void runTest()
          Method invoked to actually run a test method.
 void setContextTests(java.util.List contextTests)
          Sets the list of context tests to apply after each test method.
 void setTestContext(TestContext context)
          Set the test context for the test case.
 void setTestContextFactory(BeanConfigurator contextFactory)
          Sets the context factory for generating test contexts.
protected  void setUp()
          Sets up for a run of the test case using the test fixture (if one is configured) to initialize the test context.
protected  void tearDown()
          Cleans up after a run of the test case by using the test fixture (if one is configured) to tear down the test context.
 java.lang.String toString()
          Override to return more specific description of what case and context this instance is running.
 
Methods inherited from class junit.framework.TestCase
countTestCases, createResult, getName, run, run, runBare, setName
 
Methods inherited from class junit.framework.Assert
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, fail, fail
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

ContextualTestCase

public ContextualTestCase()
Constructor that does not set the test case name. If the name is not set and the instance is being loaded via the JUnitHandler, the handler will use introspection to determine the test methods and create an instance for each method. In this case, factories for the contexts should be configured unless the test fixture is guaranteed to reset it each time.


ContextualTestCase

public ContextualTestCase(java.lang.String name)
Constructor that sets the test case name. The test case is the method name JUnit will invoke as the test method.

Parameters:
name - Test case name.
Method Detail

setTestContext

public void setTestContext(TestContext context)
Set the test context for the test case.

Parameters:
context - New test context.

getTestContext

public TestContext getTestContext()
Returns the test context for the test case.

Returns:
Test context.

setTestContextFactory

public void setTestContextFactory(BeanConfigurator contextFactory)
Sets the context factory for generating test contexts.

Parameters:
contextFactory - New test context factory.

getTestContextFactory

public BeanConfigurator getTestContextFactory()
Returns the context factory for generating test contexts.

Returns:
Context factory or null if none configured.

setContextTests

public void setContextTests(java.util.List contextTests)
Sets the list of context tests to apply after each test method.


getContextTests

public java.util.List getContextTests()
Returns the list of context tests to apply after each test method.


setUp

protected void setUp()
              throws java.lang.Exception
Sets up for a run of the test case using the test fixture (if one is configured) to initialize the test context.

Overrides:
setUp in class junit.framework.TestCase
Throws:
java.lang.Exception

tearDown

protected void tearDown()
                 throws java.lang.Exception
Cleans up after a run of the test case by using the test fixture (if one is configured) to tear down the test context.

Overrides:
tearDown in class junit.framework.TestCase
Throws:
java.lang.Exception

runTest

protected void runTest()
                throws java.lang.Throwable
Method invoked to actually run a test method. Delegates to its parents method to run the actual test case method and then does any configured context tests after the case method is done.

Overrides:
runTest in class junit.framework.TestCase
Throws:
java.lang.Throwable

toString

public java.lang.String toString()
Override to return more specific description of what case and context this instance is running.

Overrides:
toString in class junit.framework.TestCase

runContextTests

protected void runContextTests()

assertEquals

public static void assertEquals(java.lang.Object expected,
                                TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is equal to the expected value.


assertEquals

public static void assertEquals(java.lang.String message,
                                java.lang.Object expected,
                                TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is equal to the expected value.


assertSame

public static void assertSame(java.lang.Object expected,
                              TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation refers to the expected object.


assertSame

public static void assertSame(java.lang.String message,
                              java.lang.Object expected,
                              TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation refers to the expected object.


assertNotSame

public static void assertNotSame(java.lang.Object expected,
                                 TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation does not refer to the expected object.


assertNotSame

public static void assertNotSame(java.lang.String message,
                                 java.lang.Object expected,
                                 TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation does not refer to the expected object.


assertNull

public static void assertNull(TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is null.


assertNull

public static void assertNull(java.lang.String message,
                              TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is null.


assertNotNull

public static void assertNotNull(TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is not null.


assertNotNull

public static void assertNotNull(java.lang.String message,
                                 TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is not null.


assertFalse

public static void assertFalse(TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is false.


assertFalse

public static void assertFalse(java.lang.String message,
                               TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is false.


assertTrue

public static void assertTrue(TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is true.


assertTrue

public static void assertTrue(java.lang.String message,
                              TemplateExpressionProcessor.TemplateExpression expression)
Asserts that the value returned by the expression evaluation is true.



Copyright © 2002-2003 Paul Speed. All Rights Reserved.