@Test public void applyUpdate() throws Exception { UsergroupChangeUpdate update = new UsergroupChangeUpdate(date, creator1, completeUsergroup); update.applyUpdate(mockRepos); verify(mockUserGroupRepository).getGroup(group1); verify(mockUsergroup).setName("Gruppe"); verify(mockUserGroupRepository).updateGroupMembers(group1, ids); verify(mockUserGroupRepository).removeGroup(mockUsergroup); }
@Override public void applyUpdate(RepositorySet repositorySet) { UserGroup userGroupEntity = repositorySet.userGroupRepository .getGroup(usergroup.id); boolean newGroup = (userGroupEntity == null); if (newGroup) { userGroupEntity = new UserGroup(usergroup.id, usergroup.name); } else { userGroupEntity.setName(usergroup.name); } repositorySet.userGroupRepository .updateGroupMembers(usergroup.id, usergroup.members); Context ctx = TreffPunkt.getAppContext(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(ctx); int ownID = pref.getInt(ctx.getString(R.string.key_userId), -1); boolean kickedOut = true; for (int memberID : usergroup.members) if (memberID == ownID) kickedOut = false; if (kickedOut) repositorySet.userGroupRepository.removeGroup(userGroupEntity); else { if (newGroup) repositorySet.userGroupRepository.addGroup(userGroupEntity); else repositorySet.userGroupRepository.updateGroup(userGroupEntity); } }
UsergroupChangeUpdate extends Update { @Override public void applyUpdate(RepositorySet repositorySet) { UserGroup userGroupEntity = repositorySet.userGroupRepository .getGroup(usergroup.id); boolean newGroup = (userGroupEntity == null); if (newGroup) { userGroupEntity = new UserGroup(usergroup.id, usergroup.name); } else { userGroupEntity.setName(usergroup.name); } repositorySet.userGroupRepository .updateGroupMembers(usergroup.id, usergroup.members); Context ctx = TreffPunkt.getAppContext(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(ctx); int ownID = pref.getInt(ctx.getString(R.string.key_userId), -1); boolean kickedOut = true; for (int memberID : usergroup.members) if (memberID == ownID) kickedOut = false; if (kickedOut) repositorySet.userGroupRepository.removeGroup(userGroupEntity); else { if (newGroup) repositorySet.userGroupRepository.addGroup(userGroupEntity); else repositorySet.userGroupRepository.updateGroup(userGroupEntity); } } }
UsergroupChangeUpdate extends Update { @Override public void applyUpdate(RepositorySet repositorySet) { UserGroup userGroupEntity = repositorySet.userGroupRepository .getGroup(usergroup.id); boolean newGroup = (userGroupEntity == null); if (newGroup) { userGroupEntity = new UserGroup(usergroup.id, usergroup.name); } else { userGroupEntity.setName(usergroup.name); } repositorySet.userGroupRepository .updateGroupMembers(usergroup.id, usergroup.members); Context ctx = TreffPunkt.getAppContext(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(ctx); int ownID = pref.getInt(ctx.getString(R.string.key_userId), -1); boolean kickedOut = true; for (int memberID : usergroup.members) if (memberID == ownID) kickedOut = false; if (kickedOut) repositorySet.userGroupRepository.removeGroup(userGroupEntity); else { if (newGroup) repositorySet.userGroupRepository.addGroup(userGroupEntity); else repositorySet.userGroupRepository.updateGroup(userGroupEntity); } } UsergroupChangeUpdate(@JsonProperty("time-created") Date timeCreated,
                                 @JsonProperty("creator") int creator,
                                 @JsonProperty("usergroup") CompleteUsergroup group); }
UsergroupChangeUpdate extends Update { @Override public void applyUpdate(RepositorySet repositorySet) { UserGroup userGroupEntity = repositorySet.userGroupRepository .getGroup(usergroup.id); boolean newGroup = (userGroupEntity == null); if (newGroup) { userGroupEntity = new UserGroup(usergroup.id, usergroup.name); } else { userGroupEntity.setName(usergroup.name); } repositorySet.userGroupRepository .updateGroupMembers(usergroup.id, usergroup.members); Context ctx = TreffPunkt.getAppContext(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(ctx); int ownID = pref.getInt(ctx.getString(R.string.key_userId), -1); boolean kickedOut = true; for (int memberID : usergroup.members) if (memberID == ownID) kickedOut = false; if (kickedOut) repositorySet.userGroupRepository.removeGroup(userGroupEntity); else { if (newGroup) repositorySet.userGroupRepository.addGroup(userGroupEntity); else repositorySet.userGroupRepository.updateGroup(userGroupEntity); } } UsergroupChangeUpdate(@JsonProperty("time-created") Date timeCreated,
                                 @JsonProperty("creator") int creator,
                                 @JsonProperty("usergroup") CompleteUsergroup group); @Override void applyUpdate(RepositorySet repositorySet); }
UsergroupChangeUpdate extends Update { @Override public void applyUpdate(RepositorySet repositorySet) { UserGroup userGroupEntity = repositorySet.userGroupRepository .getGroup(usergroup.id); boolean newGroup = (userGroupEntity == null); if (newGroup) { userGroupEntity = new UserGroup(usergroup.id, usergroup.name); } else { userGroupEntity.setName(usergroup.name); } repositorySet.userGroupRepository .updateGroupMembers(usergroup.id, usergroup.members); Context ctx = TreffPunkt.getAppContext(); SharedPreferences pref = PreferenceManager .getDefaultSharedPreferences(ctx); int ownID = pref.getInt(ctx.getString(R.string.key_userId), -1); boolean kickedOut = true; for (int memberID : usergroup.members) if (memberID == ownID) kickedOut = false; if (kickedOut) repositorySet.userGroupRepository.removeGroup(userGroupEntity); else { if (newGroup) repositorySet.userGroupRepository.addGroup(userGroupEntity); else repositorySet.userGroupRepository.updateGroup(userGroupEntity); } } UsergroupChangeUpdate(@JsonProperty("time-created") Date timeCreated,
                                 @JsonProperty("creator") int creator,
                                 @JsonProperty("usergroup") CompleteUsergroup group); @Override void applyUpdate(RepositorySet repositorySet);  }