Java 类org.junit.internal.runners.model.MultipleFailureException 实例源码

项目:cJUnit-mc626    文件:ResultCollector.java   
protected void foundConcurrencyBug() {
    if (fromNotDeadlockedProperty(error)) {
        exception = new DeadlockError(
                error.getProperty().getErrorMessage());
    } else if (exception instanceof MultipleFailureException) {
        MultipleFailureException mfe
                = (MultipleFailureException) exception;
        List<Throwable> failures = mfe.getFailures();
        for (int i = 0; i < failures.size(); i++) {
            Throwable t = failures.remove(0);
            failures.add(new ConcurrentError(t));
        }
    } else {
        exception = new ConcurrentError(exception);
    }
    terminateSearch();
}
项目:cJUnit-mc626    文件:ExceptionFactory.java   
public MultipleFailureException createMultipleFailureException(
        MultipleFailureExceptionInfo exceptionInfo)
        throws IllegalArgumentException, ClassNotFoundException,
            InstantiationException, IllegalAccessException,
            InvocationTargetException,
            NoSuchMethodException {
    List<Throwable> exceptions = new ArrayList<Throwable>();

    ExceptionInfo[] failures = exceptionInfo.getFailures();

    for (int i = 0; i < failures.length; i++) {
        exceptions.add(createException(failures[i]));
    }

    return new MultipleFailureException(exceptions);
}
项目:cJUnit-mc626    文件:ExceptionComparator.java   
public static boolean equals(Throwable t1, Throwable t2) {
    if (t1 == t2) {
        return true;
    }
    if (t1 == null || t2 == null) {
        return false;
    }

    if (!t1.getClass().equals(t2.getClass())) {
        return false;
    } else if (t1 instanceof MultipleFailureException) {
        return equals(((MultipleFailureException) t1).getFailures(),
                ((MultipleFailureException) t2).getFailures());
    } else {
        return eq(t1.getMessage(), t2.getMessage())
            && Arrays.equals(t1.getStackTrace(),
                    t2.getStackTrace())
            && equals(t1.getCause(), t2.getCause());
    }
}
项目:cJUnit-mc626    文件:MultipleFailureExceptionInfoTest.java   
@Test
public void testMultipleFailureExceptionInfoCtor() {
    Throwable t1 = new TestException();
    Throwable t2 = new OtherTestException();
    List<Throwable> failures = new ArrayList<Throwable>();
    failures.add(t1);
    failures.add(t2);
    MultipleFailureException mfe = new MultipleFailureException(
            failures);

    MultipleFailureExceptionInfo mfei
            = new MultipleFailureExceptionInfo(mfe);

    assertThat(mfei.failures.length, equalTo(2));
    assertThat(mfei.failures[0].getClassName(),
            equalTo(TestException.class.getName()));
    assertThat(mfei.failures[1].getClassName(),
            equalTo(OtherTestException.class.getName()));
}
项目:multiverse-test    文件:UnfinalizingTestRunnerTest.java   
@Test
public void testAnnotation() throws Exception {
    JUnitCore core = new JUnitCore();
    Result result = core.run(Request.method(TestClass.class, "testThis"));

    if (!result.wasSuccessful()) {
        if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
            Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
        } else {
            Assert.fail(result.getFailures().toString());
        }
    }

    Assert.assertTrue(result.getFailures().toString(), result.wasSuccessful());

    ClassLoader loader = UnfinalizingTestRunner.getLastCreatedClassLoader();

    // now check to see that the classes are not final
    Class<?> finalClass = loader.loadClass(FinalClass.class.getName());
    Assert.assertFalse("Class should have been non-final", Modifier.isFinal(finalClass.getModifiers()));
    Class<?> finalClass2 = loader.loadClass(FinalClass2.class.getName());
    Assert.assertFalse("Class 2 should have been non-final", Modifier.isFinal(finalClass2.getModifiers()));
}
项目:multiverse-test    文件:UnfinalizingTestRunnerTest.java   
@Test
public void testMockFinal() {
    IMocksControl control = EasyMock.createStrictControl();
    try {
        control.createMock(TestClass.FinalClass.class);
        Assert.fail("FinalClass wasn't actually final or EasyMock has changed to support this case");
    } catch(IllegalArgumentException e) {

    }

    JUnitCore core = new JUnitCore();
    Result result = core.run(Request.method(TestClass.class, "testMockingFinal"));

    if (!result.wasSuccessful()) {
        if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
            Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
        } else {
            Assert.fail(result.getFailures().toString());
        }
    }

}
项目:multiverse-test    文件:UnfinalizingTestRunnerTest.java   
@Test
public void testMockParentFinalMethod() {
    IMocksControl control = EasyMock.createStrictControl();
    try {
        control.createMock(TestClass.FinalChild.class);
        Assert.fail("FinalClass wasn't actually final or EasyMock has changed to support this case");
    } catch(IllegalArgumentException e) {

    }

    JUnitCore core = new JUnitCore();
    Result result = core.run(Request.method(TestClass.class, "testMockingParentFinal"));

    if (!result.wasSuccessful()) {
        if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
            Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
        } else {
            Assert.fail(result.getFailures().toString());
        }
    }
}
项目:multiverse-test    文件:UnfinalizingTestRunnerTest.java   
@Test
public void testPrivateMethodAccess() throws Exception{
    try {
        TestClass.FinalClass.class.getDeclaredMethod("hiddenMethod").invoke((new TestClass()).new FinalClass());
        Assert.fail("FinalClass.hiddenMethod doesn't seem to be private");
    } catch(IllegalAccessException e) {

    }

    JUnitCore core = new JUnitCore();
    Result result = core.run(Request.method(TestClass.class, "testAllMethodsPublic"));

    if (!result.wasSuccessful()) {
        if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
            Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
        } else {
            Assert.fail(result.getFailures().toString());
        }
    }
}
项目:multiverse-test    文件:UnfinalizingTestRunnerTest.java   
@Test
public void testPrivateClassAccess() throws Exception{
    Parent parent = Parent.getAHiddenImplementationOfParent();
    Assert.assertEquals(parent.getClass().getSimpleName(), "PrivateParentImpl");
    Assert.assertTrue("PrivateParentImpl should be private to start with", Modifier.isPrivate(parent.getClass().getModifiers()));       

    JUnitCore core = new JUnitCore();
    Result result = core.run(Request.method(TestClassForNonVisibleClasses.class, "testProxyingNonVisibleClass"));

    if (!result.wasSuccessful()) {
        if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
            Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
        } else {
            Assert.fail(result.getFailures().toString());
        }
    }
}
项目:cJUnit-mc626    文件:TestWrapper.java   
protected void run() {
    try {
        createTest();
        runTest();
        notifyTestSucceeded();
    } catch (MultipleFailureException mfe) {
        notifyTestFailed(new MultipleFailureExceptionInfo(mfe));
    } catch (Throwable t) {
        notifyTestFailed(new ExceptionInfo(t));
    }
}
项目:cJUnit-mc626    文件:TestWrapper.java   
protected void handleErrors() throws Throwable, Exception {
    if (errors.size() == 1) {
        throw errors.get(0);
    } else if (errors.size() > 1) {
        throw new MultipleFailureException(errors);
    }
}
项目:cJUnit-mc626    文件:MultipleFailureExceptionInfo.java   
public MultipleFailureExceptionInfo(String message,
        StackTraceElementInfo[] stackTrace,
        ExceptionInfo cause, ExceptionInfo[] failures) {
    super(MultipleFailureException.class.getName(), message,
            stackTrace, cause);
    this.failures = failures;
}
项目:cJUnit-mc626    文件:MultipleFailureExceptionInfo.java   
public MultipleFailureExceptionInfo(MultipleFailureException mfe) {
    super(mfe);

    if (mfe.getFailures() == null) {
        failures = new ExceptionInfo[0];
    } else {
        failures = new ExceptionInfo[mfe.getFailures().size()];
        int i = 0;
        for (Throwable t : mfe.getFailures()) {
            failures[i] = new ExceptionInfo(t);
            i++;
        }
    }
}
项目:cJUnit-mc626    文件:ResultCollectorTest.java   
@Test
public void testFoundConcurrencyBugWithMultipleFailures() {
    ResultCollector rc = new ResultCollector(null, null) {
        @Override
        public void terminateSearch() {}
    };
    Throwable t1 = new TestException();
    Throwable t2 = new OtherTestException();
    List<Throwable> initFailures = new ArrayList<Throwable>();
    initFailures.add(t1);
    initFailures.add(t2);
    MultipleFailureException mfe = new MultipleFailureException(
            initFailures);
    rc.exception = mfe;
    rc.error = new Error(0, new PropertyListenerAdapter(), null,
            null);
    rc.foundConcurrencyBug();
    assertThat("MFE unchanged", rc.exception,
            equalTo((Throwable) mfe));
    assertThat("number of failures", mfe.getFailures().size(),
            equalTo(2));
    assertThat("first type", mfe.getFailures().get(0),
            instanceOf(ConcurrentError.class));
    assertThat("first cause", mfe.getFailures().get(0).getCause(),
            equalTo(t1));
    assertThat("second type", mfe.getFailures().get(1),
            instanceOf(ConcurrentError.class));
    assertThat("second cause", mfe.getFailures().get(1).getCause(),
            equalTo(t2));
}
项目:cJUnit-mc626    文件:TestWrapperTest.java   
@Test
public void testRunWhenFailedMultiple() {
    final Counter succeededCounter = new Counter();
    final Counter failedCounter = new Counter();
    TestWrapper tw = new TestWrapper() {
        @Override
        protected void createTest() {}
        @Override
        protected void runTest() throws Throwable {
            throw new MultipleFailureException(null);
        }
        @Override
        protected void notifyTestSucceeded() {
            succeededCounter.increment();
        }
        @Override
        protected void notifyTestFailed(ExceptionInfo ei) {
            failedCounter.increment();
            // if this is not invoked, one of the asserts
            // below will fail anyway
            assertThat("type", ei, instanceOf(
                MultipleFailureExceptionInfo.class));
        }
    };

    tw.run();

    assertThat("succeeded", succeededCounter.getValue(),
            equalTo(0));
    assertThat("failed", failedCounter.getValue(), equalTo(1));
}
项目:cJUnit-mc626    文件:TestWrapperTest.java   
@Test(expected=MultipleFailureException.class)
public void testExceptionOnMultipleError() throws Throwable {
    TestWrapper tw = new TestWrapper();
    tw.errors.add(new TestException());
    tw.errors.add(new OtherTestException());

    tw.handleErrors();
}
项目:cJUnit-mc626    文件:MultipleFailureExceptionInfoTest.java   
@Test
public void testMultipleFailureExceptionInfoCtorWithNullFailures() {
    MultipleFailureException mfe = new MultipleFailureException(
            null);

    MultipleFailureExceptionInfo mfei
            = new MultipleFailureExceptionInfo(mfe);

    assertThat(mfei.failures.length, equalTo(0));
}
项目:cJUnit-mc626    文件:ExceptionComparatorTest.java   
@Test
public void falseWhenMFEsWithDifferentLists() {
    List<Throwable> l = new ArrayList<Throwable>();
    l.add(t);
    MultipleFailureException mfe1
            = new MultipleFailureException(l);
    MultipleFailureException mfe2
            = new MultipleFailureException(null);
    assertThat(ExceptionComparator.equals(mfe1, mfe2), is(false));
}
项目:cJUnit-mc626    文件:ExceptionComparatorTest.java   
@Test
public void trueWhenMFEsWithEqualLists() {
    List<Throwable> l1 = new ArrayList<Throwable>();
    l1.add(t);
    MultipleFailureException mfe1
            = new MultipleFailureException(l1);
    List<Throwable> l2 = new ArrayList<Throwable>();
    Throwable t2 = new TestException(t.getMessage());
    t2.setStackTrace(t.getStackTrace());
    l2.add(t2);
    MultipleFailureException mfe2
            = new MultipleFailureException(l2);
    assertThat(ExceptionComparator.equals(mfe1, mfe2), is(true));

}
项目:ormlite-jdbc    文件:BaseJdbcTest.java   
@Override
public void evaluate() throws Throwable {
    try {
        statement.evaluate();
    } catch (Throwable t) {
        if (t instanceof MultipleFailureException) {
            t = ((MultipleFailureException) t).getFailures().get(0);
        }
        if (t instanceof InvocationTargetException) {
            t = ((InvocationTargetException) t).getTargetException();
        }
        String assertMsg;
        if (t instanceof AssertionError) {
            throw t;
        } else if ((!isConnectionExpected) && t.getMessage() != null
                && t.getMessage().contains(DATASOURCE_ERROR)) {
            // if we throw because of missing data-source and the db server isn't available, ignore it
            return;
        } else if (tClass == null) {
            assertMsg = "Test threw unexpected exception: " + t;
        } else if (tClass == t.getClass()) {
            // we matched our expected exception
            return;
        } else {
            assertMsg = "Expected test to throw " + tClass + " but it threw: " + t;
        }
        Error error = new AssertionError(assertMsg);
        error.initCause(t);
        throw error;
    }
    // can't be in the throw block
    if (tClass != null) {
        throw new AssertionError("Expected test to throw " + tClass);
    }
}
项目:usergrid    文件:NoAWSCredsRule.java   
private boolean isMissingCredsException( final Throwable t ) {

        if ( t instanceof AmazonClientException ) {

            final AmazonClientException ace = ( AmazonClientException ) t;

            if ( ace.getMessage().contains( "could not get aws access key" ) || ace.getMessage().contains(
                "could not get aws secret key from system properties" ) ) {
                //swallow
                return true;
            }
        }

        if( t instanceof AwsPropertiesNotFoundException ){
            return true;
        }

        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
项目:usergrid    文件:NoGoogleCredsRule.java   
private boolean isMissingCredsException( final Throwable t ) {

        // either no filename was provided or the filename provided doesn't actually exist on the file system
        if ( t instanceof FileNotFoundException || t instanceof NullPointerException ) {
                return true;
            }


        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
项目:usergrid    文件:NoAWSCredsRule.java   
private boolean isMissingCredsException( final Throwable t ) {

        if ( t instanceof AmazonClientException ) {

            final AmazonClientException ace = ( AmazonClientException ) t;

            if ( ace.getMessage().contains( "could not get aws access key" ) || ace.getMessage().contains(
                "could not get aws secret key from system properties" ) ) {
                //swallow
                return true;
            }
        }

        /**
         * Handle the multiple failure junit trace
         */
        if( t instanceof MultipleFailureException ){
            for(final Throwable failure : ((MultipleFailureException)t).getFailures()){
                final boolean isMissingCreds = isMissingCredsException( failure );

                if(isMissingCreds){
                    return true;
                }
            }
        }
        final Throwable cause = t.getCause();

        if ( cause == null ) {
            return false;
        }


        return isMissingCredsException( cause );
    }
项目:kurento-java    文件:Retry.java   
private Statement statement(final Statement base, final Description description) {
  return new Statement() {

    @Override
    public void evaluate() throws Throwable {
      Throwable caughtThrowable = null;
      for (; currentRetry <= retryCount; currentRetry++) {
        try {
          testReport.appendHeader(description.getClassName() + "." + description.getMethodName()
              + " - Execution " + (exceptions.size() + 1) + "/" + getRetryCount());
          base.evaluate();
          testReport.flushExtraInfoHtml();
          testReport.appendSuccess("Test ok");
          testReport.flushExtraInfoHtml();
          testReport.appendLine();
          return;
        } catch (Throwable t) {

          if (t instanceof MultipleFailureException) {
            MultipleFailureException m = (MultipleFailureException) t;
            for (Throwable throwable : m.getFailures()) {
              log.warn("Multiple exception element", throwable);
            }
          }

          exceptions.add(t);
          if (testReport != null) {
            testReport.appendWarning("Test failed in retry " + exceptions.size());
            testReport.appendException(t, testScenario);
            testReport.flushExtraInfoHtml();
            testReport.flushExtraErrorHtml();
          }

          caughtThrowable = t;
          log.error(SEPARATOR);
          log.error("{}: run {} failed", description.getDisplayName(), currentRetry, t);
          log.error(SEPARATOR);
        }
      }

      String errorMessage = "TEST ERROR: " + description.getMethodName() + " (giving up after "
          + retryCount + " retries)";
      if (exceptions.size() > 0 && testReport != null) {
        testReport.appendError(errorMessage);
        testReport.appendLine();
      }

      throw caughtThrowable;
    }
  };
}
项目:cJUnit-mc626    文件:ExceptionComparatorTest.java   
@Test
public void falseWhenOneMFE() {
    MultipleFailureException mfe
            = new MultipleFailureException(null);
    assertThat(ExceptionComparator.equals(mfe, t), is(false));
}