Package org.junit

Examples of org.junit.Test


        }
        return sb.toString();
    }

    private boolean isThrowingExpectedException(Method testMethod, Class<?> throwable) {
        Test JUNITtestAnnotation = testMethod.getAnnotation(Test.class);

        if (JUNITtestAnnotation != null) {
            return JUNITtestAnnotation.expected() == throwable;
        } else {
            throw new IllegalStateException("Test method is not annotated with @Test annotation");
        }

    }
View Full Code Here


    public boolean isIgnored() {
        return method.getAnnotation(Ignore.class) != null;
    }

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

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

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

     * throws an exception of the correct type, and throw an exception
     * otherwise.
     */
    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

    if (timeoutAnn != null) {
      timeout = (int) Math.min(Integer.MAX_VALUE, 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

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

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

    final HTMLFixture htmlFixture = testClass.getAnnotation(HTMLFixture.class);

    final Scripts addedScripts = testClass.getAnnotation(Scripts.class);
    final ScriptsBefore addedScriptsBefore = testClass.getAnnotation(ScriptsBefore.class);
    final ScriptsAfter addedScriptsAfter = testClass.getAnnotation(ScriptsAfter.class);
    final Test test = meth.getMethod().getAnnotation(Test.class);

    StringBuilder resp = new StringBuilder(8192);
    resp.append("<html>\n");
    resp.append("<head>\n");
    appendScriptTag(resp, "/stjs.js");
    appendScriptTag(resp, "/junit.js");

    resp.append("<script language='javascript'>stjs.mainCallDisabled=true;</script>\n");

    // scripts added explicitly
    if (addedScripts != null) {
      for (String script : addedScripts.value()) {
        appendScriptTag(resp, script);
      }
    }
    // scripts before - new style
    if (addedScriptsBefore != null) {
      for (String script : addedScriptsBefore.value()) {
        appendScriptTag(resp, script);
      }
    }

    Set<URI> jsFiles = new LinkedHashSet<URI>();
    for (ClassWithJavascript dep : new DependencyCollection(stjsClass).orderAllDependencies(getConfig().getClassLoader())) {

      if (addedScripts != null && dep instanceof BridgeClass) {
        // bridge dependencies are not added when using @Scripts
        System.out
            .println("WARNING: You're using @Scripts deprecated annotation that disables the automatic inclusion of the Javascript files of the bridges you're using! "
                + "Please consider using @ScriptsBefore and/or @ScriptsAfter instead.");
        continue;
      }
      for (URI file : dep.getJavascriptFiles()) {
        jsFiles.add(file);
      }
    }

    for (URI file : jsFiles) {
      appendScriptTag(resp, file.toString());
    }

    // scripts after - new style
    if (addedScriptsAfter != null) {
      for (String script : addedScriptsAfter.value()) {
        appendScriptTag(resp, script);
      }
    }
    resp.append("<script language='javascript'>\n");
    resp.append("  window.onload=function(){\n");
    // resp.append("    console.error(document.getElementsByTagName('html')[0].innerHTML);\n");

    // Adapter between generated assert (not global) and JS-test-driver assert (which is a
    // set of global methods)
    resp.append("    Assert=window;\n");

    String testedClassName = testClass.getSimpleName();
    resp.append("    parent.startingTest('" + testedClassName + "', '" + method.getName() + "');");
    resp.append("    var stjsTest = new " + testedClassName + "();\n");
    resp.append("    var stjsResult = 'OK';\n");
    resp.append("    var expectedException = " + (test.expected() != Test.None.class ? getTypeName(test.expected()) : null) + ";\n");
    resp.append("    try{\n");
    // call before methods
    for (FrameworkMethod beforeMethod : beforeMethods) {
      resp.append("      stjsTest." + beforeMethod.getName() + "();\n");
    }
View Full Code Here

    if (timeoutAnn != null) {
      timeout = (int) Math.min(Integer.MAX_VALUE, 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

  }

  private static boolean containsTests(Class<?> testClass) {
    boolean containsTests = false;
    for (Method m: testClass.getMethods()) {
      Test test = m.getAnnotation(Test.class);
      if (test != null) {
        containsTests = true;
        break;
      }
      if (m.getName().startsWith("test")
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.