i'm trying to learn project Reactor and have the problem.
@Test
@DisplayName("check that standaloneUser fields are correct")
void validateUserFields() {
userService.save(standaloneUser).subscribe();
assertEquals(userService.count().block(), Long.valueOf(1));
User user = userService.findByEmail("[email protected]").block();
assertNotNull(user);
assertNotNull(user.getId());
assertEquals(user.getFirstName(), "test");
assertEquals(user.getLastName(), "test");
assertNotEquals(user.getPassword(), "test");
assertEquals(user.getRole(), Role.CANDIDATE);
assertNotNull(user.getCreatedDate());
assertNull(user.getStoppedDate());
assertEquals(user.getEmail(), "[email protected]");
}
Sometimes block() method returns null. Who can explain me this? Thanks
block()
can return null, it means theMono
completed empty, which in this case means the user wasn't found.Could it be that it wasn't properly saved? (although you assert the user count)
Note that you do
userService.save(standaloneUser).subscribe()
. This form is often not ideal, as it is "async fire-and-forget":Make an habit of at least setting onNext and onError handler lambdas when calling
subscribe
.