org.jtiger.framework
Annotation Type ExpectException


@Documented
@Target(value=METHOD)
@Retention(value=RUNTIME)
@Inherited
public @interface ExpectException

Used to annotate a test case method that is expecting an exception to occur. If the exception or one of its subclasses (if annotated with subclass = true) occurs during execution of the test case, the test case has a success result. If the exception doesn't occur or some other exception occurs, the test case has a fail result. If the exception is a compile-time checked exception, it will need to be declared to be thrown on the test case method as per the language rules for the Java programming language. There is no such requirement for unchecked exceptions.
Example:

    @Fixture("Demonstration")
    class MyTestFixture
    {
        @Test
        @ExpectException(NullPointerException.class)
        public void myTestCase1()
        {

        }

        @Test
        @ExpectException(NullPointerException.class)
        public void myTestCase2()
        {
            throw new NullPointerException();
        }

        @Test
        @ExpectException(NullPointerException.class)
        public void myTestCase3()
        {
            throw new IllegalArgumentException();
        }

        @Test
        @ExpectException(value=RuntimeException.class, subclass=true)
        public void myTestCase4()
        {
            throw new NullPointerException();
        }

        @Test
        @ExpectException(value=java.io.IOException.class, subclass=true)
        public void myTestCase5() throws java.io.FileNotFoundException
        {
            throw new java.io.FileNotFoundException();
        }
    }
In the example given above:
  • The test case method myTestCase1 will give a fail result because it declares to expect a java.lang.NullPointerException, however it is never thrown.

  • The test case method myTestCase2 will give a success result because it declares to expect a java.lang.NullPointerException and it is thrown in the body of the method.

  • The test case method myTestCase3 will give a fail result because it declares to expect a java.lang.NullPointerException, however it is never thrown and some other type of exception is thrown.

  • The test case method myTestCase4 will give a success result because it declares to expect a java.lang.RuntimeException or any of its subclasses, and one of its subclasses, java.lang.NullPointerException, is thrown in the body of the method.

  • The test case method myTestCase5 will give a success result because it declares to expect a java.io.IOException or any of its subclasses, and one of its subclasses, java.io.FileNotFoundException, is thrown in the body of the method. This method is compile-time checked and so must be declared on the body of the method as per the language rules for the Java programming language.
  • Version:
    2.1
    Build Number 0376
    Build Time 2006-07-28 01:50.16.218 CET (GMT + 1)
    Author:
    Tony Morris
    See Also:
    Test

    Required Element Summary
     Class<? extends Throwable> value
              Returns the java.lang.Class that the test case is expecting will be thrown.
     
    Optional Element Summary
     boolean subclass
              Returns true if the test case should succeed if a subclass of the exception is thrown, false otherwise.
     

    Element Detail

    value

    public abstract Class<? extends Throwable> value
    Returns the java.lang.Class that the test case is expecting will be thrown.

    Returns:
    The java.lang.Class that the test case is expecting will be thrown.

    subclass

    public abstract boolean subclass
    Returns true if the test case should succeed if a subclass of the exception is thrown, false otherwise.

    Returns:
    true if the test case should succeed if a subclass of the exception is thrown, false otherwise.
    Default:
    false