@Test
 public void shouldCreateUser() throws Exception {
   final User savedUser = stubServiceToReturnStoredUser();
   final User user = UserUtil.createUser();
   User returnedUser = userController.createUser(user);
   // verify user was passed to UserService
   verify(userService, times(1)).create(user);
   assertEquals("Returned user should come from the service", savedUser, returnedUser);
 }
 private void stubServiceToReturnExistingUsers(int howMany) {
   when(userService.getAll()).thenReturn(UserUtil.createUserList(howMany));
 }
 private User stubServiceToReturnStoredUser() {
   final User user = UserUtil.createUser();
   when(userService.create(any(User.class))).thenReturn(user);
   return user;
 }