use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method empty.
@ParameterizedTestWithName
@MethodSource("sourcesEmpty")
void empty(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
source.doOnEach(s -> {
if (s.isOnNext()) {
onNext.set(s.get());
state.increment();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).filter(t -> true).subscribe(ts);
assertThat(onNext).hasValue(null);
assertThat(onError).hasValue(null);
assertThat(onComplete).isTrue();
assertThat(state.intValue()).isEqualTo(0);
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method nextCallbackError.
@ParameterizedTestWithName
@MethodSource("sources12Complete")
void nextCallbackError(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
Throwable err = new Exception("test");
source.doOnEach(s -> {
if (s.isOnNext()) {
state.increment();
throw Exceptions.propagate(err);
}
}).filter(t -> true).subscribe(ts);
// nominal error path (DownstreamException)
ts.assertErrorMessage("test");
assertThat(state.intValue()).isEqualTo(1);
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method completeCallbackError.
@ParameterizedTestWithName
@MethodSource("sources12Complete")
void completeCallbackError(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicBoolean completeHandled = new AtomicBoolean();
AtomicBoolean errorHandled = new AtomicBoolean();
Throwable err = new Exception("test");
source.doOnEach(s -> {
if (s.isOnComplete()) {
completeHandled.set(true);
throw Exceptions.propagate(err);
}
if (s.isOnError()) {
errorHandled.set(true);
}
}).filter(t -> true).subscribe(ts);
ts.assertErrorMessage("test");
assertThat(completeHandled).as("complete() handler triggered").isTrue();
assertThat(errorHandled).as("complete() failure passed to error handler triggered").isTrue();
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method nextCallbackBubbleError.
@ParameterizedTestWithName
@MethodSource("sources12Complete")
void nextCallbackBubbleError(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
LongAdder state = new LongAdder();
Throwable err = new Exception("test");
try {
source.doOnEach(s -> {
if (s.isOnNext()) {
state.increment();
throw Exceptions.bubble(err);
}
}).filter(t -> true).subscribe(ts);
fail("Exception expected");
} catch (Exception e) {
assertThat(Exceptions.unwrap(e)).isSameAs(err);
assertThat(state.intValue()).isEqualTo(1);
}
}
use of reactor.test.ParameterizedTestWithName in project reactor-core by reactor.
the class FluxDoOnEachTest method never.
@ParameterizedTestWithName
@MethodSource("sourcesNever")
void never(Flux<Integer> source) {
AssertSubscriber<Integer> ts = AssertSubscriber.create();
AtomicReference<Integer> onNext = new AtomicReference<>();
AtomicReference<Throwable> onError = new AtomicReference<>();
AtomicBoolean onComplete = new AtomicBoolean();
LongAdder state = new LongAdder();
source.doOnEach(s -> {
if (s.isOnNext()) {
onNext.set(s.get());
state.increment();
} else if (s.isOnError()) {
onError.set(s.getThrowable());
} else if (s.isOnComplete()) {
onComplete.set(true);
}
}).filter(t -> true).subscribe(ts);
assertThat(onNext).hasValue(null);
assertThat(onError).hasValue(null);
assertThat(onComplete).isFalse();
assertThat(state.intValue()).isEqualTo(0);
}
Aggregations