Posts

Showing posts with the label junit

How would I test a no events yet logic with from RxJava with Project Reactor Stepverifier?

How would I test a no events yet logic with from RxJava with Project Reactor Stepverifier? I'm currently trying to figure out, how to do a similar test in Project Reactor. Basically I want to ensure that before connect no events occur. @Test void connectable() { Observable<String> provider = Observable.just("Test1", "Test2"); ConnectableObservable<String> connectable = provider.publish(); TestObserver<String> testSubscriber = connectable.test(); testSubscriber.assertEmpty(); connectable.connect(); testSubscriber.assertResult("Test1", "Test2").assertComplete(); } This is my current attempt, but it is not correct, how would I get this to work? @Test void connectable() { Flux<String> provider = Flux.just("Test1", "Test2"); ConnectableFlux<String> connectable = provider.publish(); FirstStep<String> tester = StepVerifier.create(connectable).expectNoEvent(Du...

How to mock java.util.base64 methods using mockito

How to mock java.util.base64 methods using mockito I have REST API which returns json response i am writing test case for the REST api method using mockito There is a xml response in the json so i am trying to encode the xml string in the json using Base64 My test case throws null pointer exception while executing the Base64.encode line in the REST api method I cant use powermockito , its not used in the organisation how can i fix this issue using mockito itself below is the line of code which throws error Base64.getEncoder().encodeToString((message)).getBytes(StandardCharsets.UTF_8); Here message is the xml string . 1 Answer 1 Are you sure you have to embed your XML in your JSON? Perhaps it would make for an easier API if you could transform your XML to JSON and not encode anything? But, If you're sure you have to have XML nested in JSON, then you should pass Base64.getEncoder() result as you...