@Test public void testGenerateUpdateActivity() { Activity ret; ret = projectActivityGenerator.generateUpdateActivity(project, projectDeleted); assertEquals(ret.getAction(), ActivityActionType.DISCARD); ret = projectActivityGenerator.generateUpdateActivity(projectDeleted, project); assertEquals(ret.getAction(), ActivityActionType.RECOVER); ret = projectActivityGenerator.generateUpdateActivity(project, projectArchive); assertEquals(ret.getAction(), ActivityActionType.ARCHIVE); ret = projectActivityGenerator.generateUpdateActivity(projectArchive, project); assertEquals(ret.getAction(), ActivityActionType.ACTIVATE); ret = projectActivityGenerator.generateUpdateActivity(project, project); assertEquals(ret.getAction(), ActivityActionType.UPDATE); ret = projectActivityGenerator.generateUpdateActivity(project, projectName); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(ProjectActivityGenerator.NAME_UPDATE, project.getName(), projectName.getName())); ret = projectActivityGenerator.generateUpdateActivity(project, projectDescription); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(ProjectActivityGenerator.DESCRIPTION_UPDATE, project.getDescription(), projectDescription.getDescription())); ret = projectActivityGenerator.generateUpdateActivity(project, projectNameAndDescription); assertEquals(ret.getAction(), ActivityActionType.UPDATE); assertEquals(ret.getContent(), String.format(ProjectActivityGenerator.NAME_AND_DESCRIPTION_UPDATE, project.getName(), projectNameAndDescription.getName(), project.getDescription(),projectNameAndDescription.getDescription())); }
private Activity generateUpdateActivity(Project p1, Project p2) { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, p1); boolean changeName = p2.getName() != null && !p2.getName().equals(p1.getName()); boolean changeDescription = p2.getDescription() != null && !p2.getDescription().equals(p1.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, p1.getName(), p2.getName(), p1.getDescription(), p2.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, p1.getName(), p2.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, p1.getDescription(), p2.getDescription())); } return activity; }
ProjectActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Project p1, Project p2) { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, p1); boolean changeName = p2.getName() != null && !p2.getName().equals(p1.getName()); boolean changeDescription = p2.getDescription() != null && !p2.getDescription().equals(p1.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, p1.getName(), p2.getName(), p1.getDescription(), p2.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, p1.getName(), p2.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, p1.getDescription(), p2.getDescription())); } return activity; } }
ProjectActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Project p1, Project p2) { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, p1); boolean changeName = p2.getName() != null && !p2.getName().equals(p1.getName()); boolean changeDescription = p2.getDescription() != null && !p2.getDescription().equals(p1.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, p1.getName(), p2.getName(), p1.getDescription(), p2.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, p1.getName(), p2.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, p1.getDescription(), p2.getDescription())); } return activity; }  }
ProjectActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Project p1, Project p2) { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, p1); boolean changeName = p2.getName() != null && !p2.getName().equals(p1.getName()); boolean changeDescription = p2.getDescription() != null && !p2.getDescription().equals(p1.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, p1.getName(), p2.getName(), p1.getDescription(), p2.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, p1.getName(), p2.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, p1.getDescription(), p2.getDescription())); } return activity; }  @Override Activity generateCreateActivity(BaseProjectItem item); @Override Activity generateUpdateActivity(BaseProjectItem item, BaseProjectItem modifiedItem); @Override String modelType(); @Override BaseProjectItem enrichModel(BaseProjectItem identifiable); @Override String modelService(); }
ProjectActivityGenerator implements ActivityGenerator { private Activity generateUpdateActivity(Project p1, Project p2) { Activity activity = this.generateActivityByActionType(ActivityActionType.UPDATE, UPDATE_SUBJECT, p1); boolean changeName = p2.getName() != null && !p2.getName().equals(p1.getName()); boolean changeDescription = p2.getDescription() != null && !p2.getDescription().equals(p1.getDescription()); if (changeName & changeDescription) { activity.setContent(String.format(NAME_AND_DESCRIPTION_UPDATE, p1.getName(), p2.getName(), p1.getDescription(), p2.getDescription())); } else if (changeName) { activity.setContent(String.format(NAME_UPDATE, p1.getName(), p2.getName())); } else if (changeDescription) { activity.setContent(String.format(DESCRIPTION_UPDATE, p1.getDescription(), p2.getDescription())); } return activity; }  @Override Activity generateCreateActivity(BaseProjectItem item); @Override Activity generateUpdateActivity(BaseProjectItem item, BaseProjectItem modifiedItem); @Override String modelType(); @Override BaseProjectItem enrichModel(BaseProjectItem identifiable); @Override String modelService(); static final String CREATE_SUBJECT; static final String UPDATE_SUBJECT; static final String DISCARD_SUBJECT; static final String RECOVER_SUBJECT; static final String ARCHIVE_SUBJECT; static final String ACTIVATE_SUBJECT; static final String NAME_UPDATE; static final String DESCRIPTION_UPDATE; static final String NAME_AND_DESCRIPTION_UPDATE; }