org.junit.runners.model.MultipleFailureException Java Examples

The following examples show how to use org.junit.runners.model.MultipleFailureException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SpliceWatcher.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
private void closeResultSets() {
    List<Throwable> t = Lists.newArrayListWithExpectedSize(0);
    for (ResultSet r : resultSets) {
        try {
            if (!r.isClosed()) {
                r.close();
            }
        } catch (Exception e) {
            e.printStackTrace();
            t.add(e);
        }
    }
    try {
        MultipleFailureException.assertEmpty(t);
    } catch (Throwable throwable) {
        throw new RuntimeException(throwable);
    }
}
 
Example #2
Source File: ClusterWithManagement.java    From ehcache3 with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
  return cluster.apply(new Statement() {
    @Override
    public void evaluate() throws Throwable {
      before();
      try {
        base.evaluate();
        after();
      } catch (Throwable t) {
        try {
          after();
          throw t;
        } catch (Exception e) {
          throw new MultipleFailureException(asList(t, e));
        }
      }
    }
  }, description);
}
 
Example #3
Source File: ParameterizedTestWatcher.java    From hifive-pitalium with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, final Description description, final Object[] params) {
	return new Statement() {
		public void evaluate() throws Throwable {
			ArrayList<Throwable> errors = new ArrayList<Throwable>();
			ParameterizedTestWatcher.this.startingQuietly(description, errors, params);

			try {
				base.evaluate();
				ParameterizedTestWatcher.this.succeededQuietly(description, errors, params);
			} catch (AssumptionViolatedException var7) {
				errors.add(var7);
				ParameterizedTestWatcher.this.skippedQuietly(var7, description, errors, params);
			} catch (Throwable var8) {
				errors.add(var8);
				ParameterizedTestWatcher.this.failedQuietly(var8, description, errors, params);
			} finally {
				ParameterizedTestWatcher.this.finishedQuietly(description, errors, params);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example #4
Source File: GrpcCleanupRule.java    From grpc-java with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      try {
        base.evaluate();
      } catch (Throwable t) {
        firstException = t;

        try {
          teardown();
        } catch (Throwable t2) {
          throw new MultipleFailureException(Arrays.asList(t, t2));
        }

        throw t;
      }

      teardown();
      if (firstException != null) {
        throw firstException;
      }
    }
  };
}
 
Example #5
Source File: MozillaJSTest.java    From es6draft with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Throwable {
    assumeTrue("Test disabled", test.isEnabled());

    realm.initialize(new NullConsole(), test);
    realm.get().createGlobalProperties(new Print(), Print.class);
    exceptionHandler.setExecutionContext(realm.get().defaultContext());

    // Apply scripted conditions
    scriptConditions();

    // Filter disabled tests (may have changed after applying scripted conditions)
    assumeTrue("Test disabled", test.isEnabled());

    if (test.negative) {
        expected.expect(
                Matchers.either(StandardErrorHandler.defaultMatcher()).or(ScriptExceptionHandler.defaultMatcher())
                        .or(Matchers.instanceOf(MultipleFailureException.class)));
    } else {
        errorHandler.match(StandardErrorHandler.defaultMatcher());
        exceptionHandler.match(ScriptExceptionHandler.defaultMatcher());
    }
}
 
Example #6
Source File: WebKitTest.java    From es6draft with MIT License 6 votes vote down vote up
@Before
public void setUp() throws Throwable {
    assumeTrue("Test disabled", test.isEnabled());

    realm.initialize(new NullConsole(), test);
    realm.get().createGlobalProperties(new Print(), Print.class);
    exceptionHandler.setExecutionContext(realm.get().defaultContext());

    if (test.negative) {
        expected.expect(
                Matchers.either(StandardErrorHandler.defaultMatcher()).or(ScriptExceptionHandler.defaultMatcher())
                        .or(Matchers.instanceOf(MultipleFailureException.class)));
    } else {
        errorHandler.match(StandardErrorHandler.defaultMatcher());
        exceptionHandler.match(ScriptExceptionHandler.defaultMatcher());
    }
}
 
Example #7
Source File: FlakyTestJUnit4RetryRule.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Override
public void evaluate() {

    int attempts = 0;
    final List<Throwable> causes = new ArrayList<>();

    while (++attempts <= maxTries) {
        try {
            base.evaluate();
            return;
        } catch (Throwable throwable) {
            log.warn("Retrying @Flaky-annotated test: {}", description.getDisplayName());
            causes.add(throwable);
        }
    }

    throw new IllegalStateException(
        "@Flaky-annotated test failed despite retries.",
        new MultipleFailureException(causes));
}
 
Example #8
Source File: FailureDetectingExternalResource.java    From testcontainers-java with MIT License 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {

    return new Statement() {
        @Override
        public void evaluate() throws Throwable {

            List<Throwable> errors = new ArrayList<Throwable>();

            try {
                starting(description);
                base.evaluate();
                succeeded(description);
            } catch (Throwable e) {
                errors.add(e);
                failed(e, description);
            } finally {
                finished(description);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #9
Source File: GrpcCleanupRule.java    From grpc-nebula-java with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      try {
        base.evaluate();
      } catch (Throwable t) {
        firstException = t;

        try {
          teardown();
        } catch (Throwable t2) {
          throw new MultipleFailureException(Arrays.asList(t, t2));
        }

        throw t;
      }

      teardown();
      if (firstException != null) {
        throw firstException;
      }
    }
  };
}
 
Example #10
Source File: TraceUnitTestRule.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {

    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            System.out.println("Starting test ... " + description.getMethodName());
            try {
                base.evaluate();
            } catch (Throwable e) {
                errors.add(e);
            } finally {
                System.out.println("... test finished. " + description.getMethodName());
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #11
Source File: TraceUnitTestRule.java    From tutorials with MIT License 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {

    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            System.out.println("Starting test ... " + description.getMethodName());
            try {
                base.evaluate();
            } catch (Throwable e) {
                errors.add(e);
            } finally {
                System.out.println("... test finished. " + description.getMethodName());
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #12
Source File: TableRule.java    From spliceengine with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
public org.junit.runners.model.Statement apply(final org.junit.runners.model.Statement base,
                                               Description description){

    return new org.junit.runners.model.Statement(){
        @Override
        public void evaluate() throws Throwable{
            try{
                setup();
            }catch(SQLException e){
                throw new SetupFailureException(e);
            }
            List<Throwable> errors = new LinkedList<>();
            try{
                base.evaluate();
            }catch(Throwable t){
                errors.add(t);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #13
Source File: FlowableEventRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #14
Source File: FlowableContentRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #15
Source File: FlowableFormRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #16
Source File: FlowableAppRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #17
Source File: FlowableRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #18
Source File: FlowableCmmnRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #19
Source File: ActivitiRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #20
Source File: FlowableIdmRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #21
Source File: FlowableDmnRule.java    From flowable-engine with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #22
Source File: WaitForHttp.java    From apiman-cli with Apache License 2.0 6 votes vote down vote up
@Override
public Statement apply(Statement base, Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            final List<Throwable> errors = Lists.newArrayList();

            starting();

            try {
                base.evaluate();
            } catch (Throwable e) {
                errors.add(e);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #23
Source File: TestBed.java    From smart-testing with Apache License 2.0 6 votes vote down vote up
private Statement statement(final Statement base, final Description description) {

        return new Statement() {
            public void evaluate() throws Throwable {
                before(description);
                try {
                    List<Throwable> errors = new ArrayList<>();

                    try {
                        base.evaluate();
                        succeededQuietly(description, errors);
                    } catch (Throwable e) {
                        errors.add(e);
                        failedQuietly(e, description, errors);
                    }
                    MultipleFailureException.assertEmpty(errors);
                } finally {
                    after();
                }
            }
        };
    }
 
Example #24
Source File: ActivitiDmnRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
    return new Statement() {
        @Override
        public void evaluate() throws Throwable {
            List<Throwable> errors = new ArrayList<Throwable>();

            startingQuietly(description, errors);
            try {
                base.evaluate();
                succeededQuietly(description, errors);
            } catch (AssumptionViolatedException e) {
                errors.add(e);
                skippedQuietly(e, description, errors);
            } catch (Throwable t) {
                errors.add(t);
                failedQuietly(t, description, errors);
            } finally {
                finishedQuietly(description, errors);
            }

            MultipleFailureException.assertEmpty(errors);
        }
    };
}
 
Example #25
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
	return new Statement() {
		@Override
		public void evaluate() throws Throwable {
			List<Throwable> errors = new ArrayList<Throwable>();

			startingQuietly(description, errors);
			try {
				base.evaluate();
				succeededQuietly(description, errors);
			} catch (AssumptionViolatedException e) {
				errors.add(e);
				skippedQuietly(e, description, errors);
			} catch (Throwable t) {
				errors.add(t);
				failedQuietly(t, description, errors);
			} finally {
				finishedQuietly(description, errors);
			}

			MultipleFailureException.assertEmpty(errors);
		}
	};
}
 
Example #26
Source File: ActivitiRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      List<Throwable> errors = new ArrayList<Throwable>();

      startingQuietly(description, errors);
      try {
        base.evaluate();
        succeededQuietly(description, errors);
      } catch (AssumptionViolatedException e) {
        errors.add(e);
        skippedQuietly(e, description, errors);
      } catch (Throwable t) {
        errors.add(t);
        failedQuietly(t, description, errors);
      } finally {
        finishedQuietly(description, errors);
      }

      MultipleFailureException.assertEmpty(errors);
    }
  };
}
 
Example #27
Source File: ActivitiFormRule.java    From activiti6-boot2 with Apache License 2.0 6 votes vote down vote up
/**
 * Implementation based on {@link TestWatcher}.
 */
@Override
public Statement apply(final Statement base, final Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      List<Throwable> errors = new ArrayList<Throwable>();

      startingQuietly(description, errors);
      try {
        base.evaluate();
        succeededQuietly(description, errors);
      } catch (AssumptionViolatedException e) {
        errors.add(e);
        skippedQuietly(e, description, errors);
      } catch (Throwable t) {
        errors.add(t);
        failedQuietly(t, description, errors);
      } finally {
        finishedQuietly(description, errors);
      }

      MultipleFailureException.assertEmpty(errors);
    }
  };
}
 
Example #28
Source File: AsyncTest.java    From mesos-rxjava with Apache License 2.0 5 votes vote down vote up
@Test
public void multipleExceptionReportedWhenTheyOccur() {
    final Async async = new Async();
    final IllegalStateException exception1 = new IllegalStateException("exception-1");
    final IllegalStateException exception2 = new IllegalStateException("exception-2");
    final IllegalStateException exception3 = new IllegalStateException("exception-3");
    async.run(() -> {
        throw exception1;
    });
    async.run(() -> {
        throw exception2;
    });
    async.run(() -> {
        throw exception3;
    });

    try {
        async.verify();
        fail("Exception should have been thrown in verify");
    } catch (MultipleFailureException mfe) {
        final Set<String> errorMessages = mfe.getFailures().stream()
            .map(Throwable::getCause)
            .map(Throwable::getMessage)
            .collect(Collectors.toSet());
        assertThat(errorMessages).isEqualTo(Sets.newHashSet("exception-1", "exception-2", "exception-3"));
        assertThat(mfe.getMessage()).contains("Error while running Async: exception-1");
    } catch (Throwable e) {
        fail("Expected MultipleFailureException but got: " + e.getClass().getName());
    }
}
 
Example #29
Source File: JGivenMethodRule.java    From JGiven with Apache License 2.0 5 votes vote down vote up
protected void failed( Throwable e ) throws Throwable {
    if( scenario.getExecutor().hasFailed() ) {
        Throwable failedException = scenario.getExecutor().getFailedException();
        List<Throwable> errors = Lists.newArrayList( failedException, e );
        scenario.getExecutor().setFailedException( new MultipleFailureException( errors ) );
    } else {
        scenario.getExecutor().failed( e );
    }

    scenario.finished();
}
 
Example #30
Source File: JUnitRuleFiberExceptions.java    From c5-replicator with Apache License 2.0 5 votes vote down vote up
@Override
public Statement apply(final Statement base, Description description) {
  return new Statement() {
    @Override
    public void evaluate() throws Throwable {
      try {
        base.evaluate();
      } catch (Throwable t) {
        throwables.add(t);
      }
      MultipleFailureException.assertEmpty(throwables);
    }
  };
}