Java Assert assertException(Runnable task, Class clazz)

Here you can find the source of assertException(Runnable task, Class clazz)

Description

assert Exception

License

Open Source License

Declaration

public static void assertException(Runnable task, Class<?> clazz) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static void assertException(Runnable task, Class<?> clazz) {
        try {/*from  w ww .j  av a  2 s .c om*/
            task.run();
            throw new AssertionError(String.format("expected exception of type %s", clazz.getSimpleName()));
        } catch (Exception ex) {
            if (!ex.getClass().isAssignableFrom(clazz)) {
                new AssertionError(String.format("expected exception of type %s but found exception of type %s",
                        clazz.getCanonicalName(), ex.getClass().getCanonicalName()));
            }
        }
    }
}

Related

  1. assertDidNotThrow(final Runnable r)
  2. assertDifferentInstance(final Object o1, final Object o2)
  3. assertDotted(String name)
  4. assertEntryCount(final long entryCount)
  5. assertEnvVarPresent(String envVarKey, String errorMessage)
  6. assertFact(boolean truth, String failure)
  7. assertFailed(Object expression, Object message)
  8. assertFails(Class expectedThrowable, String pattern, int... values)
  9. assertFalse(boolean test, String message)