Package org.junit

Examples of org.junit.Test


            initMethodObjects(this.testObject);
            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() {
                    public void protect() throws Throwable {
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

   * test method} is expected to throw.
   * <p>Supports JUnit's {@link Test#expected() @Test(expected=...)} annotation.
   * @return the expected exception, or {@code null} 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);

    return junitExpectedException;
  }
View Full Code Here

   * Retrieves the configured JUnit {@code timeout} from the {@link Test @Test}
   * annotation on the supplied {@link FrameworkMethod test method}.
   * @return the timeout, or {@code 0} 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

    }
    return results;
  }

  long getTimeout(Method method) {
    Test annotation= method.getAnnotation(Test.class);
    long timeout= annotation.timeout();
    return timeout;
  }
View Full Code Here

    long timeout= annotation.timeout();
    return timeout;
  }

  Class<? extends Throwable> expectedException(Method method) {
    Test annotation= method.getAnnotation(Test.class);
    if (annotation.expected() == None.class)
      return null;
    else
      return annotation.expected();
  }
View Full Code Here

        }
    }

    @Test(timeout = 666000)
    public void testGeneratedAnnotationEquivalentToRealAnnotation() throws Exception {
        final Test real = getClass().getDeclaredMethod(
                "testGeneratedAnnotationEquivalentToRealAnnotation").getAnnotation(Test.class);

        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.identityHashCode(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()
                .getContextClassLoader(), new Class[] { Test.class },
                generatedTestInvocationHandler);
        assertTrue(real.equals(generated));
        assertFalse(generated.equals(real));
        assertTrue(AnnotationUtils.equals(generated, real));
        assertTrue(AnnotationUtils.equals(real, generated));

        final Test generated2 = (Test) Proxy.newProxyInstance(Thread.currentThread()
                .getContextClassLoader(), new Class[] { Test.class },
                generatedTestInvocationHandler);
        assertFalse(generated.equals(generated2));
        assertFalse(generated2.equals(generated));
        assertTrue(AnnotationUtils.equals(generated, generated2));
        assertTrue(AnnotationUtils.equals(generated2, generated));
    }
View Full Code Here

        assertTrue(AnnotationUtils.equals(generated2, generated));
    }

    @Test(timeout = 666000)
    public void testHashCode() throws Exception {
        final Test test = getClass().getDeclaredMethod("testHashCode").getAnnotation(Test.class);
        assertEquals(test.hashCode(), AnnotationUtils.hashCode(test));
        final TestAnnotation testAnnotation1 = field1.getAnnotation(TestAnnotation.class);
        assertEquals(testAnnotation1.hashCode(), AnnotationUtils.hashCode(testAnnotation1));
        final TestAnnotation testAnnotation3 = field3.getAnnotation(TestAnnotation.class);
        assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
    }
View Full Code Here

        assertEquals(testAnnotation3.hashCode(), AnnotationUtils.hashCode(testAnnotation3));
    }

    @Test(timeout = 666000)
    public void testToString() throws Exception {
        final Test testAnno = getClass().getDeclaredMethod("testToString")
                .getAnnotation(Test.class);
        final String toString = AnnotationUtils.toString(testAnno);
        assertTrue(toString.startsWith("@org.junit.Test("));
        assertTrue(toString.endsWith(")"));
        assertTrue(toString.contains("expected=class org.junit.Test$None"));
View Full Code Here

   * @deprecated Will be private soon: use Rules instead
   */
  @Deprecated
  protected Statement possiblyExpectingExceptions(FrameworkMethod method,
      Object test, Statement next) {
    Test annotation= method.getAnnotation(Test.class);
    return expectsException(annotation) ? new ExpectException(next,
        getExpectedException(annotation)) : next;
  }
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.