Java Code Examples for org.junit.Test

The following are top voted examples for showing how to use org.junit.Test. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to product more good examples.

Example 1
Project: lcm   File: TestMethod.java View source code Vote up 10 votes
protected Class<? extends Throwable> getExpectedException() {
    Test annotation = fMethod.getAnnotation(Test.class);
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    } else {
        return annotation.expected();
    }
}
 
Example 2
Project: serenity-core   File: RetryFilteringRunNotifier.java View source code Vote up 8 votes
private boolean isExpected(Failure failure) {
    if ((failure.getDescription().getTestClass() == null) || (failure.getDescription().getMethodName() == null)) {
        return false;
    }
    try {
        Method testMethod =  failure.getDescription().getTestClass().getMethod(failure.getDescription().getMethodName());
        Test testAnnotation = testMethod.getAnnotation(Test.class);
        if (testAnnotation.expected() != null) {
            return (failure.getException().getClass().isAssignableFrom(testAnnotation.expected()));
        }
    } catch (NoSuchMethodException e) {
        return false;
    }
    return false;
}
 
Example 3
Project: RoboBuggy   File: TestMethod.java View source code Vote up 7 votes
protected Class<? extends Throwable> getExpectedException() {
    Test annotation = method.getAnnotation(Test.class);
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    } else {
        return annotation.expected();
    }
}
 
Example 4
Project: arquillian_deprecated   File: JUnitTestRunner.java View source code Vote up 6 votes
@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);
   }
}
 
Example 5
Project: clinic-softacad   File: BaseAnnotationBindingTestCase.java View source code Vote up 6 votes
private void createBindings() {
	try {
		sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
		Resources resourcesAnnotation = origFrameworkMethod.getAnnotation( Resources.class );
		if ( resourcesAnnotation != null ) {
			sources.getMetadataBuilder().with( resourcesAnnotation.cacheMode() );

			for ( Class<?> annotatedClass : resourcesAnnotation.annotatedClasses() ) {
				sources.addAnnotatedClass( annotatedClass );
			}
			if ( !resourcesAnnotation.ormXmlPath().isEmpty() ) {
				sources.addResource( resourcesAnnotation.ormXmlPath() );
			}
		}
		meta = (MetadataImpl) sources.buildMetadata();
	}
	catch ( final Throwable t ) {
		setupError = t;
		Test testAnnotation = origFrameworkMethod.getAnnotation( Test.class );
		Class<?> expected = testAnnotation.expected();
		if ( t.getClass().equals( expected ) ) {
			expectedException = true;
		}
	}
}
 
Example 6
Project: seasar2   File: AnnotationTestIntrospector.java View source code Vote up 6 votes
public Class<? extends Throwable> expectedException(final Method method) {
    final Test annotation = method.getAnnotation(Test.class);
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    }
    return annotation.expected();
}
 
Example 7
Project: sosies-generator   File: BlockJUnit4ClassRunner.java View source code Vote up 6 votes
private Class<? extends Throwable> getExpectedException(Test annotation) {
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    } else {
        return annotation.expected();
    }
}
 
Example 8
Project: CallBuilder   File: TestMethod.java View source code Vote up 6 votes
protected Class<? extends Throwable> getExpectedException() {
    Test annotation = method.getAnnotation(Test.class);
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    } else {
        return annotation.expected();
    }
}
 
Example 9
Project: powermock   File: PowerMockJUnit4LegacyTestIntrospector.java View source code Vote up 6 votes
@SuppressWarnings("all")
public Class<? extends Throwable> expectedException(Method method) {
	Test annotation = method.getAnnotation(Test.class);
	if (annotation == null || annotation.expected() == None.class)
		return null;
	else
		return annotation.expected();
}
 
Example 10
Project: hibernate-core-ogm   File: BaseAnnotationBindingTestCase.java View source code Vote up 6 votes
private void createBindings() {
	try {
		sources = new MetadataSources( new ServiceRegistryBuilder().buildServiceRegistry() );
		Resources resourcesAnnotation = origFrameworkMethod.getAnnotation( Resources.class );
		if ( resourcesAnnotation != null ) {
			sources.getMetadataBuilder().with( resourcesAnnotation.cacheMode() );

			for ( Class<?> annotatedClass : resourcesAnnotation.annotatedClasses() ) {
				sources.addAnnotatedClass( annotatedClass );
			}
			if ( !resourcesAnnotation.ormXmlPath().isEmpty() ) {
				sources.addResource( resourcesAnnotation.ormXmlPath() );
			}
		}
		meta = (MetadataImpl) sources.buildMetadata();
	}
	catch ( final Throwable t ) {
		setupError = t;
		Test testAnnotation = origFrameworkMethod.getAnnotation( Test.class );
		Class<?> expected = testAnnotation.expected();
		if ( t.getClass().equals( expected ) ) {
			expectedException = true;
		}
	}
}
 
Example 11
Project: arquillian-core   File: JUnitTestRunner.java View source code Vote up 6 votes
@Override
public void testFailure(Failure failure) throws Exception {
    exception = State.getTestException();
    Test test = failure.getDescription().getAnnotation(Test.class);
    if ( !(test != null && test.expected() != Test.None.class))
    {
        // Not Expected Exception, and non thrown internally
        if(exception == null) {
            exception = failure.getException();
        }
    }
}
 
Example 12
Project: spring-framework-2.5.x   File: SpringTestMethod.java View source code Vote up 6 votes
/**
 * Get the <code>exception</code> that this test method is expected to throw.
 * <p>Supports both Spring's [email protected] ExpectedException @ExpectedException(...)}
 * and JUnit's [email protected] Test#expected() @Test(expected=...)} annotations, but
 * 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. " +
				"Only one declaration of an 'expected exception' is permitted per test method.";
		logger.error(msg);
		throw new IllegalStateException(msg);
	}
	else if (springExpectedException != null) {
		expectedException = springExpectedException;
	}
	else if (junitExpectedException != null) {
		expectedException = junitExpectedException;
	}

	return expectedException;
}
 
Example 13
Project: org.openntf.domino   File: TestMethod.java View source code Vote up 6 votes
protected Class<? extends Throwable> getExpectedException() {
    Test annotation = fMethod.getAnnotation(Test.class);
    if (annotation == null || annotation.expected() == None.class) {
        return null;
    } else {
        return annotation.expected();
    }
}
 
Example 14
Project: windowtester   File: TestIntrospector.java View source code Vote up 6 votes
Class<? extends Throwable> expectedException(Method method) {
	Test annotation= method.getAnnotation(Test.class);
	if (annotation.expected() == None.class)
		return null;
	else
		return annotation.expected();
}
 
Example 15
Project: flink   File: RetryRule.java View source code Vote up 6 votes
@Override
public Statement apply(Statement statement, Description description) {
	RetryOnFailure retryOnFailure = description.getAnnotation(RetryOnFailure.class);
	RetryOnException retryOnException = description.getAnnotation(RetryOnException.class);

	// sanity check that we don't use expected exceptions with the RetryOnX annotations
	if (retryOnFailure != null || retryOnException != null) {
		Test test = description.getAnnotation(Test.class);
		if (test.expected() != Test.None.class) {
			throw new IllegalArgumentException("You cannot combine the RetryOnFailure " +
					"annotation with the Test(expected) annotation.");
		}
	}

	// sanity check that we don't use both annotations
	if (retryOnFailure != null && retryOnException != null) {
		throw new IllegalArgumentException(
				"You cannot combine the RetryOnFailure and RetryOnException annotations.");
	}
	
	if (retryOnFailure != null) {
		return new RetryOnFailureStatement(retryOnFailure.times(), statement);
	}
	else if (retryOnException != null) {
		return new RetryOnExceptionStatement(retryOnException.times(), retryOnException.exception(), statement);
	}
	else {
		return statement;
	}
}
 
Example 16
Project: lcm   File: TestMethod.java View source code Vote up 6 votes
public long getTimeout() {
    Test annotation = fMethod.getAnnotation(Test.class);
    if (annotation == null) {
        return 0;
    }
    long timeout = annotation.timeout();
    return timeout;
}
 
Example 17
Project: RoboBuggy   File: TestMethod.java View source code Vote up 6 votes
public long getTimeout() {
    Test annotation = method.getAnnotation(Test.class);
    if (annotation == null) {
        return 0;
    }
    long timeout = annotation.timeout();
    return timeout;
}
 
Example 18
Project: seasar2   File: AnnotationTestIntrospector.java View source code Vote up 6 votes
public long getTimeout(final Method method) {
    final Test annotation = method.getAnnotation(Test.class);
    if (annotation != null) {
        return annotation.timeout();
    }
    return 0;
}
 
Example 19
Project: Rio   File: RioTestRunner.java View source code Vote up 6 votes
@Override
  protected Statement withPotentialTimeout(FrameworkMethod method,
                                           Object target,
                                           Statement next) {
      Test testAnnotation = method.getAnnotation(Test.class);
      long junitTimeout = 0;
      if(testAnnotation != null && testAnnotation.timeout() > 0)
          junitTimeout = testAnnotation.timeout();

      long testTimeout = testManager.getTestConfig().getTimeout();
      if (junitTimeout > 0) {
          if(testTimeout > 0) {
              logger.info("Test method [{}] has a default test configuration timeout value of {} "+
                          "and JUnit's @Test(timeout={}) annotation. The JUnit declaration takes precedence " +
                          "over the configured default timeout.", method.getMethod(), testTimeout, junitTimeout);
          }
	return super.withPotentialTimeout(method, target, next);
}
      if(testTimeout>0)
          return new FailOnTimeout(next, testTimeout);

      return super.withPotentialTimeout(method, target, next);
  }
 
Example 20
Project: CallBuilder   File: TestMethod.java View source code Vote up 6 votes
public long getTimeout() {
    Test annotation = method.getAnnotation(Test.class);
    if (annotation == null) {
        return 0;
    }
    long timeout = annotation.timeout();
    return timeout;
}
 
Example 21
Project: org.openntf.domino   File: TestMethod.java View source code Vote up 6 votes
public long getTimeout() {
    Test annotation = fMethod.getAnnotation(Test.class);
    if (annotation == null) {
        return 0;
    }
    long timeout = annotation.timeout();
    return timeout;
}