Package org.junit

Examples of org.junit.Test


        .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


      // with @Test
      Statement containerTestRunnerStatement = new ContainerTestRunnerStatement(method, description);
     
      // Handle expected exception. We need to handle this explicitly as it is implemented
      // using a statement that we will discard here (as we don't use base)
      Test t = method.getAnnotation(Test.class);
      if (t != null && t.expected() != None.class) {
        testStatement = new ExpectException(containerTestRunnerStatement, t.expected());
      } else {
        testStatement = containerTestRunnerStatement;
      }
    } else {
      // With LOCAL_TEST, just run the original statement locally.
View Full Code Here

    for (Method method : testClass.getDeclaredMethods()) {
      int modifiers = method.getModifiers();

      if (Modifier.isPublic(modifiers) && !Modifier.isStatic(modifiers)
          && method.getAnnotation(Ignore.class) == null) {
        Test testAnnotation = method.getAnnotation(Test.class);

        if (testAnnotation != null) {
          for (Method setup : setups) {
            setup.invoke(instance, (Object[]) null);
          }

          Class expectedException = testAnnotation.expected();

          // can't for the life of me get eclipse to be able to
          // resolve Test.None directly
          if (expectedException.getName().equals(
              "org.junit.Test$None")) // why the hell doesn't this
          // just return null?
          {
            expectedException = null;
          }

          try {
            method.invoke(instance, (Object[]) null);
          } catch (Exception e) {
            if (expectedException == null) {
              System.out.println(testClass.getName() + "."
                  + method.getName() + ": "
                  + e.getCause().getMessage());
              new BufferedReader(new InputStreamReader(System.in))
                  .readLine();
            } else {
              // is there a cleaner way of saying this?
              if (!e.getCause().getClass().equals(
                  testAnnotation.expected())) {
                System.out.println(testClass.getName() + "."
                    + method.getName() + ": "
                    + "Exception expected: "
                    + testAnnotation.expected().getName()
                    + ", Exception thrown: "
                    + e.getCause().getMessage());
                new BufferedReader(new InputStreamReader(
                    System.in)).readLine();
              }

              expectedException = null;
            }
          }

          if (expectedException != null) {
            System.out.println(testClass.getName() + "."
                + method.getName() + ": "
                + "Expected exception not thrown: "
                + testAnnotation.expected().getName());
            new BufferedReader(new InputStreamReader(System.in))
                .readLine();
          }

          for (Method tearDown : tearDowns) {
View Full Code Here

        }
    }

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

        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 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);
            }
        };

        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));

        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);
        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

        super(klass);
    }

    @Override
    protected Statement withPotentialTimeout(FrameworkMethod method, final Object test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
        timeout = annotation.timeout();
        if (timeout > 0 && workflowTestRule != null) {
            workflowTestRule.setTestTimeoutActualTimeMilliseconds(timeout);
        }
        return next;
    }
View Full Code Here

        return result;
    }

    @Override
    protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
        Class<? extends Throwable> expected = annotation.expected();
        if (expected != Test.None.class) {
            expectedException = expected;
            if (workflowTestRule != null) {
                workflowTestRule.setExpectedException(expectedException);
            }
View Full Code Here

        super(clazz);
    }

    @Override
    protected Statement withPotentialTimeout(final FrameworkMethod method, final Object test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
        long timeout = annotation.timeout();
        if (timeout > 0) {
            long springTimeout = getSpringTimeout(method);
            if (workflowTestRule != null && springTimeout == 0) {
                workflowTestRule.setTestTimeoutActualTimeMilliseconds(timeout);
            }
View Full Code Here

        return result;
    }

    @Override
    protected Statement possiblyExpectingExceptions(FrameworkMethod method, Object test, Statement next) {
        Test annotation = method.getAnnotation(Test.class);
        Class<? extends Throwable> expected = annotation.expected();
        if (expected != Test.None.class) {
            expectedException = expected;
            if (workflowTestRule != null) {
                workflowTestRule.setExpectedException(expectedException);
            }
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.