Java Code Examples for org.junit.Test.expected()

The following are Jave code examples for showing how to use expected() of the org.junit.Test class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: fuck_zookeeper   File: JUnit4ZKTestRunner.java   View Source Code Vote up 5 votes
@Override
public void evaluate() throws Throwable {
    LOG.info("RUNNING TEST METHOD {}", name);
    try {
        super.evaluate();
        Runtime rt = Runtime.getRuntime();
        long usedKB = (rt.totalMemory() - rt.freeMemory()) / 1024;
        LOG.info("Memory used {}", usedKB);
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        while (tg.getParent() != null) {
            tg = tg.getParent();
        }
        LOG.info("Number of threads {}", tg.activeCount());
    } catch (Throwable t) {
        // The test method threw an exception, but it might be an
        // expected exception as defined in the @Test annotation.
        // Check the annotation and log an appropriate message.
        Test annotation = this.method.getAnnotation(Test.class);
        if (annotation != null && annotation.expected() != null &&
                annotation.expected().isAssignableFrom(t.getClass())) {
            LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name,
                annotation.expected());
        } else {
            LOG.info("TEST METHOD FAILED {}", name, t);
        }
        throw t;
    }
    LOG.info("FINISHED TEST METHOD {}", name);
}
 
Example 2
Project: https-github.com-apache-zookeeper   File: JUnit4ZKTestRunner.java   View Source Code Vote up 5 votes
@Override
public void evaluate() throws Throwable {
    LOG.info("RUNNING TEST METHOD {}", name);
    try {
        super.evaluate();
        Runtime rt = Runtime.getRuntime();
        long usedKB = (rt.totalMemory() - rt.freeMemory()) / 1024;
        LOG.info("Memory used {}", usedKB);
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        while (tg.getParent() != null) {
            tg = tg.getParent();
        }
        LOG.info("Number of threads {}", tg.activeCount());
    } catch (Throwable t) {
        // The test method threw an exception, but it might be an
        // expected exception as defined in the @Test annotation.
        // Check the annotation and log an appropriate message.
        Test annotation = this.method.getAnnotation(Test.class);
        if (annotation != null && annotation.expected() != null &&
                annotation.expected().isAssignableFrom(t.getClass())) {
            LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name,
                annotation.expected());
        } else {
            LOG.info("TEST METHOD FAILED {}", name, t);
        }
        throw t;
    }
    LOG.info("FINISHED TEST METHOD {}", name);
}
 
Example 3
Project: ZooKeeper   File: JUnit4ZKTestRunner.java   View Source Code Vote up 5 votes
@Override
public void evaluate() throws Throwable {
    LOG.info("RUNNING TEST METHOD {}", name);
    try {
        super.evaluate();
        Runtime rt = Runtime.getRuntime();
        long usedKB = (rt.totalMemory() - rt.freeMemory()) / 1024;
        LOG.info("Memory used {}", usedKB);
        ThreadGroup tg = Thread.currentThread().getThreadGroup();
        while (tg.getParent() != null) {
            tg = tg.getParent();
        }
        LOG.info("Number of threads {}", tg.activeCount());
    } catch (Throwable t) {
        // The test method threw an exception, but it might be an
        // expected exception as defined in the @Test annotation.
        // Check the annotation and log an appropriate message.
        Test annotation = this.method.getAnnotation(Test.class);
        if (annotation != null && annotation.expected() != null &&
                annotation.expected().isAssignableFrom(t.getClass())) {
            LOG.info("TEST METHOD {} THREW EXPECTED EXCEPTION {}", name,
                annotation.expected());
        } else {
            LOG.info("TEST METHOD FAILED {}", name, t);
        }
        throw t;
    }
    LOG.info("FINISHED TEST METHOD {}", name);
}