Reputation: 1903
How can I make a stub using Mockito to simulate the operation of a transaction in a reactive stack
.as(customerMono -> txOperator.transactional(customerMono))
private Mono<User> findUserByPhone(String mobilePhone) {
return service.findByMobilePhone(mobilePhone)
.flatMap(customer -> {
System.out.println(customer);
return Mono.just(customer);
})
.singleOrEmpty()
.as(customerMono -> txOperator.transactional(customerMono))
.flatMap(customer -> {
System.out.println(customer);
return Mono.just(customer);
})
.....
I tried this,
protected void mockWhenTxOperatorTransactional(){
Mockito.when(
this.txOperator.transactional(buildUserAsMono())
).thenReturn(buildUserAsMono());
}
private Mono<User> buildUserAsMono(){
int accountEnabled = 1;
User user = User.builder()
.enabled(accountEnabled)
.mobilePhone(this.phoneNumberExpected)
.build();
return Mono.just(user);
}
however I get the error anyway.
Suppressed: java.lang.NullPointerException at com.service.UserService.findCustomerByPhone(
Who knows, tell me an example, please
Upvotes: 0
Views: 100
Reputation: 1903
protected void mockWhenUsingTransactionalOperator(){
Mockito.when(
this.transactionalOperator.transactional(
any(Mono.class)
)
)
.thenReturn(
buildUserAsMono()
);
}
buildUserAsMono() - here is the object that is obtained at the output, after calling this.transactionalOperator.transactional(....)
Upvotes: 0