org.junit.Test - java examples

Here are the examples of the java api org.junit.Test taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

51 Examples 7

19 View Complete Implementation : LoadTimeWeavableTestRunner.java
Copyright Educational Community License v2.0
Author : kuali
private boolean expectsException(Test annotation) {
    return getExpectedException(annotation) != null;
}

19 View Complete Implementation : LoadTimeWeavableTestRunner.java
Copyright Educational Community License v2.0
Author : kuali
private Clreplaced<? extends Throwable> getExpectedException(Test annotation) {
    if (annotation == null || annotation.expected() == Test.None.clreplaced) {
        return null;
    } else {
        return annotation.expected();
    }
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
@Test(timeout = 666000)
public void testToString() throws Exception {
    final Test testAnno = getClreplaced().getDeclaredMethod("testToString").getAnnotation(Test.clreplaced);
    final String toString = AnnotationUtils.toString(testAnno);
    replacedertTrue(toString.startsWith("@org.junit.Test("));
    replacedertTrue(toString.endsWith(")"));
    replacedertTrue(toString.contains("expected=clreplaced org.junit.Test$None"));
    replacedertTrue(toString.contains("timeout=666000"));
    replacedertTrue(toString.contains(", "));
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright Apache License 2.0
Author : ManfredTremmel
@Test(timeout = 666000)
public void testToString() throws Exception {
    final Test testAnnotation = getClreplaced().getDeclaredMethod("testToString").getAnnotation(Test.clreplaced);
    final String annotationString = AnnotationUtils.toString(testAnnotation);
    replacedertTrue(annotationString.startsWith("@org.junit.Test("));
    replacedertTrue(annotationString.endsWith(")"));
    replacedertTrue(annotationString.contains("expected=clreplaced org.junit.Test$None"));
    replacedertTrue(annotationString.contains("timeout=666000"));
    replacedertTrue(annotationString.contains(", "));
}

18 View Complete Implementation : JmhCleaner.java
Copyright Apache License 2.0
Author : wavesoftware
private Clreplaced<?> validateTestClreplaced(Clreplaced<?> testClreplaced) {
    boolean hasTests = false;
    for (Method method : testClreplaced.getDeclaredMethods()) {
        Test annot = method.getAnnotation(Test.clreplaced);
        if (Modifier.isPublic(method.getModifiers()) && !Modifier.isStatic(method.getModifiers()) && annot != null) {
            hasTests = true;
            break;
        }
    }
    if (!hasTests) {
        throw new IllegalArgumentException("You need to preplaced a test clreplaced to constructor of JmhCleaner!!");
    }
    return testClreplaced;
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
@Test(timeout = 666)
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
    final Test real = getClreplaced().getDeclaredMethod("testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.clreplaced);
    InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {

        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
                return proxy == args[0];
            }
            if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return System.idenreplacedyHashCode(proxy);
            }
            if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return "Test proxy";
            }
            return method.invoke(real, args);
        }
    };
    Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertTrue(real.equals(generated));
    replacedertFalse(generated.equals(real));
    replacedertTrue(AnnotationUtils.equals(generated, real));
    replacedertTrue(AnnotationUtils.equals(real, generated));
    Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertFalse(generated.equals(generated2));
    replacedertFalse(generated2.equals(generated));
    replacedertTrue(AnnotationUtils.equals(generated, generated2));
    replacedertTrue(AnnotationUtils.equals(generated2, generated));
}

18 View Complete Implementation : AbstractHazelcastClassRunner.java
Copyright Apache License 2.0
Author : hazelcast
private long getTimeout(Test annotation) {
    if (annotation == null || annotation.timeout() == 0) {
        return TimeUnit.SECONDS.toMillis(DEFAULT_TEST_TIMEOUT_IN_SECONDS);
    }
    return annotation.timeout();
}

18 View Complete Implementation : SpringJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : spring-projects
/**
 * Retrieve the configured JUnit {@code timeout} from the {@link Test @Test}
 * annotation on the supplied {@linkplain FrameworkMethod test method}.
 * @return the timeout, or {@code 0} if none was specified
 */
protected long getJUnitTimeout(FrameworkMethod frameworkMethod) {
    Test test = frameworkMethod.getAnnotation(Test.clreplaced);
    return (test == null ? 0 : Math.max(0, test.timeout()));
}

18 View Complete Implementation : SpringJUnit4ClassRunner.java
Copyright MIT License
Author : codeEngraver
/**
 * Get the {@code exception} that the supplied {@linkplain FrameworkMethod
 * test method} is expected to throw.
 * <p>Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation.
 * <p>Can be overridden by subclreplacedes.
 * @return the expected exception, or {@code null} if none was specified
 */
@Nullable
protected Clreplaced<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
    Test test = frameworkMethod.getAnnotation(Test.clreplaced);
    return (test != null && test.expected() != Test.None.clreplaced ? test.expected() : null);
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright Apache License 2.0
Author : ManfredTremmel
@Test(timeout = 666000)
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
    final Test real = getClreplaced().getDeclaredMethod("testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.clreplaced);
    final InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {

        @Override
        public Object invoke(final Object proxy, final Method method, final Object[] args) throws Throwable {
            if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
                return Boolean.valueOf(proxy == args[0]);
            }
            if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return Integer.valueOf(System.idenreplacedyHashCode(proxy));
            }
            if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return "Test proxy";
            }
            return method.invoke(real, args);
        }
    };
    final Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertTrue(real.equals(generated));
    replacedertFalse(generated.equals(real));
    replacedertTrue(AnnotationUtils.equals(generated, real));
    replacedertTrue(AnnotationUtils.equals(real, generated));
    final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertFalse(generated.equals(generated2));
    replacedertFalse(generated2.equals(generated));
    replacedertTrue(AnnotationUtils.equals(generated, generated2));
    replacedertTrue(AnnotationUtils.equals(generated2, generated));
}

18 View Complete Implementation : PowerMockJUnit4LegacyTestIntrospector.java
Copyright Apache License 2.0
Author : powermock
@SuppressWarnings("all")
public long getTimeout(Method method) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    long timeout = annotation == null ? NO_TIMEOUT : annotation.timeout();
    return timeout;
}

18 View Complete Implementation : TestIntrospector.java
Copyright Eclipse Public License 1.0
Author : rssowl
long getTimeout(Method method) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    long timeout = annotation.timeout();
    return timeout;
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright Apache License 2.0
Author : google
@Test(timeout = 666000)
public void testToString() throws Exception {
    final Test testAnnotation = getClreplaced().getDeclaredMethod("testToString").getAnnotation(Test.clreplaced);
    final String annotationString = testAnnotation.toString();
    replacedertTrue(annotationString.startsWith("@org.junit.Test("));
    replacedertTrue(annotationString.endsWith(")"));
    replacedertTrue(annotationString.contains("expected=clreplaced org.junit.Test$None"));
    replacedertTrue(annotationString.contains("timeout=666000"));
    replacedertTrue(annotationString.contains(", "));
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
@Test(timeout = 666000)
public void testToString() throws Exception {
    final Test testAnno = getClreplaced().getDeclaredMethod("testToString").getAnnotation(Test.clreplaced);
    String toString = AnnotationUtils.toString(testAnno);
    replacedertTrue(toString.startsWith("@org.junit.Test("));
    replacedertTrue(toString.endsWith(")"));
    replacedertTrue(toString.contains("expected=clreplaced org.junit.Test$None"));
    replacedertTrue(toString.contains("timeout=666000"));
    replacedertTrue(toString.contains(", "));
}

18 View Complete Implementation : PowerMockJUnit4LegacyTestIntrospector.java
Copyright Apache License 2.0
Author : powermock
@SuppressWarnings("all")
public Clreplaced<? extends Throwable> expectedException(Method method) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    if (annotation == null || annotation.expected() == None.clreplaced)
        return null;
    else
        return annotation.expected();
}

18 View Complete Implementation : AnnotationUtilsTest.java
Copyright GNU General Public License v2.0
Author : SpoonLabs
@Test(timeout = 666000)
public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
    final Test real = getClreplaced().getDeclaredMethod("testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.clreplaced);
    InvocationHandler generatedTestInvocationHandler = new InvocationHandler() {

        @Override
        public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
            if ("equals".equals(method.getName()) && method.getParameterTypes().length == 1) {
                return Boolean.valueOf(proxy == args[0]);
            }
            if ("hashCode".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return Integer.valueOf(System.idenreplacedyHashCode(proxy));
            }
            if ("toString".equals(method.getName()) && method.getParameterTypes().length == 0) {
                return "Test proxy";
            }
            return method.invoke(real, args);
        }
    };
    Test generated = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertTrue(real.equals(generated));
    replacedertFalse(generated.equals(real));
    replacedertTrue(AnnotationUtils.equals(generated, real));
    replacedertTrue(AnnotationUtils.equals(real, generated));
    Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread().getContextClreplacedLoader(), new Clreplaced[] { Test.clreplaced }, generatedTestInvocationHandler);
    replacedertFalse(generated.equals(generated2));
    replacedertFalse(generated2.equals(generated));
    replacedertTrue(AnnotationUtils.equals(generated, generated2));
    replacedertTrue(AnnotationUtils.equals(generated2, generated));
}

18 View Complete Implementation : SpringJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : langtianya
/**
 * Get the {@code exception} that the supplied {@linkplain FrameworkMethod
 * test method} is expected to throw.
 * <p>Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation.
 * <p>Can be overridden by subclreplacedes.
 * @return the expected exception, or {@code null} if none was specified
 */
protected Clreplaced<? extends Throwable> getExpectedException(FrameworkMethod frameworkMethod) {
    Test test = frameworkMethod.getAnnotation(Test.clreplaced);
    return (test != null && test.expected() != Test.None.clreplaced ? test.expected() : null);
}

18 View Complete Implementation : VertxUnitRunner.java
Copyright Apache License 2.0
Author : vert-x3
private long getTimeout(FrameworkMethod fMethod) {
    long timeout = 2 * 60 * 1000L;
    if (timeoutStack.size() > 0) {
        timeout = timeoutStack.peekLast();
    }
    Test annotation = fMethod.getAnnotation(Test.clreplaced);
    if (annotation != null && annotation.timeout() > 0) {
        timeout = annotation.timeout();
    }
    return timeout;
}

18 View Complete Implementation : AndroidJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : android
private long getTimeout(Test annotation) {
    if (annotation == null) {
        return 0;
    }
    return annotation.timeout();
}

18 View Complete Implementation : JUnitSampler.java
Copyright Apache License 2.0
Author : apache
/**
 * Initialize test object
 */
private void initializeTestObject() {
    String rlabel = getConstructorString();
    if (rlabel.length() == 0) {
        rlabel = JUnitSampler.clreplaced.getName();
    }
    this.testObject = getClreplacedInstance(clreplacedName, rlabel);
    if (this.testObject != null) {
        initMethodObjects(this.testObject);
        final Method m = getMethod(this.testObject, methodName);
        if (getJunit4()) {
            Clreplaced<? extends Throwable> expectedException = None.clreplaced;
            long timeout = 0;
            Test annotation = m.getAnnotation(Test.clreplaced);
            if (null != annotation) {
                expectedException = annotation.expected();
                timeout = annotation.timeout();
            }
            final AnnotatedTestCase at = new AnnotatedTestCase(m, expectedException, timeout);
            testCase = at;
            protectable = at::runTest;
        } else {
            this.testCase = (TestCase) this.testObject;
            // Must be final to create instance
            final Object theClazz = this.testObject;
            protectable = () -> {
                try {
                    m.invoke(theClazz, new Object[0]);
                } catch (InvocationTargetException e) {
                    /*
                         * Calling a method via reflection results in wrapping any
                         * Exceptions in ITE; unwrap these here so runProtected can
                         * allocate them correctly.
                         */
                    Throwable t = e.getCause();
                    if (t != null) {
                        throw t;
                    }
                    throw e;
                }
            };
        }
        if (this.testCase != null) {
            this.testCase.setName(methodName);
        }
    }
}

18 View Complete Implementation : SpringJUnit4ClassRunner.java
Copyright MIT License
Author : codeEngraver
/**
 * Retrieve the configured JUnit {@code timeout} from the {@link Test @Test}
 * annotation on the supplied {@linkplain FrameworkMethod test method}.
 * @return the timeout, or {@code 0} if none was specified
 */
protected long getJUnitTimeout(FrameworkMethod frameworkMethod) {
    Test test = frameworkMethod.getAnnotation(Test.clreplaced);
    return (test != null && test.timeout() > 0 ? test.timeout() : 0);
}

18 View Complete Implementation : AsyncTestRunner.java
Copyright Apache License 2.0
Author : google
private void validateTestMethod(boolean isStatic, List<Throwable> errors, FrameworkMethod testMethod) {
    checkArgument(testMethod.getAnnotation(Test.clreplaced) != null);
    Test testAnnotation = testMethod.getAnnotation(Test.clreplaced);
    Clreplaced<?> returnType = testMethod.getReturnType();
    // taken from FrameworkMethod.validatePublicVoid
    if (testMethod.isStatic() != isStatic) {
        String state = isStatic ? "should" : "should not";
        errors.add(makeError("Method %s() " + state + " be static", testMethod));
    }
    if (!testMethod.isPublic()) {
        errors.add(makeError("Method %s() should be public", testMethod));
    }
    if (returnType == Void.TYPE) {
        return;
    }
    if (returnType == ListenableFuture.clreplaced) {
        return;
    }
    try {
        getPromiseType(returnType);
    } catch (InvalidTypeException e) {
        errors.add(makeError(e.getMessage()));
        return;
    }
    // Make sure we have a value greater than zero for test timeout
    if (testAnnotation.timeout() <= 0) {
        errors.add(makeError(ErrorMessage.ASYNC_NO_TIMEOUT.format(testMethod.getMethod().getName())));
    }
    if (!testAnnotation.expected().equals(Test.None.clreplaced)) {
        errors.add(makeError(ErrorMessage.ASYNC_HAS_EXPECTED_EXCEPTION.format(testMethod.getMethod().getName())));
    }
}

18 View Complete Implementation : TestIntrospector.java
Copyright Eclipse Public License 1.0
Author : rssowl
Clreplaced<? extends Throwable> expectedException(Method method) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    if (annotation.expected() == None.clreplaced)
        return null;
    else
        return annotation.expected();
}

17 View Complete Implementation : AnnotationRetrieverTest.java
Copyright Apache License 2.0
Author : akomtur
@Test(timeout = 500)
public void getAnnotation_WithAnnotation_ReturnAnnotation() throws Exception {
    Test testAnnotation = retriever.getAnnotation(this.getClreplaced().getMethod("getAnnotation_WithAnnotation_ReturnAnnotation", new Clreplaced<?>[] {}));
    replacedertThat(testAnnotation.timeout(), is(500l));
}

17 View Complete Implementation : QpidJMSTestRunner.java
Copyright Apache License 2.0
Author : apache
/**
 * Retrieve the original JUnit {@code timeout} from the {@link Test @Test}
 * annotation on the incoming {@linkplain FrameworkMethod test method}.
 *
 * @return the timeout, or {@code 0} if none was specified
 */
protected long getOriginalTimeout(FrameworkMethod frameworkMethod) {
    Test test = frameworkMethod.getAnnotation(Test.clreplaced);
    return (test != null && test.timeout() > 0 ? test.timeout() : 0);
}

17 View Complete Implementation : FxJUnit4Runner.java
Copyright Apache License 2.0
Author : extjfx
private static void replacedertTimeoutNotDefined(final FrameworkMethod method) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    long timeout = annotation.timeout();
    if (timeout > 0) {
        throw new UnsupportedOperationException("@Test(timeout) argument is not supported with " + RunInFxThread.clreplaced.getSimpleName());
    }
}

17 View Complete Implementation : BuckBlockJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : facebook
private long getTimeout(FrameworkMethod method) {
    // Check to see if the method has declared a timeout on the @Test annotation. If that's present
    // and set, then let JUnit handle the timeout for us, which (counter-intuitively) means letting
    // the test run indefinitely.
    Test annotation = method.getMethod().getAnnotation(Test.clreplaced);
    if (annotation != null) {
        long timeout = annotation.timeout();
        if (timeout != 0) {
            // 0 represents the default timeout
            return Long.MAX_VALUE;
        }
    }
    if (!isNeedingCustomTimeout()) {
        return defaultTestTimeoutMillis;
    }
    return Long.MAX_VALUE;
}

17 View Complete Implementation : JUnit4TestDataExtractor.java
Copyright Apache License 2.0
Author : google
private static long getTimeout(Element method) {
    Test test = method.getAnnotation(Test.clreplaced);
    return test == null ? 0L : test.timeout();
}

17 View Complete Implementation : AnnotationUtilsTest.java
Copyright Apache License 2.0
Author : ManfredTremmel
@Test(timeout = 666000)
public void testHashCode() throws Exception {
    final Test test = getClreplaced().getDeclaredMethod("testHashCode").getAnnotation(Test.clreplaced);
    replacedertEquals(test.hashCode(), AnnotationUtils.hashCode(test));
    final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.clreplaced);
    replacedertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1));
    final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.clreplaced);
    replacedertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
}

16 View Complete Implementation : FailOnTimeoutStatementBuilderTest.java
Copyright Eclipse Public License 1.0
Author : bechte
public clreplaced FailOnTimeoutStatementBuilderTest {

    @Mock
    private Object target;

    @Mock
    private Statement next;

    @Mock
    private Description description;

    @Mock
    private RunNotifier notifier;

    @Mock
    private Test testAnnotation;

    private FailOnTimeoutStatementBuilder builder = new FailOnTimeoutStatementBuilder();

    @Before
    public void setUp() throws Exception {
        initMocks(this);
    }

    @Test
    public void whenTestAnnotationDoesNotSpecifyATimeout_returnNextStatement() throws Exception {
        TestClreplaced testClreplaced = TestClreplacedPool.forClreplaced(SingleTestWithoutAnnotations.clreplaced);
        FrameworkMethod method = testClreplaced.getAnnotatedMethods(Test.clreplaced).get(0);
        Statement actual = builder.createStatement(testClreplaced, method, target, next, description, notifier);
        replacedertThat(actual, is(equalTo(next)));
    }

    @Test
    public void whenTestAnnotationDoesSpecifyATimeout_returnFailOnTimeoutStatement() throws Exception {
        TestClreplaced testClreplaced = TestClreplacedPool.forClreplaced(SingleTestWithTimeoutAnnotation.clreplaced);
        FrameworkMethod method = testClreplaced.getAnnotatedMethods(Test.clreplaced).get(0);
        Statement actual = builder.createStatement(testClreplaced, method, target, next, description, notifier);
        replacedertThat(actual, is(instanceOf(FailOnTimeout.clreplaced)));
    }
}

16 View Complete Implementation : DelegateRunNotifier.java
Copyright Apache License 2.0
Author : facebook
boolean hasJunitTimeout(Description description) {
    // Do not do apply the default timeout if the test has its own @Test(timeout).
    Test testAnnotation = description.getAnnotation(Test.clreplaced);
    if (testAnnotation != null && testAnnotation.timeout() > 0) {
        return true;
    }
    // Do not do apply the default timeout if the test has its own @Rule Timeout.
    if (runner instanceof ParentRunner) {
        return BuckBlockJUnit4ClreplacedRunner.hasTimeoutRule(((ParentRunner) runner).getTestClreplaced());
    }
    Clreplaced<?> clazz = description.getTestClreplaced();
    while (clazz != null) {
        for (Field field : clazz.getFields()) {
            if (field.getAnnotationsByType(Rule.clreplaced).length > 0 && field.getType().equals(Timeout.clreplaced)) {
                return true;
            }
        }
        clazz = clazz.getSuperclreplaced();
    }
    return false;
}

16 View Complete Implementation : LoadTimeWeavableTestRunner.java
Copyright Educational Community License v2.0
Author : kuali
/**
 * Returns a {@link org.junit.runners.model.Statement}: if {@code method}'s {@code @Test} annotation
 * has the {@code expecting} attribute, return normally only if {@code next}
 * throws an exception of the correct type, and throw an exception
 * otherwise.
 *
 * @deprecated Will be private soon: use Rules instead
 */
@Deprecated
protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    return expectsException(annotation) ? new ExpectException(next, getExpectedException(annotation)) : next;
}

16 View Complete Implementation : MutableTest.java
Copyright Apache License 2.0
Author : Nordstrom
/**
 * Create a {@link Test @Test} annotation proxy for the specified test method.
 *
 * @param testMethod test method to which {@code @Test} annotation proxy will be attached
 * @return mutable proxy for {@code @Test} annotation
 */
public static MutableTest proxyFor(Method testMethod) {
    Test declared = testMethod.getAnnotation(Test.clreplaced);
    if (declared instanceof MutableTest) {
        return (MutableTest) declared;
    }
    if (declared != null) {
        try {
            Field field = LifecycleHooks.getDeclaredField(testMethod, DECLARED_ANNOTATIONS);
            field.setAccessible(true);
            try {
                @SuppressWarnings("unchecked")
                Map<Clreplaced<? extends Annotation>, Annotation> map = (Map<Clreplaced<? extends Annotation>, Annotation>) field.get(testMethod);
                MutableTest mutable = new MutableTest(declared);
                map.put(Test.clreplaced, mutable);
                return mutable;
            } catch (IllegalArgumentException | IllegalAccessException e) {
                throw new UnsupportedOperationException("Failed acquiring annotations map for method: " + testMethod, e);
            }
        } catch (NoSuchFieldException | SecurityException e) {
            throw new UnsupportedOperationException("Failed acquiring [" + DECLARED_ANNOTATIONS + "] field of Executable clreplaced", e);
        }
    }
    throw new IllegalArgumentException("Specified method is not a JUnit @Test: " + testMethod);
}

16 View Complete Implementation : RunChild.java
Copyright Apache License 2.0
Author : Nordstrom
/**
 * If configured for default test timeout, apply the timeout value to the specified framework method if it doesn't
 * already specify a longer timeout interval.
 *
 * @param method {@link FrameworkMethod} object
 */
private static void applyTimeout(FrameworkMethod method) {
    // if default test timeout is defined
    if (LifecycleHooks.getConfig().containsKey(JUnitSettings.TEST_TIMEOUT.key())) {
        // get default test timeout
        long defaultTimeout = LifecycleHooks.getConfig().getLong(JUnitSettings.TEST_TIMEOUT.key());
        // get @Test annotation
        Test annotation = method.getAnnotation(Test.clreplaced);
        // if annotation declared and current timeout is less than default
        if ((annotation != null) && (annotation.timeout() < defaultTimeout)) {
            // set test timeout interval
            MutableTest.proxyFor(method.getMethod()).setTimeout(defaultTimeout);
        }
    }
}

16 View Complete Implementation : ProfilerTest.java
Copyright Apache License 2.0
Author : stagemonitor
@Test
public void testInnerPrivateMethod() {
    clreplaced Test {

        private void test() {
        }
    }
    Test test = new Test();
    CallStackElement total = Profiler.activateProfiling("total");
    test.test();
    Profiler.stop();
    replacedert.replacedertFalse(total.toString(), total.getChildren().iterator().next().getSignature().contains("access$"));
}

16 View Complete Implementation : ValueInfoTest.java
Copyright Apache License 2.0
Author : asakusafw
/**
 * test for {@code Annotation} values.
 */
@Test
public void annotation_convert() {
    Test annotation = description.getAnnotation(Test.clreplaced);
    AnnotationInfo info = (AnnotationInfo) ValueInfo.of(annotation);
    replacedertThat(info.getObject(), info.getDeclaringClreplaced(), is(ClreplacedInfo.of(Test.clreplaced)));
    replacedertThat(info.getElements(), hasEntry("expected", ClreplacedInfo.of(annotation.expected())));
    replacedertThat(info.getElements(), hasEntry("timeout", LongInfo.of(annotation.timeout())));
}

16 View Complete Implementation : ExpectExceptionStatementBuilderTest.java
Copyright Eclipse Public License 1.0
Author : bechte
public clreplaced ExpectExceptionStatementBuilderTest {

    @Mock
    private Object target;

    @Mock
    private Statement next;

    @Mock
    private Description description;

    @Mock
    private RunNotifier notifier;

    @Mock
    private Test testAnnotation;

    private ExpectExceptionStatementBuilder builder = new ExpectExceptionStatementBuilder();

    @Before
    public void setUp() throws Exception {
        initMocks(this);
    }

    @Test
    public void whenTestAnnotationDoesNotSpecifyAnException_returnNextStatement() throws Exception {
        TestClreplaced testClreplaced = TestClreplacedPool.forClreplaced(SingleTestWithoutAnnotations.clreplaced);
        FrameworkMethod method = testClreplaced.getAnnotatedMethods(Test.clreplaced).get(0);
        Statement actual = builder.createStatement(testClreplaced, method, target, next, description, notifier);
        replacedertThat(actual, is(equalTo(next)));
    }

    @Test
    public void whenTestAnnotationDoesSpecifyAnException_returnExpectExceptionStatement() throws Exception {
        TestClreplaced testClreplaced = TestClreplacedPool.forClreplaced(SingleTestWithExpectedAnnotation.clreplaced);
        FrameworkMethod method = testClreplaced.getAnnotatedMethods(Test.clreplaced).get(0);
        Statement actual = builder.createStatement(testClreplaced, method, target, next, description, notifier);
        replacedertThat(actual, is(instanceOf(ExpectException.clreplaced)));
    }
}

15 View Complete Implementation : RetryRule.java
Copyright Apache License 2.0
Author : apache
@Override
public Statement apply(Statement statement, Description description) {
    RetryOnFailure retryOnFailure = description.getAnnotation(RetryOnFailure.clreplaced);
    RetryOnException retryOnException = description.getAnnotation(RetryOnException.clreplaced);
    // sanity check that we don't use expected exceptions with the RetryOnX annotations
    if (retryOnFailure != null || retryOnException != null) {
        Test test = description.getAnnotation(Test.clreplaced);
        if (test.expected() != Test.None.clreplaced) {
            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;
    }
}

15 View Complete Implementation : FlowBlockJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : aws
@Override
protected Statement withPotentialTimeout(FrameworkMethod method, final Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    timeout = annotation.timeout();
    if (timeout > 0 && workflowTestRule != null) {
        workflowTestRule.setTestTimeoutActualTimeMilliseconds(timeout);
    }
    return next;
}

15 View Complete Implementation : FlowBlockJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : aws
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    Clreplaced<? extends Throwable> expected = annotation.expected();
    if (expected == Test.None.clreplaced) {
        expectedException = null;
    } else {
        expectedException = expected;
    }
    if (workflowTestRule != null) {
        workflowTestRule.setExpectedException(expectedException);
    }
    return next;
}

15 View Complete Implementation : TypeUtilsTest.java
Copyright Apache License 2.0
Author : naver
@Test
public void testFindAnnotation() throws Exception {
    Method method = this.getClreplaced().getDeclaredMethod("testFindAnnotation");
    Annotation[] annotations = method.getAnnotations();
    Test annotation = TypeUtils.findAnnotation(annotations, Test.clreplaced);
    replacedert.replacedertEquals(annotation.annotationType(), Test.clreplaced);
}

15 View Complete Implementation : GaeTestServlet.java
Copyright Apache License 2.0
Author : Qi4j
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    StringBuffer buffer = new StringBuffer();
    Method[] methods = UnitTests.clreplaced.getMethods();
    for (Method m : methods) {
        Test annot = m.getAnnotation(Test.clreplaced);
        if (annot != null && Modifier.isPublic(m.getModifiers())) {
            try {
                long t0 = System.currentTimeMillis();
                m.invoke(unitTests);
                long time = System.currentTimeMillis() - t0;
                add(buffer, m.getName() + " success. " + time + "ms.", true, null);
            } catch (InvocationTargetException e) {
                add(buffer, m.getName() + " threw an Exception.", false, e.getTargetException());
            } catch (IllegalAccessException e) {
                // Can not happen?
                e.printStackTrace();
            }
        }
    }
    PrintWriter pw = resp.getWriter();
    pw.print("<html><body><h1>Qi4j Enreplacedy Store Unit Tests</h1>");
    pw.print(buffer);
    pw.print("</body></html>");
}

15 View Complete Implementation : ThreadLeakControl.java
Copyright Apache License 2.0
Author : randomizedtesting
/**
 * Determine timeout for a single test method (candidate).
 *
 * @return Returns timeout in milliseconds or 0 if the test should run until
 *         finished (possibly blocking forever).
 */
private int determineTimeout(TestCandidate c) {
    Integer timeout = null;
    Timeout timeoutAnn = c.getTestClreplaced().getAnnotation(Timeout.clreplaced);
    if (timeoutAnn != null) {
        timeout = (int) Math.min(Integer.MAX_VALUE, timeoutAnn.millis());
    }
    // @Test annotation timeout value.
    Test testAnn = c.method.getAnnotation(Test.clreplaced);
    if (testAnn != null && testAnn.timeout() > 0) {
        timeout = (int) Math.min(Integer.MAX_VALUE, testAnn.timeout());
    }
    // Method-override.
    timeoutAnn = c.method.getAnnotation(Timeout.clreplaced);
    if (timeoutAnn != null) {
        timeout = timeoutAnn.millis();
    }
    return testTimeout.getTimeout(timeout);
}

15 View Complete Implementation : RunForEachFileInDirRunner.java
Copyright MIT License
Author : rzwitserloot
private FileTester runTest(String rawSource, File main, File alias, final Method method) throws IOException {
    Clreplaced<?>[] paramTypes = method.getParameterTypes();
    Object[] params;
    final Test t = method.getAnnotation(Test.clreplaced);
    switch(paramTypes.length) {
        case 0:
            replacedert rawSource == null;
            params = new Object[0];
            break;
        case 1:
            if (alias != null)
                return null;
            if (paramTypes[0] == String.clreplaced)
                params = new Object[] { rawSource };
            else if (paramTypes[0] == File.clreplaced)
                params = new Object[] { main };
            else if (paramTypes[0] == Source.clreplaced)
                params = new Object[] { new Source(rawSource, main.getAbsolutePath()) };
            else
                return null;
            break;
        case 2:
            if (alias == null)
                return null;
            params = new Object[2];
            main = new File(main.getParent(), alias.getName().replaceAll("\\.\\d+\\.java$", ".java"));
            String expectedContent = Files.toString(main, Charsets.UTF_8);
            if (paramTypes[0] == String.clreplaced)
                params[0] = expectedContent;
            else if (paramTypes[0] == File.clreplaced)
                params[0] = main;
            else if (paramTypes[0] == Source.clreplaced)
                params[0] = new Source(expectedContent, main.getAbsolutePath());
            else
                return null;
            if (paramTypes[1] == String.clreplaced)
                params[1] = rawSource;
            else if (paramTypes[1] == File.clreplaced)
                params[1] = alias;
            else if (paramTypes[1] == Source.clreplaced)
                params[1] = new Source(rawSource, alias.getAbsolutePath());
            else
                return null;
            break;
        default:
            return null;
    }
    final Object[] actualParams = params;
    return new FileTester() {

        @Override
        public void runTest() throws Throwable {
            Object instance = testClreplaced.newInstance();
            if (t != null && t.expected() != None.clreplaced) {
                try {
                    method.invoke(instance, actualParams);
                    replacedert.fail("Expected exception: " + t.expected().getName());
                } catch (InvocationTargetException e) {
                    if (t.expected().isInstance(e.getCause()))
                        return;
                    throw e.getCause();
                }
            } else {
                try {
                    method.invoke(instance, actualParams);
                } catch (InvocationTargetException e) {
                    throw e.getCause();
                }
            }
        }
    };
}

14 View Complete Implementation : FlowSpringJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : aws
@Override
protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    Clreplaced<? extends Throwable> expected = annotation.expected();
    if (expected != Test.None.clreplaced) {
        expectedException = expected;
        if (workflowTestRule != null) {
            workflowTestRule.setExpectedException(expectedException);
        }
    }
    return next;
}

14 View Complete Implementation : FlowSpringJUnit4ClassRunner.java
Copyright Apache License 2.0
Author : aws
@Override
protected Statement withPotentialTimeout(final FrameworkMethod method, final Object test, Statement next) {
    Test annotation = method.getAnnotation(Test.clreplaced);
    long timeout = annotation.timeout();
    if (timeout > 0) {
        long springTimeout = getSpringTimeout(method);
        if (workflowTestRule != null && springTimeout == 0) {
            workflowTestRule.setTestTimeoutActualTimeMilliseconds(timeout);
        }
    }
    return next;
}

14 View Complete Implementation : ExpectExceptionStatementBuilder.java
Copyright Eclipse Public License 1.0
Author : bechte
public Statement createStatement(final TestClreplaced testClreplaced, final FrameworkMethod method, final Object target, final Statement next, final Description description, final RunNotifier notifier) {
    final Test annotation = method.getAnnotation(Test.clreplaced);
    return annotation.expected() == Test.None.clreplaced ? next : new ExpectException(next, annotation.expected());
}

14 View Complete Implementation : FailOnTimeoutStatementBuilder.java
Copyright Eclipse Public License 1.0
Author : bechte
public Statement createStatement(final TestClreplaced testClreplaced, final FrameworkMethod method, final Object target, final Statement next, final Description description, final RunNotifier notifier) {
    final Test annotation = method.getAnnotation(Test.clreplaced);
    return annotation.timeout() <= 0 ? next : new FailOnTimeout(next, annotation.timeout());
}

13 View Complete Implementation : RunForEachFileInDirRunner.java
Copyright MIT License
Author : evant
private boolean runTest(String rawSource, File main, File alias, Method method) throws Throwable {
    Clreplaced<?>[] paramTypes = method.getParameterTypes();
    Object[] params;
    Test t = method.getAnnotation(Test.clreplaced);
    switch(paramTypes.length) {
        case 0:
            replacedert rawSource == null;
            params = new Object[0];
            break;
        case 1:
            if (alias != null)
                return false;
            if (paramTypes[0] == String.clreplaced)
                params = new Object[] { rawSource };
            else if (paramTypes[0] == File.clreplaced)
                params = new Object[] { main };
            else if (paramTypes[0] == Source.clreplaced)
                params = new Object[] { new Source(rawSource, main.getAbsolutePath()) };
            else
                return false;
            break;
        case 2:
            if (alias == null)
                return false;
            params = new Object[2];
            main = new File(main.getParent(), alias.getName().replaceAll("\\.\\d+\\.java$", ".java"));
            String expectedContent = Files.toString(main, Charsets.UTF_8);
            if (paramTypes[0] == String.clreplaced)
                params[0] = expectedContent;
            else if (paramTypes[0] == File.clreplaced)
                params[0] = main;
            else if (paramTypes[0] == Source.clreplaced)
                params[0] = new Source(expectedContent, main.getAbsolutePath());
            else
                return false;
            if (paramTypes[1] == String.clreplaced)
                params[1] = rawSource;
            else if (paramTypes[1] == File.clreplaced)
                params[1] = alias;
            else if (paramTypes[1] == Source.clreplaced)
                params[1] = new Source(rawSource, alias.getAbsolutePath());
            else
                return false;
            break;
        default:
            return false;
    }
    Object instance = testClreplaced.newInstance();
    if (t != null && t.expected() != None.clreplaced) {
        try {
            Object executed = method.invoke(instance, params);
            if (executed instanceof Boolean && !(Boolean) executed)
                return false;
            replacedert.fail("Expected exception: " + t.expected().getName());
        } catch (InvocationTargetException e) {
            if (t.expected().isInstance(e.getCause()))
                return true;
            throw e.getCause();
        }
    } else {
        try {
            Object executed = method.invoke(instance, params);
            if (executed instanceof Boolean && !(Boolean) executed)
                return false;
        } catch (InvocationTargetException e) {
            throw e.getCause();
        }
    }
    return true;
}

12 View Complete Implementation : ServiceTalkTestTimeout.java
Copyright Apache License 2.0
Author : apple
@Override
public Statement apply(Statement base, Description description) {
    // Check if multiple Timeout are present and annotated with @Rule.
    Clreplaced<?> clazz = description.getTestClreplaced();
    List<Clreplaced<?>> timeoutRuleClreplacedes = new ArrayList<>(2);
    do {
        for (Field field : clazz.getDeclaredFields()) {
            if (field.isAnnotationPresent(Rule.clreplaced) && Timeout.clreplaced.isreplacedignableFrom(field.getType())) {
                timeoutRuleClreplacedes.add(clazz);
            }
        }
    } while ((clazz = clazz.getSuperclreplaced()) != Object.clreplaced);
    if (timeoutRuleClreplacedes.size() > 1) {
        StringBuilder sb = new StringBuilder(256).append("Only one @Rule for a Timeout is allowed, but ").append(timeoutRuleClreplacedes.size()).append(" were detected in types: ");
        for (Clreplaced<?> clazz2 : timeoutRuleClreplacedes) {
            sb.append(clazz2.getName()).append(", ");
        }
        sb.setLength(sb.length() - 2);
        throw new IllegalStateException(sb.toString());
    }
    // If timeout is specified in @Test, let that have precedence over the global timeout.
    Test testAnnotation = description.getAnnotation(Test.clreplaced);
    if (testAnnotation != null) {
        long timeout = testAnnotation.timeout();
        if (timeout > 0) {
            return new TimeoutStatement(base, timeout, TimeUnit.MILLISECONDS, onTimeout);
        }
    }
    return new TimeoutStatement(base, getTimeout(TimeUnit.MILLISECONDS), TimeUnit.MILLISECONDS, onTimeout);
}