@Test public void testFindUserByIdReturnsNullForNonExistingUserId() { when(userViewRepository.findByIdentifier(testUserId.getIdentifier())).thenReturn(null); assertNull(testSubject.find(new UserByIdQuery(testUserId))); }
@QueryHandler public UserView find(UserByIdQuery query) { String userId = query.getUserId().getIdentifier(); return Optional.ofNullable(userRepository.findByIdentifier(userId)) .orElseGet(() -> { logger.warn("Tried to retrieve a User query model with a non existent user id [{}]", userId); return null; }); }
UserEventHandler { @QueryHandler public UserView find(UserByIdQuery query) { String userId = query.getUserId().getIdentifier(); return Optional.ofNullable(userRepository.findByIdentifier(userId)) .orElseGet(() -> { logger.warn("Tried to retrieve a User query model with a non existent user id [{}]", userId); return null; }); } }
UserEventHandler { @QueryHandler public UserView find(UserByIdQuery query) { String userId = query.getUserId().getIdentifier(); return Optional.ofNullable(userRepository.findByIdentifier(userId)) .orElseGet(() -> { logger.warn("Tried to retrieve a User query model with a non existent user id [{}]", userId); return null; }); } UserEventHandler(UserViewRepository userRepository); }
UserEventHandler { @QueryHandler public UserView find(UserByIdQuery query) { String userId = query.getUserId().getIdentifier(); return Optional.ofNullable(userRepository.findByIdentifier(userId)) .orElseGet(() -> { logger.warn("Tried to retrieve a User query model with a non existent user id [{}]", userId); return null; }); } UserEventHandler(UserViewRepository userRepository); @EventHandler void on(UserCreatedEvent event); @QueryHandler UserView find(UserByIdQuery query); @QueryHandler List<UserView> findAll(FindAllUsersQuery query); }
UserEventHandler { @QueryHandler public UserView find(UserByIdQuery query) { String userId = query.getUserId().getIdentifier(); return Optional.ofNullable(userRepository.findByIdentifier(userId)) .orElseGet(() -> { logger.warn("Tried to retrieve a User query model with a non existent user id [{}]", userId); return null; }); } UserEventHandler(UserViewRepository userRepository); @EventHandler void on(UserCreatedEvent event); @QueryHandler UserView find(UserByIdQuery query); @QueryHandler List<UserView> findAll(FindAllUsersQuery query);  }