### Question:
Registration { public User getUserByCode(String code) { return pool.select("SELECT * FROM users where code = ?", new Object[] {code}, rs -> { if (!rs.next()) { throw new UsernameNotFoundException(String.format("User with code '%s' does not exist", code)); } return extractUser(rs); }); } Registration(ConnectionThreadPoolFactory factory, String adminEmail, String adminPassword, PasswordEncoder passwordEncoder, ConfigProperties properties, boolean initAdminUser); boolean approved(String id); boolean registered(String id); User getOrRegister(String id, String email, String readableName); User registerApproved(String id, String email, String readableName); User register(String id, String email, String readableName, String password, String data, Collection<String> roles); String login(String id, String password); String checkUser(String id); String checkUser(String id, String code); String checkUserByPassword(String id, String password); String getIdByCode(String code); boolean emailIsUsed(String email); boolean nameIsUsed(String name); String getEmailById(String id); String getIdByName(String name); String getIdByEmail(String email); String getNameById(String id); String getCodeById(String id); void approve(String code); void updateReadableName(String id, String name); void updateId(String name, String id); void updateNameAndEmail(String id, String name, String email); User getUserByCode(String code); Optional<User> getUserByEmail(String email); Optional<User> getUserById(String id); List<User> getUsers(); void replace(User user); void remove(String id); void removeAll(); static final int ADMIN_USER_ID; }### Answer:
@Test public void shouldGetUserByCode_notExistent() { try { Registration.User user = service.getUserByCode("bad_code"); fail("Expected exception"); } catch (Exception e) { assertEquals("java.util.concurrent.ExecutionException: " + "org.springframework.security.core.userdetails.UsernameNotFoundException: " + "User with code 'bad_code' does not exist", e.toString()); } }