Package org.junit

Examples of org.junit.Test


   *
   * @return the expected exception, or <code>null</code> if none was
   * specified
   */
  protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
    Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
    Class<? extends Throwable> junitExpectedException = testAnnotation != null
        && testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null;

    ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
    Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);

    if (springExpectedException != null && junitExpectedException != null) {
View Full Code Here


   * method}.
   *
   * @return the timeout, or <code>0</code> if none was specified.
   */
  protected long getJUnitTimeout(FrameworkMethod frameworkMethod) {
    Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
    return (testAnnotation != null && testAnnotation.timeout() > 0 ? testAnnotation.timeout() : 0);
  }
View Full Code Here

   * and JUnit's {@link Test#expected() @Test(expected=...)} annotations, but
   * not both simultaneously.
   * @return the expected exception, or <code>null</code> if none was specified
   */
  protected Class<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
    Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
    Class<? extends Throwable> junitExpectedException = (testAnnotation != null
        && testAnnotation.expected() != Test.None.class ? testAnnotation.expected() : null);

    ExpectedException expectedExAnn = frameworkMethod.getAnnotation(ExpectedException.class);
    Class<? extends Throwable> springExpectedException = (expectedExAnn != null ? expectedExAnn.value() : null);

    if (springExpectedException != null && junitExpectedException != null) {
View Full Code Here

   * Retrieves the configured JUnit <code>timeout</code> from the {@link Test
   * &#064;Test} annotation on the supplied {@link FrameworkMethod test method}.
   * @return the timeout, or <code>0</code> if none was specified.
   */
  protected long getJUnitTimeout(FrameworkMethod frameworkMethod) {
    Test testAnnotation = frameworkMethod.getAnnotation(Test.class);
    return (testAnnotation != null && testAnnotation.timeout() > 0 ? testAnnotation.timeout() : 0);
  }
View Full Code Here

*/
public abstract class Junit4Utils {

  public static boolean isExpectedException(final Method method,
      final Throwable ex) {
    final Test testAnnotation = method.getAnnotation(Test.class);
    if ((testAnnotation != null) && (testAnnotation.expected() != null)
        && testAnnotation.expected().isInstance(ex)) {
      return true;
    }
    return false;
  }
View Full Code Here

   * not both simultaneously.
   * @return the expected exception, or <code>null</code> if none was specified
   */
  public Class<? extends Throwable> getExpectedException() throws IllegalStateException {
    ExpectedException expectedExAnn = getMethod().getAnnotation(ExpectedException.class);
    Test testAnnotation = getMethod().getAnnotation(Test.class);

    Class<? extends Throwable> expectedException = null;
    Class<? extends Throwable> springExpectedException =
        (expectedExAnn != null && expectedExAnn.value() != null ? expectedExAnn.value() : null);
    Class<? extends Throwable> junitExpectedException =
        (testAnnotation != null && testAnnotation.expected() != None.class ? testAnnotation.expected() : null);

    if (springExpectedException != null && junitExpectedException != null) {
      String msg = "Test method [" + getMethod() + "] has been configured with Spring's @ExpectedException(" +
          springExpectedException.getName() + ".class) and JUnit's @Test(expected=" +
          junitExpectedException.getName() + ".class) annotations. " +
View Full Code Here

   * Get the configured <code>timeout</code> for this test method.
   * <p>Supports JUnit's {@link Test#timeout() @Test(timeout=...)} annotation.
   * @return the timeout, or <code>0</code> if none was specified
   */
  public long getTimeout() {
    Test testAnnotation = getMethod().getAnnotation(Test.class);
    return (testAnnotation != null && testAnnotation.timeout() > 0 ? testAnnotation.timeout() : 0);
  }
View Full Code Here

            initMethodObjects(this.testObject);
            final Method m = getMethod(this.testObject,methodName);
            if (getJunit4()){
                Class<? extends Throwable> expectedException = None.class;
                long timeout = 0;
                Test annotation = m.getAnnotation(Test.class);
                if(null != annotation) {
                    expectedException = annotation.expected();
                    timeout = annotation.timeout();
                }
                final AnnotatedTestCase at = new AnnotatedTestCase(m, expectedException, timeout);
                testCase = at;
                protectable = new Protectable() {
                    @Override
View Full Code Here

    if (timeoutAnn != null) {
      timeout = (int) Math.min(Integer.MAX_VALUE, timeoutAnn.millis());
    }

    // @Test annotation timeout value.
    Test testAnn = c.method.getAnnotation(Test.class);
    if (testAnn != null && testAnn.timeout() > 0) {
      timeout = (int) Math.min(Integer.MAX_VALUE, testAnn.timeout());
    }

    // Method-override.
    timeoutAnn = c.method.getAnnotation(Timeout.class);
    if (timeoutAnn != null) {
View Full Code Here

  /**
   * Wrap the given statement into another catching the expected exception, if declared.
   */
  private Statement wrapExpectedExceptions(final Statement s, TestCandidate c) {
    Test ann = c.method.getAnnotation(Test.class);

    if (ann == null) {
      return s;
    }
   
    // If there's no expected class, don't wrap. Eh, None is package-private...
    final Class<? extends Throwable> expectedClass = ann.expected();
    if (expectedClass.getName().equals("org.junit.Test$None")) {
      return s;
    }

    return new Statement() {
View Full Code Here

TOP

Related Classes of org.junit.Test

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.