@Test public void givenTheUserDoesNotExist_WhenItIsSaved_ThenANewUserIsAdded() { when(datastoreGetActionsMock.user(user.getId())).thenReturn(null); final boolean isSuccessful = datastoreSaveActions.users(users); verify(datastoreGetActionsMock, times(1)).user(user.getId()); verifyNoMoreInteractions(datastoreGetActionsMock); verify(datastoreAddActionsMock, times(1)).user(user); verifyNoMoreInteractions(datastoreAddActionsMock); assertThat(isSuccessful).isTrue(); }
@Override public boolean users(final List<User> users) { for (final User user : users) { @Nullable final User existingRealUser = datastoreGetActions.user(user.getId()); if (existingRealUser == null) { datastoreAddActions.user(user); } else { datastoreUpdateActions.user(existingRealUser, user); } } return true; }
DatastoreSaveActions implements SaveActions { @Override public boolean users(final List<User> users) { for (final User user : users) { @Nullable final User existingRealUser = datastoreGetActions.user(user.getId()); if (existingRealUser == null) { datastoreAddActions.user(user); } else { datastoreUpdateActions.user(existingRealUser, user); } } return true; } }
DatastoreSaveActions implements SaveActions { @Override public boolean users(final List<User> users) { for (final User user : users) { @Nullable final User existingRealUser = datastoreGetActions.user(user.getId()); if (existingRealUser == null) { datastoreAddActions.user(user); } else { datastoreUpdateActions.user(existingRealUser, user); } } return true; } DatastoreSaveActions(final DatastoreAddActions datastoreAddActions, final DatastoreGetActions datastoreGetActions,
                                final DatastoreUpdateActions datastoreUpdateActions); }
DatastoreSaveActions implements SaveActions { @Override public boolean users(final List<User> users) { for (final User user : users) { @Nullable final User existingRealUser = datastoreGetActions.user(user.getId()); if (existingRealUser == null) { datastoreAddActions.user(user); } else { datastoreUpdateActions.user(existingRealUser, user); } } return true; } DatastoreSaveActions(final DatastoreAddActions datastoreAddActions, final DatastoreGetActions datastoreGetActions,
                                final DatastoreUpdateActions datastoreUpdateActions); @Override boolean users(final List<User> users); }
DatastoreSaveActions implements SaveActions { @Override public boolean users(final List<User> users) { for (final User user : users) { @Nullable final User existingRealUser = datastoreGetActions.user(user.getId()); if (existingRealUser == null) { datastoreAddActions.user(user); } else { datastoreUpdateActions.user(existingRealUser, user); } } return true; } DatastoreSaveActions(final DatastoreAddActions datastoreAddActions, final DatastoreGetActions datastoreGetActions,
                                final DatastoreUpdateActions datastoreUpdateActions); @Override boolean users(final List<User> users);  }