Generated by
JDiff

org.springframework.test Documentation Differences

This file contains all the changes in documentation in the package org.springframework.test as colored differences. Deletions are shown like this, and additions are shown like this.
If no deletions or additions are shown in an entry, the HTML tags will be what has changed. The new HTML tags are shown in the differences. If no documentation existed, and then some was added in a later version, this change is noted in the appropriate class pages of differences, but the change is not shown on this page. Only changes in existing text are shown here. Similarly, documentation which was inherited from another class or interface is not shown here.
Note that an HTML error in the new documentation may cause the display of other documentation changes to be presented incorrectly. For instance, failure to close a <code> tag will cause all subsequent paragraphs to be displayed differently.

Class AssertThrows

Simple method object encapsulation of the 'test-for-Exception' scenario (for JUnit).

Used like so:

 // the class under test
 public class Foo {
    public void someBusinessLogic(String name) {
        if (name == null) {
            throw new IllegalArgumentException("The 'name' argument is required");
        }
        // rest of business logic here...
    }
 }
The test for the above bad argument path can be expressed using the AssertThrows class like so:
 public class FooTest {
    public void testSomeBusinessLogicBadArgumentPath() {
        new AssertThrows(IllegalArgumentException.class) {
            public void test() {
                new Foo().someBusinessLogic(null);
            }
        }.runTest();
    }
 }
This will result in the test passing if the Foo.someBusinessLogic(..) method threw an java.lang.IllegalArgumentException; if it did not, the test would fail with the following message:
 "Must have thrown a [class java.lang.IllegalArgumentException]"
If the wrong type of java.lang.Exception was thrown, the test will also fail, this time with a message similar to the following:
 "junit.framework.AssertionFailedError: Was expecting a [class java.lang.UnsupportedOperationException] to be thrown, but instead a [class java.lang.IllegalArgumentException] was thrown"
The test for the correct java.lang.Exception respects polymorphism, so you can test that any old java.lang.Exception is thrown like so:
 public class FooTest {
    public void testSomeBusinessLogicBadArgumentPath() {
        // any Exception will do...
        new AssertThrows(Exception.class) {
            public void test() {
                new Foo().someBusinessLogic(null);
            }
        }.runTest();
    }
 }
Intended for use with JUnit 4 and TestNG (as of Spring 3.0). You might want to compare this class with the {@code junit.extensions.ExceptionTestCase} class. @author Rick Evans @author Juergen Hoeller @since 2.0 @deprecated favor use of JUnit 4's {@code @Test(expected=...)} support