UserService { public User updateUser(String id, String name, String email) { failIfInvalid(name, email); Key key = keyFactory.newKey(id); Entity entity = datastore.get(key); if (entity == null) { throw new IllegalArgumentException("No user with id '" + id + "' found"); } else { entity = Entity.newBuilder(entity) .set("id", id) .set("name", name) .set("email", email) .build(); datastore.update(entity); } return new User(id, name, email); } UserService(Datastore datastore, String kind); List<User> getAllUsers(); User createUser(String name, String email); String deleteUser(String id); User updateUser(String id, String name, String email);  }
@Test public void testUpdateUser() { String newName = "myNewName"; String newEmail = "mynew@email.com"; User updatedUser = USER_SERVICE.updateUser(USER_ID, newName, newEmail); assertEquals(USER_ID, updatedUser.getId()); assertEquals(newName, updatedUser.getName()); assertEquals(newEmail, updatedUser.getEmail()); try { USER_SERVICE.updateUser(USER_ID, null, USER_EMAIL); fail("Expected to fail because name is null."); } catch (IllegalArgumentException e) { assertEquals("Parameter 'name' cannot be empty", e.getMessage()); } try { USER_SERVICE.updateUser(USER_ID, USER_NAME, null); fail("Expected to fail because email is null."); } catch (IllegalArgumentException e) { assertEquals("Parameter 'email' cannot be empty", e.getMessage()); } }