/** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. * * @param b If <code>false</code>, the method will attempt to stop the test and ignore it by * throwing {@link AssumptionViolatedException}. * @param message A message to pass to {@link AssumptionViolatedException}. */ public static void assumeTrue(String message, boolean b) { if (!b) throw new AssumptionViolatedException(message); }
/** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(actual, matcher); } }
/** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(String message, T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(message, actual, matcher); } }
private void verify(SentinelsAvailable verificationMode) { int failed = 0; for (RedisNode node : sentinelConfig.getSentinels()) { if (!isAvailable(node)) { failed++; } } if (failed > 0) { if (SentinelsAvailable.ALL_ACTIVE.equals(verificationMode)) { throw new AssumptionViolatedException( String.format("Expected all Redis Sentinels to respone but %s of %s did not responde", failed, sentinelConfig.getSentinels().size())); } if (SentinelsAvailable.ONE_ACTIVE.equals(verificationMode) && sentinelConfig.getSentinels().size() - 1 < failed) { throw new AssumptionViolatedException( "Expected at least one sentinel to respond but it seems all are offline - Game Over!"); } } if (SentinelsAvailable.NONE_ACTIVE.equals(verificationMode) && failed != sentinelConfig.getSentinels().size()) { throw new AssumptionViolatedException( String.format("Expected to have no sentinels online but found that %s are still alive.", (sentinelConfig.getSentinels().size() - failed))); } }
/** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. * * @param b If <code>false</code>, the method will attempt to stop the test and ignore it by * throwing {@link AssumptionViolatedException}. * @param message A message to pass to {@link AssumptionViolatedException}. */ public static void assumeTrue(String message, boolean b) { if (!b) throw new AssumptionViolatedException(message); }
/** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(actual, matcher); } }
/** * Call to assume that <code>actual</code> satisfies the condition specified by <code>matcher</code>. * If not, the test halts and is ignored. * Example: * <pre>: * assumeThat(1, is(1)); // passes * foo(); // will execute * assumeThat(0, is(1)); // assumption failure! test halts * int x = 1 / 0; // will never execute * </pre> * * @param <T> the static type accepted by the matcher (this can flag obvious compile-time problems such as {@code assumeThat(1, is("a"))} * @param actual the computed value being compared * @param matcher an expression, built of {@link Matcher}s, specifying allowed values * @see org.hamcrest.CoreMatchers * @see org.junit.matchers.JUnitMatchers */ public static <T> void assumeThat(String message, T actual, Matcher<T> matcher) { if (!matcher.matches(actual)) { throw new AssumptionViolatedException(message, actual, matcher); } }
/** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. * * @param b If <code>false</code>, the method will attempt to stop the test and ignore it by * throwing {@link AssumptionViolatedException}. * @param message A message to pass to {@link AssumptionViolatedException}. */ public static void assumeTrue(String message, boolean b) { if (!b) throw new AssumptionViolatedException(message); }
/** * report a test has been skipped for some reason * @param message message to use in the text * @throws AssumptionViolatedException always */ public static void skip(String message) { throw new AssumptionViolatedException(message); }
/** * report an overridden test as unsupported * @param message message to use in the text * @throws AssumptionViolatedException always */ public static void unsupported(String message) { throw new AssumptionViolatedException(message); }
/** * If called with an expression evaluating to {@code false}, the test will halt and be ignored. * * @param b If <code>false</code>, the method will attempt to stop the test and ignore it by * throwing {@link AssumptionViolatedException}. * @param message A message to pass to {@link AssumptionViolatedException}. */ public static void assumeTrue(String message, boolean b) { if (!b) throw new AssumptionViolatedException(message); }
@Override public void failComparing( String message, CharSequence expected, CharSequence actual) { throw new AssumptionViolatedException(messageFor(message, expected, actual)); } @Override public void fail(String message, Throwable cause) {
private void check(WithOS withos, Class<?> testCase) { if (withos == null) return; // Checks performed in this annotation only makes sense if Jenkins and Tests are being executed in the same machine if (!(controller instanceof LocalController)) { throw new AssumptionViolatedException("Test skipped. WithOS should be used with a local controller, otherwise it cannot be fully trusted to work as expected."); } String errorMsg = "Test and Jenkins instance must be running on any of the following operating systems: " + Arrays.toString(withos.os()); if (!Arrays.asList(withos.os()).contains(currentOS())) { throw new AssumptionViolatedException(errorMsg); } }
@Override public void testAssumptionFailure(Failure failure) { // AssumptionViolatedException might not be Serializable. Recreate with only String message. exception = new AssumptionViolatedException(failure.getException().getMessage()); exception.setStackTrace(failure.getException().getStackTrace()); ; }
/** * report a test has been skipped for some reason * @param message message to use in the text * @throws AssumptionViolatedException always */ public static void skip(String message) { LOG.info("Skipping: {}", message); throw new AssumptionViolatedException(message); }
/** * report a test has been skipped for some reason * @param message message to use in the text * @throws AssumptionViolatedException always */ public static void skip(String message) { LOG.info("Skipping: {}", message); throw new AssumptionViolatedException(message); }
/** * Include at the start of tests to skip them if the FS is not enabled. */ protected void assumeEnabled() { if (!contract.isEnabled()) throw new AssumptionViolatedException("test cases disabled for " + contract); }
private void checkForAssumptionViolations() { if (StepEventBus.getEventBus().assumptionViolated()) { throw new AssumptionViolatedException(StepEventBus.getEventBus().getAssumptionViolatedMessage()); } } }
@Test public void shouldSkipResultIfExceptionCaughtAfterJunit() throws Exception { State.caughtExceptionAfterJunit(new AssumptionViolatedException("A")); TestResult result = TestResult.failed(new AssumptionViolatedException("A")); new UpdateTestResultBeforeAfter().update(event, result); State.caughtExceptionAfterJunit(null); Assert.assertEquals(Status.SKIPPED, result.getStatus()); Assert.assertNotNull(result.getThrowable()); Assert.assertTrue(result.getThrowable() instanceof AssumptionViolatedException); }
@Test public void shouldSkipResultIfExceptionCaughtAfterJunit() throws Exception { State.caughtExceptionAfterJunit(new AssumptionViolatedException("A")); TestResult result = TestResult.failed(new AssumptionViolatedException("A")); new UpdateTestResultBeforeAfter().update(event, result); State.caughtExceptionAfterJunit(null); Assert.assertEquals(Status.SKIPPED, result.getStatus()); Assert.assertNotNull(result.getThrowable()); Assert.assertTrue(result.getThrowable() instanceof AssumptionViolatedException); }