Giriş
Açıklaması şöyle
When testing reactive components, ensure you cover error scenarios using StepVerifier to verify the behavior of your reactive streams in response to different types of errors.
Örnek
Şöyle yaparız
import org.junit.jupiter.api.Test;import reactor.core.publisher.Flux;import reactor.test.StepVerifier;public class ReactiveStreamTest {@Testpublic void testFlux() {Flux<Integer> numbers = Flux.just(1, 2, 3, 4, 5);StepVerifier.create(numbers).expectNext(1, 2, 3, 4, 5).verifyComplete();}@Testpublic void testTransformations() {Flux<Integer> numbers = Flux.just(1, 2, 3, 4, 5);StepVerifier.create(numbers.filter(number -> number % 2 == 0).map(evenNumber -> evenNumber * 2)).expectNext(4, 8).verifyComplete();}@Testpublic void testWithError() {Flux<Integer> numbers = Flux.just(1, 2, 3).concatWith(Flux.error(new RuntimeException("Oops! An error occurred.")));StepVerifier.create(numbers).expectNext(1, 2, 3).expectError(RuntimeException.class).verify();}}
Hiç yorum yok:
Yorum Gönder