@Override public StepVerifier.Assertions hasDroppedErrorWithMessageContaining( String messagePart) { //noinspection ConstantConditions satisfies(() -> messagePart != null, () -> "Require non-null messagePart"); hasDroppedErrors(1); String actual = hookRecorder.droppedErrors.peek().getMessage(); return satisfies(() -> actual != null && actual.contains(messagePart), () -> String.format("Expected dropped error with message containing <\"%s\">, was <\"%s\">.", messagePart, actual)); }
@Override public StepVerifier.Assertions hasOperatorErrorWithMessageContaining( String messagePart) { //noinspection ConstantConditions satisfies(() -> messagePart != null, () -> "Require non-null messagePart"); hasOneOperatorErrorWithError(); String actual = hookRecorder.operatorErrors.peek().getT1().get().getMessage(); return satisfies(() -> actual != null && actual.contains(messagePart), () -> String.format("Expected operator error with message containing <\"%s\">, was <\"%s\">.", messagePart, actual)); }
@Override public StepVerifier.Assertions hasOperatorErrorsSatisfying(Consumer<Collection<Tuple2<Optional<Throwable>, Optional<?>>>> asserter) { //noinspection ConstantConditions satisfies(() -> asserter != null, () -> "Require non-null asserter"); hasOperatorErrors(); asserter.accept(hookRecorder.operatorErrors); return this; }
@Override public Assertions verifyThenAssertThat(Duration duration) { HookRecorder stepRecorder = new HookRecorder(); stepRecorder.plugHooksForSubscriber(this); try { //trigger the verify Duration time = verify(duration); //return the assertion API return new DefaultStepVerifierAssertions(stepRecorder, time, errorFormatter); } finally { stepRecorder.unplugHooks(); } }
@Override public Assertions verifyThenAssertThat(Duration duration) { HookRecorder stepRecorder = new HookRecorder(); stepRecorder.plugHooks(parent.options); try { //trigger the verify Duration time = verify(duration); //return the assertion API return new DefaultStepVerifierAssertions(stepRecorder, time, parent.errorFormatter); } finally { stepRecorder.unplugHooks(); } }
StepVerifier.Assertions hasOneOperatorErrorWithError() { satisfies(() -> hookRecorder.operatorErrors.size() == 1, () -> String.format("Expected exactly one operator error, %d found.", hookRecorder.operatorErrors.size())); satisfies(() -> hookRecorder.operatorErrors.peek().getT1().isPresent(), () -> "Expected exactly one operator error with an actual throwable content, no throwable found."); return this; }
@Override public StepVerifier.Assertions hasDroppedErrors() { return satisfies(hookRecorder::hasDroppedErrors, () -> "Expected at least 1 dropped error, none found."); }
@Override public StepVerifier.Assertions hasNotDroppedElements() { return satisfies(hookRecorder::noDroppedElements, () -> String.format("Expected no dropped elements, found <%s>.", hookRecorder.droppedElements)); }
@Override public StepVerifier.Assertions hasDroppedElements() { return satisfies(hookRecorder::hasDroppedElements, () -> "Expected dropped elements, none found."); }
@Override public StepVerifier.Assertions hasOperatorErrorWithMessageContaining( String messagePart) { //noinspection ConstantConditions satisfies(() -> messagePart != null, () -> "Require non-null messagePart"); hasOneOperatorErrorWithError(); String actual = hookRecorder.operatorErrors.peek().getT1().get().getMessage(); return satisfies(() -> actual != null && actual.contains(messagePart), () -> String.format("Expected operator error with message containing <\"%s\">, was <\"%s\">.", messagePart, actual)); }
@Override public StepVerifier.Assertions hasOperatorErrorMatching(Predicate<Throwable> matcher) { //noinspection ConstantConditions satisfies(() -> matcher != null, () -> "Require non-null matcher"); hasOneOperatorErrorWithError(); return satisfies( () -> matcher.test(hookRecorder.operatorErrors.peek().getT1().orElse(null)), () -> String.format( "Expected operator error matching the given predicate, did not match: <%s>.", hookRecorder.operatorErrors.peek())); }
@Override public StepVerifier.Assertions hasOperatorErrorsSatisfying(Consumer<Collection<Tuple2<Optional<Throwable>, Optional<?>>>> asserter) { //noinspection ConstantConditions satisfies(() -> asserter != null, () -> "Require non-null asserter"); hasOperatorErrors(); asserter.accept(hookRecorder.operatorErrors); return this; }
@Override public StepVerifier.Assertions hasNotDroppedErrors() { return satisfies(hookRecorder::noDroppedErrors, () -> String.format("Expected no dropped errors, found <%s>.", hookRecorder.droppedErrors)); }
@Override public StepVerifier.Assertions hasNotDiscardedElements() { return satisfies(hookRecorder::noDiscardedElements, () -> String.format("Expected no discarded elements, found <%s>.", hookRecorder.discardedElements)); }
@Override public StepVerifier.Assertions hasDropped(Object... values) { //noinspection ConstantConditions satisfies(() -> values != null && values.length > 0, () -> "Require non-empty values"); List<Object> valuesList = Arrays.asList(values); return satisfies(() -> hookRecorder.droppedAllOf(valuesList), () -> String.format( "Expected dropped elements to contain <%s>, was <%s>.", valuesList, hookRecorder.droppedElements)); }
@Override public StepVerifier.Assertions hasDroppedErrorsSatisfying(Consumer<Collection<Throwable>> asserter) { //noinspection ConstantConditions satisfies(() -> asserter != null, () -> "Require non-null asserter"); hasDroppedErrors(); asserter.accept(hookRecorder.droppedErrors); return this; }
@Override public StepVerifier.Assertions hasDroppedErrorsMatching(Predicate<Collection<Throwable>> matcher) { //noinspection ConstantConditions satisfies(() -> matcher != null, () -> "Require non-null matcher"); hasDroppedErrors(); return satisfies(() -> matcher.test(hookRecorder.droppedErrors), () -> String.format( "Expected collection of dropped errors matching the given predicate, did not match: <%s>.", hookRecorder.droppedErrors)); }
@Override public StepVerifier.Assertions hasDroppedErrorWithMessageContaining( String messagePart) { //noinspection ConstantConditions satisfies(() -> messagePart != null, () -> "Require non-null messagePart"); hasDroppedErrors(1); String actual = hookRecorder.droppedErrors.peek().getMessage(); return satisfies(() -> actual != null && actual.contains(messagePart), () -> String.format("Expected dropped error with message containing <\"%s\">, was <\"%s\">.", messagePart, actual)); }
@Override public StepVerifier.Assertions hasOperatorErrorWithMessage(String message) { //noinspection ConstantConditions satisfies(() -> message != null, () -> "Require non-null message"); hasOneOperatorErrorWithError(); String actual = hookRecorder.operatorErrors.peek().getT1().get().getMessage(); return satisfies(() -> message.equals(actual), () -> String.format("Expected operator error with message <\"%s\">, was <\"%s\">.", message, actual)); }
@Override public StepVerifier.Assertions hasOperatorErrorOfType(Class<? extends Throwable> clazz) { //noinspection ConstantConditions satisfies(() -> clazz != null, () -> "Require non-null clazz"); hasOneOperatorErrorWithError(); return satisfies( () -> clazz.isInstance(hookRecorder.operatorErrors.peek().getT1().get()), () -> String.format("Expected operator error to be of type %s, was %s.", clazz.getCanonicalName(), hookRecorder.operatorErrors.peek().getT1().get().getClass().getCanonicalName())); }