Package org.junit

Examples of org.junit.Test


   * 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

  /**
   * 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

        .isPublic()
        .isNotStatic()
        .hasArgsCount(0);

      // No @Test(timeout=...) and @Timeout at the same time.
      Test testAnn = classModel.getAnnotation(method, Test.class, true);
      if (testAnn != null && testAnn.timeout() > 0 && classModel.isAnnotationPresent(method, Timeout.class, true)) {
        throw new IllegalArgumentException("Conflicting @Test(timeout=...) and @Timeout " +
            "annotations in: " + suiteClass.getName() + "#" + method.getName());
      }

      // @Seed annotation on test methods must have at most 1 seed value.
View Full Code Here

  /**
   * Wrap the given statement into another catching the expected exception, if declared.
   */
  private Statement wrapExpectedExceptions(final Statement s, TestCandidate c, Object instance) {
    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

    if (timeoutAnn != null) {
      timeout = 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

        .isPublic()
        .isNotStatic()
        .hasArgsCount(0);

      // No @Test(timeout=...) and @Timeout at the same time.
      Test testAnn = method.getAnnotation(Test.class);
      if (testAnn != null && testAnn.timeout() > 0 && method.isAnnotationPresent(Timeout.class)) {
        throw new IllegalArgumentException("Conflicting @Test(timeout=...) and @Timeout " +
            "annotations in: " + suiteClass.getName() + "#" + method.getName());
      }

      // @Seed annotation on test methods must have at most 1 seed value.
View Full Code Here

      }

      @Override
      public void testFinished(Description description) throws Exception
      {
         Test test = description.getAnnotation(Test.class);
         if (test != null && test.expected() != Test.None.class)
         {
            exception = Arquillian.caughtTestException.get();
            Arquillian.caughtTestException.set(null);
         }
      }
View Full Code Here

        .isPublic()
        .isNotStatic()
        .hasArgsCount(0);

      // No @Test(timeout=...) and @Timeout at the same time.
      Test testAnn = method.getAnnotation(Test.class);
      if (testAnn != null && testAnn.timeout() > 0 && method.isAnnotationPresent(Timeout.class)) {
        throw new IllegalArgumentException("Conflicting @Test(timeout=...) and @Timeout " +
            "annotations in: " + suiteClass.getName() + "#" + method.getName());
      }

      // @Seed annotation on test methods must have at most 1 seed value.
View Full Code Here

  /**
   * Wrap the given statement into another catching the expected exception, if declared.
   */
  private Statement wrapExpectedExceptions(final Statement s, TestCandidate c, Object instance) {
    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.