Package org.junit

Examples of org.junit.Test.expected()


      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 {
View Full Code Here


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

    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

    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

    return timeout;
  }

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

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

  boolean isUnexpected(Throwable exception) {
    return ! getExpectedException().isAssignableFrom(exception.getClass());
  }
View Full Code Here

    if (ann == null) {
      return s;
    }
   
    // If there's no expected class, don't wrap. Eh, None is package-private...
    final Class<? extends Throwable> expectedClass = ann.expected();
    if (expectedClass.getName().equals("org.junit.Test$None")) {
      return s;
    }

    return new Statement() {
View Full Code Here

      return false;
    }
   
    Object instance = testClass.newInstance();
   
    if (t != null && t.expected() != None.class) {
      try {
        Object executed = method.invoke(instance, params);
        if (executed instanceof Boolean && !(Boolean)executed) return false;
        Assert.fail("Expected exception: " + t.expected().getName());
      } catch (InvocationTargetException e) {
View Full Code Here

   
    if (t != null && t.expected() != None.class) {
      try {
        Object executed = method.invoke(instance, params);
        if (executed instanceof Boolean && !(Boolean)executed) return false;
        Assert.fail("Expected exception: " + t.expected().getName());
      } catch (InvocationTargetException e) {
        if (t.expected().isInstance(e.getCause())) return true;
        throw e.getCause();
      }
    } else {
View Full Code Here

      try {
        Object executed = method.invoke(instance, params);
        if (executed instanceof Boolean && !(Boolean)executed) return false;
        Assert.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);
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. 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.