UserRef { public static UserRef of(User user) { Objects.requireNonNull(user, "user may not be null."); Objects.requireNonNull(user.getId(), "user ID may not be null."); return UserRef.of(user.getId()); }  static UserRef of(User user);  }
@Test void test() { Iterable<User> users = userRepository.saveAll( Stream.of("lola", "bola") .map(name -> new User(null, name)) .collect(Collectors.toList())); log.info("saved: {}", users); Iterator<User> iterator = userRepository.findAll() .iterator(); User from = iterator.next(); User to = iterator.next(); Iterable<Message> messages = messageRepository.saveAll( Stream.of("ololo", "trololo") .map(body -> new Message(null, body, UserRef.of(from), UserRef.of(to))) .collect(Collectors.toList())); log.info(messages); }