From 455c0f53b0531f3f542426fc6253733de4dac16a Mon Sep 17 00:00:00 2001 From: Vova Perebykivskyi Date: Tue, 24 May 2016 16:55:13 +0300 Subject: [PATCH] Update Hibernate stack. Update Hibernate ID generator. Changes to Hibernate mappings. Changes to OrderFileTest. Code refactoring. --- NEWS.rst | 8 +- conf/libreplan.xml | 10 +- .../java/org/zkoss/ganttz/TaskComponent.java | 95 +- .../CriticalPathCalculatorTest.java | 3025 ++++++++--------- .../timetracker/OnColumnsRowRendererTest.java | 16 +- .../ganttz/util/MutableTreeModelTest.java | 67 +- libreplan-business/pom.xml | 76 +- .../libreplan/business/BootstrapOrder.java | 13 +- .../advance/daos/AdvanceAssignmentDAO.java | 6 +- .../advance/entities/AdvanceAssignment.java | 27 +- .../advance/entities/AdvanceType.java | 87 +- .../daos/CalendarExceptionTypeDAO.java | 21 +- .../calendars/entities/CalendarBootstrap.java | 53 +- .../entities/CalendarExceptionType.java | 69 +- .../entities/CalendarExceptionTypeColor.java | 3 +- .../common/AdHocTransactionService.java | 67 +- .../libreplan/business/common/BaseEntity.java | 13 +- .../business/common/Configuration.java | 14 +- .../business/common/IntegrationEntity.java | 50 +- .../libreplan/business/common/Registry.java | 22 +- .../common/daos/EntitySequenceDAO.java | 71 +- .../common/daos/GenericDAOHibernate.java | 34 +- .../business/common/daos/IGenericDAO.java | 148 +- .../email/entities/EmailNotification.java | 4 +- .../email/entities/EmailTemplate.java | 2 +- .../email/entities/EmailTemplateEnum.java | 2 +- .../entities/CommunicationType.java | 8 +- ...ibernateDatabaseModificationsListener.java | 89 +- .../PredefinedDatabaseSnapshots.java | 266 +- .../business/labels/entities/LabelType.java | 50 +- .../business/orders/daos/OrderElementDAO.java | 241 +- .../business/orders/daos/OrderFileDAO.java | 8 +- .../business/orders/entities/HoursGroup.java | 108 +- .../orders/entities/OrderElement.java | 712 ++-- .../business/orders/entities/OrderLine.java | 99 +- .../orders/entities/OrderLineGroup.java | 258 +- .../orders/entities/SumChargedEffort.java | 18 +- .../entities/SubcontractedTaskData.java | 86 +- .../entities/SubcontractorCommunication.java | 21 +- .../business/resources/daos/CriterionDAO.java | 96 +- .../resources/daos/ResourcesSearcher.java | 114 +- .../business/scenarios/entities/Scenario.java | 72 +- .../entities/OrderElementTemplate.java | 214 +- .../business/users/daos/UserDAO.java | 49 +- .../business/users/entities/User.java | 95 +- .../workreports/entities/WorkReportType.java | 251 +- .../src/main/resources/db.changelog-1.0.xml | 3 +- .../src/main/resources/db.changelog-1.1.xml | 11 +- .../src/main/resources/db.changelog-1.2.xml | 8 +- .../src/main/resources/db.changelog-1.3.xml | 3 +- .../src/main/resources/db.changelog-1.4.xml | 3 +- .../src/main/resources/db.changelog-1.5.xml | 3 +- .../main/resources/db.changelog-database.xml | 89 +- .../main/resources/db.changelog-initial.xml | 9 +- .../src/main/resources/db.changelog.xml | 19 +- .../libreplan-business-hibernate.cfg.xml | 4 +- .../libreplan-business-spring-config.xml | 27 +- .../business/advance/entities/Advance.hbm.xml | 244 +- .../calendars/entities/Calendars.hbm.xml | 58 +- .../common/entities/Configuration.hbm.xml | 113 +- .../common/entities/Connector.hbm.xml | 12 +- .../common/entities/EntitySequence.hbm.xml | 16 +- .../JobSchedulerConfiguration.hbm.xml | 15 +- .../business/common/entities/Limits.hbm.xml | 7 +- .../entities/CostCategories.hbm.xml | 158 +- .../business/email/entities/Email.hbm.xml | 12 +- .../entities/ExpenseSheets.hbm.xml | 43 +- .../entities/ExternalCompanies.hbm.xml | 139 +- .../business/labels/entities/Labels.hbm.xml | 103 +- .../business/logs/entities/Logs.hbm.xml | 9 +- .../materials/entities/Materials.hbm.xml | 209 +- .../business/orders/entities/Orders.hbm.xml | 165 +- .../entities/AdvanceConsolidations.hbm.xml | 51 +- .../entities/ResourceAllocations.hbm.xml | 155 +- .../SubcontractorCommunication.hbm.xml | 40 +- .../business/planner/entities/Tasks.hbm.xml | 120 +- .../entities/QualityForms.hbm.xml | 134 +- .../entities/Requirements.hbm.xml | 76 +- .../resources/entities/Resources.hbm.xml | 448 +-- .../scenarios/entities/Scenarios.hbm.xml | 19 +- .../templates/entities/Templates.hbm.xml | 38 +- .../business/users/entities/Users.hbm.xml | 87 +- .../workreports/entities/WorkReports.hbm.xml | 285 +- .../advance/entities/AdvanceTypeTest.java | 12 +- .../test/orders/daos/OrderElementDAOTest.java | 260 +- .../bootstrap/CriterionsBootstrapTest.java | 11 +- .../test/resources/daos/ResourceDAOTest.java | 127 +- .../entities/WorkReportTypeTest.java | 25 +- .../src/test/resources/TestEntities.hbm.xml | 44 +- .../libreplan-business-hibernate-test.cfg.xml | 5 +- .../libreplan-business-spring-config-test.xml | 38 +- .../libreplan/importers/TimSoapClient.java | 86 +- .../libreplan/web/LoggingConfiguration.java | 8 +- .../web/bootstrap/BootstrapListener.java | 54 +- .../OrderElementsMultipleFiltersFinder.java | 71 +- .../AdvanceConsolidationController.java | 26 +- .../web/planner/order/OrderPlanningModel.java | 611 ++-- ...contractorCommunicationCRUDController.java | 111 +- .../web/users/bootstrap/PredefinedUsers.java | 103 +- .../ws/boundusers/api/package-info.java | 5 +- ...timisticLockingFailureExceptionMapper.java | 9 +- .../impl/ReportAdvancesServiceREST.java | 201 +- .../libreplan-webapp-spring-config.xml | 9 +- ...ibreplan-webapp-spring-security-config.xml | 6 +- .../LimitingDependencyComponent.js | 221 +- .../src/main/webapp/WEB-INF/web.xml | 14 +- .../subcontractorCommunications.zul | 43 +- .../libreplan/web/orders/OrderFilesTest.java | 302 +- .../bootstrap/UsersBootstrapInDBTest.java | 8 +- .../DBPasswordEncoderServiceTest.java | 8 +- .../services/DBUserDetailsServiceTest.java | 44 +- .../services/LDAPUserDetailsServiceTest.java | 42 +- .../ws/workreports/WorkReportServiceTest.java | 161 +- .../libreplan-webapp-hibernate-test.cfg.xml | 4 +- .../libreplan-webapp-spring-config-test.xml | 16 +- ...lan-webapp-spring-security-config-test.xml | 21 +- pom.xml | 38 +- 117 files changed, 6119 insertions(+), 6418 deletions(-) diff --git a/NEWS.rst b/NEWS.rst index ed525d9ba..8896311bb 100644 --- a/NEWS.rst +++ b/NEWS.rst @@ -58,6 +58,10 @@ Changes * Update Spring Security Web * Update Spring Security Config +* Update Hibernate Core +* Update Hibernate Ehcache +* Update Hibernate Validator + * Update MPXJ * Update Bonecp * Update Guava @@ -75,7 +79,9 @@ Changes * Update JAX-RS API * Update BeanShell * Update Quartz Framework -* Update Hibernate +* Update Usertype.Core + +* Add Javax EL * Update LibrePlan version to 1.6.0 diff --git a/conf/libreplan.xml b/conf/libreplan.xml index 2eb4921c0..440ad8666 100644 --- a/conf/libreplan.xml +++ b/conf/libreplan.xml @@ -2,9 +2,9 @@ + type="javax.sql.DataSource" + maxActive="100" maxIdle="30" maxWait="10000" + username="libreplan" password="libreplan" + driverClassName="org.postgresql.Driver" + url="jdbc:postgresql://localhost/libreplan" /> diff --git a/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java b/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java index 5b40c63bf..07cab2efd 100644 --- a/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java +++ b/ganttzk/src/main/java/org/zkoss/ganttz/TaskComponent.java @@ -21,7 +21,6 @@ package org.zkoss.ganttz; -import java.beans.PropertyChangeEvent; import java.beans.PropertyChangeListener; import java.io.IOException; import java.util.Date; @@ -35,8 +34,6 @@ import org.joda.time.Duration; import org.joda.time.LocalDate; import org.zkoss.ganttz.adapters.IDisabilityConfiguration; import org.zkoss.ganttz.data.GanttDate; -import org.zkoss.ganttz.data.ITaskFundamentalProperties.IModifications; -import org.zkoss.ganttz.data.ITaskFundamentalProperties.IUpdatablePosition; import org.zkoss.ganttz.data.Milestone; import org.zkoss.ganttz.data.Task; import org.zkoss.ganttz.data.Task.IReloadResourcesTextRequested; @@ -111,7 +108,9 @@ public class TaskComponent extends Div implements AfterCompose { setClass(calculateCSSClass()); setId(UUID.randomUUID().toString()); this.disabilityConfiguration = disabilityConfiguration; - taskViolationListener = Constraint.onlyOnZKExecution(new IConstraintViolationListener() { + + IConstraintViolationListener taskViolationListener = + Constraint.onlyOnZKExecution(new IConstraintViolationListener() { @Override public void constraintViolated(Constraint constraint, GanttDate value) { @@ -125,23 +124,18 @@ public class TaskComponent extends Div implements AfterCompose { }); this.task.addConstraintViolationListener(taskViolationListener, Mode.RECEIVE_PENDING); - reloadResourcesTextRequested = new IReloadResourcesTextRequested() { - - @Override - public void reloadResourcesTextRequested() { - if ( canShowResourcesText() ) { - smartUpdate("resourcesText", getResourcesText()); - } - - String cssClass = calculateCSSClass(); - - response("setClass", new AuInvoke(TaskComponent.this, "setClass", cssClass)); - - // FIXME: Refactor to another listener - updateDeadline(); - invalidate(); + reloadResourcesTextRequested = () -> { + if ( canShowResourcesText() ) { + smartUpdate("resourcesText", getResourcesText()); } + String cssClass = calculateCSSClass(); + + response("setClass", new AuInvoke(TaskComponent.this, "setClass", cssClass)); + + // FIXME: Refactor to another listener + updateDeadline(); + invalidate(); }; this.task.addReloadListener(reloadResourcesTextRequested); @@ -155,9 +149,7 @@ public class TaskComponent extends Div implements AfterCompose { if ( command.equals("onUpdatePosition") ){ ta = retrieveTaskComponent(request); - ta.doUpdatePosition( - toInteger(retrieveData(request, "left")) - ); + ta.doUpdatePosition(toInteger(retrieveData(request, "left"))); Events.postEvent(new Event(getId(), ta, request.getData())); @@ -248,25 +240,15 @@ public class TaskComponent extends Div implements AfterCompose { public final void afterCompose() { updateProperties(); if ( propertiesListener == null ) { - propertiesListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - updateProperties(); - } - }; + propertiesListener = evt -> updateProperties(); } this.task.addFundamentalPropertiesChangeListener(propertiesListener); if ( showingAdvancePropertyListener == null ) { - showingAdvancePropertyListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if ( isInPage() && !(task instanceof Milestone) ) { - updateCompletionAdvance(); - } + showingAdvancePropertyListener = evt -> { + if ( isInPage() && !(task instanceof Milestone) ) { + updateCompletionAdvance(); } }; } @@ -274,13 +256,9 @@ public class TaskComponent extends Div implements AfterCompose { this.task.addAdvancesPropertyChangeListener(showingAdvancePropertyListener); if ( showingReportedHoursPropertyListener == null ) { - showingReportedHoursPropertyListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if ( isInPage() && !(task instanceof Milestone) ) { - updateCompletionReportedHours(); - } + showingReportedHoursPropertyListener = evt -> { + if ( isInPage() && !(task instanceof Milestone) ) { + updateCompletionReportedHours(); } }; } @@ -288,13 +266,9 @@ public class TaskComponent extends Div implements AfterCompose { this.task.addReportedHoursPropertyChangeListener(showingReportedHoursPropertyListener); if ( showingMoneyCostBarPropertyListener == null ) { - showingMoneyCostBarPropertyListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - if ( isInPage() && !(task instanceof Milestone) ) { - updateCompletionMoneyCostBar(); - } + showingMoneyCostBarPropertyListener = evt -> { + if ( isInPage() && !(task instanceof Milestone) ) { + updateCompletionMoneyCostBar(); } }; } @@ -302,14 +276,7 @@ public class TaskComponent extends Div implements AfterCompose { this.task.addMoneyCostBarPropertyChangeListener(showingMoneyCostBarPropertyListener); if ( criticalPathPropertyListener == null ) { - criticalPathPropertyListener = new PropertyChangeListener() { - - @Override - public void propertyChange(PropertyChangeEvent evt) { - updateClass(); - } - - }; + criticalPathPropertyListener = evt -> updateClass(); } this.task.addCriticalPathPropertyChangeListener(criticalPathPropertyListener); @@ -330,7 +297,6 @@ public class TaskComponent extends Div implements AfterCompose { private final Task task; private transient PropertyChangeListener propertiesListener; - private IConstraintViolationListener taskViolationListener; private String progressType; @@ -371,13 +337,7 @@ public class TaskComponent extends Div implements AfterCompose { void doUpdatePosition(int leftX) { GanttDate startBeforeMoving = this.task.getBeginDate(); final LocalDate newPosition = getMapper().toDate(leftX); - this.task.doPositionModifications(new IModifications() { - - @Override - public void doIt(IUpdatablePosition position) { - position.moveTo(GanttDate.createFrom(newPosition)); - } - }); + this.task.doPositionModifications(position -> position.moveTo(GanttDate.createFrom(newPosition))); boolean remainsInOriginalPosition = this.task.getBeginDate().equals(startBeforeMoving); if ( remainsInOriginalPosition ) { @@ -417,7 +377,8 @@ public class TaskComponent extends Div implements AfterCompose { * of the style */ protected void renderProperties(ContentRenderer renderer) throws IOException{ - if( getColor() != null ) setStyle("background-color : " + getColor()); + if ( getColor() != null ) + setStyle("background-color : " + getColor()); setWidgetAttribute("movingTasksEnabled", ((Boolean)isMovingTasksEnabled()).toString()); setWidgetAttribute("resizingTasksEnabled", ((Boolean)isResizingTasksEnabled()).toString()); diff --git a/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java b/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java index 72b924ba9..1325ed218 100644 --- a/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java +++ b/ganttzk/src/test/java/org/zkoss/ganttz/data/criticalpath/CriticalPathCalculatorTest.java @@ -31,6 +31,7 @@ import static org.junit.Assert.assertThat; import static org.zkoss.ganttz.data.constraint.ConstraintOnComparableValues.biggerOrEqualThan; import java.util.Arrays; +import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -55,49 +56,49 @@ public class CriticalPathCalculatorTest { private final LocalDate START = new LocalDate(2009, 12, 1); - private ITaskFundamentalProperties createTask(LocalDate start, - int durationDays) { + private ITaskFundamentalProperties createTask(LocalDate start, int durationDays) { ITaskFundamentalProperties result = createNiceMock(ITaskFundamentalProperties.class); expect(result.getBeginDate()).andReturn(toDate(start)).anyTimes(); - expect(result.getEndDate()).andReturn( - toDate(start.plusDays(durationDays))).anyTimes(); + expect(result.getEndDate()).andReturn(toDate(start.plusDays(durationDays))).anyTimes(); replay(result); + return result; } - private CriticalPathCalculator> buildCalculator() { + private CriticalPathCalculator> + buildCalculator() { + return CriticalPathCalculator.create(false); } private ITaskFundamentalProperties createTaskWithBiggerOrEqualThanConstraint( LocalDate start, int durationDays, LocalDate date) { + ITaskFundamentalProperties result = createNiceMock(ITaskFundamentalProperties.class); expect(result.getBeginDate()).andReturn(toDate(start)).anyTimes(); - expect(result.getEndDate()).andReturn( - toDate(start.plusDays(durationDays))).anyTimes(); + expect(result.getEndDate()).andReturn(toDate(start.plusDays(durationDays))).anyTimes(); GanttDate ganttDate = GanttDate.createFrom(date); Constraint constraint = biggerOrEqualThan(ganttDate); - expect(result.getStartConstraints()).andReturn( - Arrays.asList(constraint)).anyTimes(); + expect(result.getStartConstraints()).andReturn(Collections.singletonList(constraint)).anyTimes(); replay(result); + return result; } private ITaskFundamentalProperties createTaskWithEqualConstraint( LocalDate start, int durationDays, LocalDate date) { + ITaskFundamentalProperties result = createNiceMock(ITaskFundamentalProperties.class); expect(result.getBeginDate()).andReturn(toDate(start)).anyTimes(); - expect(result.getEndDate()).andReturn( - toDate(start.plusDays(durationDays))).anyTimes(); + expect(result.getEndDate()).andReturn(toDate(start.plusDays(durationDays))).anyTimes(); GanttDate ganttDate = GanttDate.createFrom(date); - Constraint constraint = ConstraintOnComparableValues - .equalTo(ganttDate); - expect(result.getStartConstraints()).andReturn( - Arrays.asList(constraint)).anyTimes(); + Constraint constraint = ConstraintOnComparableValues.equalTo(ganttDate); + expect(result.getStartConstraints()).andReturn(Collections.singletonList(constraint)).anyTimes(); replay(result); + return result; } @@ -105,11 +106,13 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties source, ITaskFundamentalProperties destination, DependencyType dependencyType) { + IDependency dependency = createNiceMock(IDependency.class); expect(dependency.getSource()).andReturn(source).anyTimes(); expect(dependency.getDestination()).andReturn(destination).anyTimes(); expect(dependency.getType()).andReturn(dependencyType).anyTimes(); replay(dependency); + return dependency; } @@ -118,10 +121,9 @@ public class CriticalPathCalculatorTest { } private int daysBetweenStartAndEnd(ITaskFundamentalProperties task) { - LocalDate start = LocalDate.fromDateFields(task.getBeginDate() - .toDayRoundedDate()); - LocalDate end = LocalDate.fromDateFields(task.getEndDate() - .toDayRoundedDate()); + LocalDate start = LocalDate.fromDateFields(task.getBeginDate().toDayRoundedDate()); + LocalDate end = LocalDate.fromDateFields(task.getEndDate().toDayRoundedDate()); + return Days.daysBetween(start, end).getDays(); } @@ -133,29 +135,23 @@ public class CriticalPathCalculatorTest { private void givenOneTask(int daysTask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - List listOfTasks = Arrays - .asList(createTask(START, daysTask1)); + List listOfTasks = Collections.singletonList(createTask(START, daysTask1)); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(listOfTasks).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn(listOfTasks) + + expect(diagramGraphExample.getIncomingTasksFor(isA(ITaskFundamentalProperties.class))) + .andReturn(new HashSet<>()) .anyTimes(); - expect(diagramGraphExample.getLatestTasks()) - .andReturn(listOfTasks).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) - .anyTimes(); - expect( - diagramGraphExample - .getIncomingTasksFor(isA(ITaskFundamentalProperties.class))) - .andReturn(new HashSet()) - .anyTimes(); - expect( - diagramGraphExample - .getOutgoingTasksFor(isA(ITaskFundamentalProperties.class))) - .andReturn(new HashSet()) + + expect(diagramGraphExample.getOutgoingTasksFor(isA(ITaskFundamentalProperties.class))) + .andReturn(new HashSet<>()) .anyTimes(); addTaskMethods(listOfTasks); @@ -165,12 +161,9 @@ public class CriticalPathCalculatorTest { private void addTaskMethods(List listOfTasks) { for (ITaskFundamentalProperties task : listOfTasks) { - expect(diagramGraphExample.getStartDate(task)).andReturn( - task.getBeginDate()).anyTimes(); - expect(diagramGraphExample.getStartConstraintsFor(task)).andReturn( - task.getStartConstraints()).anyTimes(); - expect(diagramGraphExample.getEndDateFor(task)).andReturn( - task.getEndDate()).anyTimes(); + expect(diagramGraphExample.getStartDate(task)).andReturn(task.getBeginDate()).anyTimes(); + expect(diagramGraphExample.getStartConstraintsFor(task)).andReturn(task.getStartConstraints()).anyTimes(); + expect(diagramGraphExample.getEndDateFor(task)).andReturn(task.getEndDate()).anyTimes(); } } @@ -184,29 +177,24 @@ public class CriticalPathCalculatorTest { private void givenTwoTasksNotConnected(int daysTask1, int daysTask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - List listOfTasks = Arrays.asList( - createTask(START, daysTask1), createTask(START, daysTask2)); + List listOfTasks = + Arrays.asList(createTask(START, daysTask1), createTask(START, daysTask2)); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(listOfTasks).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn(listOfTasks) + + expect(diagramGraphExample.getIncomingTasksFor(isA(ITaskFundamentalProperties.class))) + .andReturn(new HashSet<>()) .anyTimes(); - expect(diagramGraphExample.getLatestTasks()) - .andReturn(listOfTasks).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) - .anyTimes(); - expect( - diagramGraphExample - .getIncomingTasksFor(isA(ITaskFundamentalProperties.class))) - .andReturn(new HashSet()) - .anyTimes(); - expect( - diagramGraphExample - .getOutgoingTasksFor(isA(ITaskFundamentalProperties.class))) - .andReturn(new HashSet()) + + expect(diagramGraphExample.getOutgoingTasksFor(isA(ITaskFundamentalProperties.class))) + .andReturn(new HashSet<>()) .anyTimes(); addTaskMethods(listOfTasks); @@ -226,31 +214,28 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList(task1, - subtask1); + List listOfTasks = Arrays.asList(task1, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(subtask1)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) - .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -266,8 +251,7 @@ public class CriticalPathCalculatorTest { * |---- #### S2 #### * */ - private void givenTwoPairOfTasksNotConnected(int daysTask1, - int daysSubtask1, int daysTask2, int daysSubtask2) { + private void givenTwoPairOfTasksNotConnected(int daysTask1, int daysSubtask1, int daysTask2, int daysSubtask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); @@ -275,42 +259,40 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList(task1, - subtask1, task2, subtask2); + List listOfTasks = Arrays.asList(task1, subtask1, task2, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) - .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task2))) + + expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -325,46 +307,39 @@ public class CriticalPathCalculatorTest { * #### IT #### * */ - private void givenTwoTaskConnectedAndOneIndependentTask(int daysTask1, - int daysTask2, int daysIndependentTask) { + private void givenTwoTaskConnectedAndOneIndependentTask(int daysTask1, int daysTask2, int daysIndependentTask) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); - ITaskFundamentalProperties independentTask = createTask(START, - daysIndependentTask); + ITaskFundamentalProperties independentTask = createTask(START, daysIndependentTask); - List listOfTasks = Arrays.asList(task1, - task2, independentTask); + List listOfTasks = Arrays.asList(task1, task2, independentTask); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, independentTask)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(task2, independentTask)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, independentTask)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task2, independentTask)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) - .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(independentTask)) - .andReturn(new HashSet()) - .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(task2))) - .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(independentTask)) - .andReturn(new HashSet()) + + expect(diagramGraphExample.getIncomingTasksFor(independentTask)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(independentTask)).andReturn(new HashSet<>()).anyTimes(); + addTaskMethods(listOfTasks); replay(diagramGraphExample); @@ -377,43 +352,40 @@ public class CriticalPathCalculatorTest { * |---- #### S2 #### * */ - private void givenOneTaskWithTwoDependantTasks(int daysTask1, - int daysSubtask1, int daysSubtask2) { + private void givenOneTaskWithTwoDependantTasks(int daysTask1, int daysSubtask1, int daysSubtask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList(task, - subtask1, subtask2); + List listOfTasks = Arrays.asList(task, subtask1, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getOutgoingTasksFor(task)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -429,45 +401,40 @@ public class CriticalPathCalculatorTest { * #### T2 #### * */ - private void givenTwoTaskWithOneCommonDependantTask(int daysTask1, - int daysTask2, int daysSubtask1) { + private void givenTwoTaskWithOneCommonDependantTask(int daysTask1, int daysTask2, int daysSubtask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList(task1, - task2, subtask1); + List listOfTasks = Arrays.asList(task1, task2, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(subtask1)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Arrays.asList(task1, task2))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1, - task2))).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -484,8 +451,8 @@ public class CriticalPathCalculatorTest { * */ private void givenOneTaskWithTwoDependantTasksAndOneCommonDependantTask( - int daysTask1, int daysSubtask1, int daysSubtask2, - int daysFinalTask1) { + int daysTask1, int daysSubtask1, int daysSubtask2, int daysFinalTask1) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task = createTask(START, daysTask1); @@ -493,42 +460,44 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); ITaskFundamentalProperties finalTask = createTask(START, daysFinalTask1); - List listOfTasks = Arrays.asList(task, - subtask1, subtask2, finalTask); + List listOfTasks = Arrays.asList(task, subtask1, subtask2, finalTask); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(finalTask)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(finalTask)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getIncomingTasksFor(finalTask)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(finalTask)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(finalTask))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet(Arrays - .asList(finalTask))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(finalTask)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(finalTask))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(finalTask))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(finalTask)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -545,62 +514,56 @@ public class CriticalPathCalculatorTest { * */ private void givenTwoTaskWithOneCommonDependantTaskWithTwoDependantTasks( - int daysTask1, int daysTask2, int daysSubtask1, int daysFinalTask1, - int daysFinalTask2) { + int daysTask1, int daysTask2, int daysSubtask1, int daysFinalTask1, int daysFinalTask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - ITaskFundamentalProperties finalTask1 = createTask(START, - daysFinalTask1); - ITaskFundamentalProperties finalTask2 = createTask(START, - daysFinalTask2); + ITaskFundamentalProperties finalTask1 = createTask(START, daysFinalTask1); + ITaskFundamentalProperties finalTask2 = createTask(START, daysFinalTask2); - List listOfTasks = Arrays.asList(task1, - task2, subtask1, finalTask1, finalTask2); + List listOfTasks = Arrays.asList(task1, task2, subtask1, finalTask1, finalTask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(finalTask1, finalTask2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(finalTask1, finalTask2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Arrays.asList(task1, task2))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1, - task2))).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(finalTask1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(finalTask2)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList( - finalTask1, finalTask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(finalTask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(finalTask2)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Arrays.asList(finalTask1, finalTask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(finalTask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(finalTask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -634,66 +597,72 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task6 = createTask(START, 6); ITaskFundamentalProperties modifiableTask = createTask(START, daysTask); - List listOfTasks = Arrays.asList(task4, - task5, task8, task2, task3, task10, task6, modifiableTask); + List listOfTasks = + Arrays.asList(task4, task5, task8, task2, task3, task10, task6, modifiableTask); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task4, task6)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(task10, modifiableTask)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task4, task6)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task10, modifiableTask)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task4)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(task6)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(task4))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task4)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task6)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task5)).andReturn( - new HashSet(Arrays.asList(task4))) - .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task8)).andReturn( - new HashSet(Arrays.asList(task4))) + + expect(diagramGraphExample.getIncomingTasksFor(task8)) + .andReturn(new HashSet<>(Collections.singletonList(task4))) .anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(modifiableTask)) - .andReturn( - new HashSet(Arrays - .asList(task6))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task4, - task5))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task3)).andReturn( - new HashSet(Arrays.asList(task8, - task6))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task10)).andReturn( - new HashSet(Arrays.asList(task2, - task3))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task4)).andReturn( - new HashSet(Arrays.asList(task2, - task5, task8))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task6)).andReturn( - new HashSet(Arrays.asList( - modifiableTask, task3))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task5)).andReturn( - new HashSet(Arrays.asList(task2))) + .andReturn(new HashSet<>(Collections.singletonList(task6))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task8)).andReturn( - new HashSet(Arrays.asList(task3))) + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Arrays.asList(task4, task5))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(modifiableTask)) - .andReturn(new HashSet()) + + expect(diagramGraphExample.getIncomingTasksFor(task3)) + .andReturn(new HashSet<>(Arrays.asList(task8, task6))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task10))) + + expect(diagramGraphExample.getIncomingTasksFor(task10)) + .andReturn(new HashSet<>(Arrays.asList(task2, task3))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task3)).andReturn( - new HashSet(Arrays.asList(task10))) + + expect(diagramGraphExample.getOutgoingTasksFor(task4)) + .andReturn(new HashSet<>(Arrays.asList(task2, task5, task8))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task10)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task6)) + .andReturn(new HashSet<>(Arrays.asList(modifiableTask, task3))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task8)) + .andReturn(new HashSet<>(Collections.singletonList(task3))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(modifiableTask)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task10))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task3)) + .andReturn(new HashSet<>(Collections.singletonList(task10))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task10)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -713,31 +682,26 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); - List listOfTasks = Arrays.asList(task1, - task2); + List listOfTasks = Arrays.asList(task1, task2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); - IDependency dependency = createDependency( - task1, task2, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn( - dependency).anyTimes(); + IDependency dependency = createDependency(task1, task2, DependencyType.START_START); + expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(dependency).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(task2))) + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -752,44 +716,38 @@ public class CriticalPathCalculatorTest { * |- #### T2 #### * */ - private void givenPairOfTasksStartStartFirstOfThemWithOneSubtask( - int daysTask1, int daysSubtask1, int daysTask2) { + private void givenPairOfTasksStartStartFirstOfThemWithOneSubtask(int daysTask1, int daysSubtask1, int daysTask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); - List listOfTasks = Arrays.asList(task1, - subtask1, task2); + List listOfTasks = Arrays.asList(task1, subtask1, task2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, task2)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, task2)).anyTimes(); - IDependency dependency = createDependency( - task1, task2, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn( - dependency).anyTimes(); + IDependency dependency = createDependency(task1, task2, DependencyType.START_START); + expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(dependency).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(subtask1, - task2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, task2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -805,8 +763,9 @@ public class CriticalPathCalculatorTest { * |----------|- #### S2 #### * */ - private void givenTwoTasksWithSubtasksRelatedWithStartStart(int daysTask1, - int daysSubtask1, int daysTask2, int daysSubtask2) { + private void givenTwoTasksWithSubtasksRelatedWithStartStart( + int daysTask1, int daysSubtask1, int daysTask2, int daysSubtask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); @@ -814,45 +773,42 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task2 = createTask(START, daysTask2); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList(task1, - subtask1, task2, subtask2); + List listOfTasks = Arrays.asList(task1, subtask1, task2, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); + + IDependency dependency = + createDependency(subtask1, subtask2, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(subtask1, subtask2)).andReturn(dependency).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); - IDependency dependency = createDependency( - subtask1, subtask2, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(subtask1, subtask2)) - .andReturn(dependency).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Arrays.asList(task2, subtask1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task2, - subtask1))).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -870,8 +826,7 @@ public class CriticalPathCalculatorTest { * |- #### S3 #### * */ - private void givenExampleStartStart(int daysTask1, int daysSubtask1, - int daysSubtask2, int daysSubtask3) { + private void givenExampleStartStart(int daysTask1, int daysSubtask1, int daysSubtask2, int daysSubtask3) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); @@ -879,44 +834,42 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); ITaskFundamentalProperties subtask3 = createTask(START, daysSubtask3); - List listOfTasks = Arrays.asList(task1, - subtask1, subtask2, subtask3); + List listOfTasks = Arrays.asList(task1, subtask1, subtask2, subtask3); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2, subtask3)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2, subtask3)).anyTimes(); - IDependency dependency = createDependency( - subtask2, subtask3, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(subtask2, subtask3)) - .andReturn(dependency).anyTimes(); + IDependency dependency = + createDependency(subtask2, subtask3, DependencyType.START_START); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getDependencyFrom(subtask2, subtask3)).andReturn(dependency).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask3)).andReturn( - new HashSet(Arrays - .asList(subtask2))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask3)) + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)) - .andReturn( - new HashSet(Arrays - .asList(subtask3))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask3)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask3))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask3)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -936,31 +889,26 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); - List listOfTasks = Arrays.asList(task1, - task2); + List listOfTasks = Arrays.asList(task1, task2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task2)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(task2)).anyTimes(); - IDependency dependency = createDependency( - task1, task2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn( - dependency).anyTimes(); + IDependency dependency = createDependency(task1, task2, DependencyType.END_END); + expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(dependency).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(task2))) + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -976,44 +924,38 @@ public class CriticalPathCalculatorTest { * #### T2 #### -| * */ - private void givenPairOfTasksEndEndFirstOfThemWithOneSubtask(int daysTask1, - int daysSubtask1, int daysTask2) { + private void givenPairOfTasksEndEndFirstOfThemWithOneSubtask(int daysTask1, int daysSubtask1, int daysTask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties task2 = createTask(START, daysTask2); - List listOfTasks = Arrays.asList(task1, - subtask1, task2); + List listOfTasks = Arrays.asList(task1, subtask1, task2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task2, subtask1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(task2, subtask1)).anyTimes(); - IDependency dependency = createDependency( - task1, task2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn( - dependency).anyTimes(); + IDependency dependency = createDependency(task1, task2, DependencyType.END_END); + expect(diagramGraphExample.getDependencyFrom(task1, task2)).andReturn(dependency).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(subtask1, - task2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, task2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1029,8 +971,9 @@ public class CriticalPathCalculatorTest { * |---- #### S2 #### -| * */ - private void givenTwoTasksWithSubtasksRelatedWithEndEnd(int daysTask1, - int daysSubtask1, int daysTask2, int daysSubtask2) { + private void givenTwoTasksWithSubtasksRelatedWithEndEnd( + int daysTask1, int daysSubtask1, int daysTask2, int daysSubtask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); @@ -1038,45 +981,42 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task2 = createTask(START, daysTask2); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList(task1, - subtask1, task2, subtask2); + List listOfTasks = Arrays.asList(task1, subtask1, task2, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, task2)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(subtask2)).anyTimes(); + + IDependency dependency = + createDependency(subtask1, subtask2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, subtask2)).andReturn(dependency).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, task2)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask2)).anyTimes(); - IDependency dependency = createDependency( - subtask1, subtask2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, subtask2)) - .andReturn(dependency).anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Arrays.asList(task2, subtask1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task2, - subtask1))).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task1)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(task2)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1094,8 +1034,7 @@ public class CriticalPathCalculatorTest { * #### S3 #### -| * */ - private void givenExampleEndEnd(int daysTask1, int daysSubtask1, - int daysSubtask2, int daysSubtask3) { + private void givenExampleEndEnd(int daysTask1, int daysSubtask1, int daysSubtask2, int daysSubtask3) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); @@ -1103,44 +1042,42 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); ITaskFundamentalProperties subtask3 = createTask(START, daysSubtask3); - List listOfTasks = Arrays.asList(task1, - subtask1, subtask2, subtask3); + List listOfTasks = Arrays.asList(task1, subtask1, subtask2, subtask3); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1, subtask3)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask3)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task1, subtask3)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask3)).anyTimes(); - IDependency dependency = createDependency( - subtask2, subtask3, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask2, subtask3)) - .andReturn(dependency).anyTimes(); + IDependency dependency = + createDependency(subtask2, subtask3, DependencyType.END_END); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task1))) + expect(diagramGraphExample.getDependencyFrom(subtask2, subtask3)).andReturn(dependency).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(subtask3)) - .andReturn( - new HashSet(Arrays - .asList(subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)) - .andReturn( - new HashSet(Arrays - .asList(subtask3))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask3)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(subtask3))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask3)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1155,44 +1092,43 @@ public class CriticalPathCalculatorTest { * */ private void givenOneTaskWithTwoDependantTasksLastOneWithEqualConstraint( - int daysTask1, int daysSubtask1, int daysSubtask2, - LocalDate dateConstraintSubtask2) { + int daysTask1, int daysSubtask1, int daysSubtask2, LocalDate dateConstraintSubtask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - ITaskFundamentalProperties subtask2 = createTaskWithEqualConstraint( - START, daysSubtask2, dateConstraintSubtask2); - List listOfTasks = Arrays.asList(task, - subtask1, subtask2); + ITaskFundamentalProperties subtask2 = + createTaskWithEqualConstraint(START, daysSubtask2, dateConstraintSubtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + List listOfTasks = Arrays.asList(task, subtask1, subtask2); + + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getOutgoingTasksFor(task)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1207,44 +1143,43 @@ public class CriticalPathCalculatorTest { * */ private void givenOneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint( - int daysTask1, int daysSubtask1, int daysSubtask2, - LocalDate dateConstraintSubtask2) { + int daysTask1, int daysSubtask1, int daysSubtask2, LocalDate dateConstraintSubtask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task = createTask(START, daysTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - ITaskFundamentalProperties subtask2 = createTaskWithBiggerOrEqualThanConstraint( - START, daysSubtask2, dateConstraintSubtask2); - List listOfTasks = Arrays.asList(task, - subtask1, subtask2); + ITaskFundamentalProperties subtask2 = + createTaskWithBiggerOrEqualThanConstraint(START, daysSubtask2, dateConstraintSubtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + List listOfTasks = Arrays.asList(task, subtask1, subtask2); + + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(task))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays.asList(task))) + + expect(diagramGraphExample.getOutgoingTasksFor(task)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task)).andReturn( - new HashSet(Arrays.asList(subtask1, - subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn(new HashSet<>()).anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1261,50 +1196,49 @@ public class CriticalPathCalculatorTest { private void givenTaskContainerWithOneSubtask(int daysSubtask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer = createTask(START, - daysSubtask1); + ITaskFundamentalProperties taskContainer = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList( - taskContainer, subtask1); + List listOfTasks = Arrays.asList(taskContainer, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer)) + .andReturn(Collections.singletonList(subtask1)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1)).anyTimes(); addTaskMethods(listOfTasks); @@ -1320,71 +1254,71 @@ public class CriticalPathCalculatorTest { * |- #### S2 #### -| * */ - private void givenTaskContainerWithTwoSubtasks(int daysSubtask1, - int daysSubtask2) { + private void givenTaskContainerWithTwoSubtasks(int daysSubtask1, int daysSubtask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer = createTask(START, Math.max( - daysSubtask1, daysSubtask2)); + ITaskFundamentalProperties taskContainer = createTask(START, Math.max(daysSubtask1, daysSubtask2)); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList( - taskContainer, subtask1, subtask2); + List listOfTasks = Arrays.asList(taskContainer, subtask1, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); - IDependency dependencyStartStart2 = createDependency( - taskContainer, subtask2, DependencyType.START_START); + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer, subtask2, DependencyType.START_START); + expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask2)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - subtask2, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask2, taskContainer)) - .andReturn(dependencyEndEnd2).anyTimes(); + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(subtask2, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask2, taskContainer)).andReturn(dependencyEndEnd2).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, subtask2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask2)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1, subtask2)).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask2)).andReturn(true).anyTimes(); + expect(diagramGraphExample.getChildren(taskContainer)).andReturn(Arrays.asList(subtask1, subtask2)).anyTimes(); addTaskMethods(listOfTasks); @@ -1398,61 +1332,59 @@ public class CriticalPathCalculatorTest { * |- #### S1 #### -| * */ - private void givenTaskContainerWithOneSubtaskDependingOnOneTask( - int daysTask1, int daysSubtask1) { + private void givenTaskContainerWithOneSubtaskDependingOnOneTask(int daysTask1, int daysSubtask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); - ITaskFundamentalProperties taskContainer = createTask(START, - daysSubtask1); + ITaskFundamentalProperties taskContainer = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList( - task1, - taskContainer, subtask1); + List listOfTasks = Arrays.asList(task1, taskContainer, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); - - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - task1, subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Arrays.asList(task1, subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer)) + .andReturn(Collections.singletonList(subtask1)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1)).anyTimes(); addTaskMethods(listOfTasks); @@ -1462,12 +1394,10 @@ public class CriticalPathCalculatorTest { @Test public void trivialBaseCase() { givenOneTask(10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); - assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), - equalTo(10)); + assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(10)); } /** @@ -1477,60 +1407,59 @@ public class CriticalPathCalculatorTest { * |- #### S1 #### -| * */ - private void givenOneTaskDependingOnTaskContainerWithOneSubtask( - int daysSubtask1, int daysTask1) { + private void givenOneTaskDependingOnTaskContainerWithOneSubtask(int daysSubtask1, int daysTask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer = createTask(START, - daysSubtask1); + ITaskFundamentalProperties taskContainer = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); ITaskFundamentalProperties task1 = createTask(START, daysTask1); - List listOfTasks = Arrays.asList( - taskContainer, subtask1, task1); + List listOfTasks = Arrays.asList(taskContainer, subtask1, task1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); - - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, task1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, task1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer)) + .andReturn(Collections.singletonList(subtask1)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1)).anyTimes(); addTaskMethods(listOfTasks); @@ -1557,69 +1486,70 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task8 = createTask(START, 8); - List listOfTasks = Arrays.asList( - taskContainer1, task10, task5, task8); + List listOfTasks = Arrays.asList(taskContainer1, task10, task5, task8); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer1, task8)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(taskContainer1, task8)).anyTimes(); + + IDependency dependencyStartStart1 = + createDependency(taskContainer1, task10, DependencyType.START_START); - IDependency dependencyStartStart1 = createDependency( - taskContainer1, task10, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, task10)) - .andReturn(dependencyStartStart1).anyTimes(); - IDependency dependencyEndEnd1 = createDependency( - task10, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)) - .andReturn(dependencyEndEnd1).anyTimes(); - - IDependency dependencyStartStart2 = createDependency( - taskContainer1, task5, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(taskContainer1, task5)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - task5, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)) - .andReturn(dependencyEndEnd2).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + .andReturn(dependencyStartStart1) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task10)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(task10, task5)).anyTimes(); + + IDependency dependencyEndEnd1 = + createDependency(task10, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)).andReturn(dependencyEndEnd1).anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer1, task5, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(taskContainer1, task5)) + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(task5, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)).andReturn(dependencyEndEnd2).anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task10)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn(true).anyTimes(); + expect(diagramGraphExample.getChildren(taskContainer1)).andReturn(Arrays.asList(task10, task5)).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task10, task5))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task5)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task8)).andReturn( - new HashSet(Arrays.asList(task5))) + .andReturn(new HashSet<>(Arrays.asList(task10, task5))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task10)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task8)) + .andReturn(new HashSet<>(Arrays.asList(task5))) .anyTimes(); expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task10, task5))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task5)).andReturn( - new HashSet(Arrays.asList( - taskContainer1, task8))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task8)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task10, task5))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task10)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task5)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, task8))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task8)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1647,68 +1577,69 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task5 = createTask(START, 5); ITaskFundamentalProperties task10 = createTask(START, 10); - List listOfTasks = Arrays.asList(task8, - taskContainer1, task5, task10); + List listOfTasks = Arrays.asList(task8, taskContainer1, task5, task10); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task8, taskContainer1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(task8, taskContainer1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer1, task5, DependencyType.START_START); - IDependency dependencyStartStart2 = createDependency( - taskContainer1, task5, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, task5)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - task5, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)) - .andReturn(dependencyEndEnd2).anyTimes(); - - IDependency dependencyStartStart1 = createDependency( - taskContainer1, task10, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(taskContainer1, task10)) - .andReturn(dependencyStartStart1).anyTimes(); - IDependency dependencyEndEnd1 = createDependency( - task10, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)) - .andReturn(dependencyEndEnd1).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + .andReturn(dependencyStartStart2) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task10)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(task5, task10)).anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(task5, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)).andReturn(dependencyEndEnd2).anyTimes(); + + IDependency dependencyStartStart1 = + createDependency(taskContainer1, task10, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(taskContainer1, task10)) + .andReturn(dependencyStartStart1) + .anyTimes(); + + IDependency dependencyEndEnd1 = + createDependency(task10, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)).andReturn(dependencyEndEnd1).anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task10)).andReturn(true).anyTimes(); + expect(diagramGraphExample.getChildren(taskContainer1)).andReturn(Arrays.asList(task5, task10)).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task5, task10))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task5)).andReturn( - new HashSet(Arrays.asList( - taskContainer1, task8))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task8)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task5, task10))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task5)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, task8))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task10)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task8)).andReturn(new HashSet<>()).anyTimes(); expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task5, task10))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task5)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task8)).andReturn( - new HashSet(Arrays.asList(task5))) + .andReturn(new HashSet<>(Arrays.asList(task5, task10))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task10)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task8)) + .andReturn(new HashSet<>(Collections.singletonList(task5))) .anyTimes(); addTaskMethods(listOfTasks); @@ -1746,118 +1677,124 @@ public class CriticalPathCalculatorTest { ITaskFundamentalProperties task9 = createTask(START, 9); - List listOfTasks = Arrays.asList( - taskContainer1, task10, task5, taskContainer2, task8, task4, - task9); + List listOfTasks = + Arrays.asList(taskContainer1, task10, task5, taskContainer2, task8, task4, task9); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer2, task9)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(taskContainer2, task9)).anyTimes(); + + IDependency dependencyStartStart1 = + createDependency(taskContainer1, task10, DependencyType.START_START); - IDependency dependencyStartStart1 = createDependency( - taskContainer1, task10, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, task10)) - .andReturn(dependencyStartStart1).anyTimes(); - IDependency dependencyEndEnd1 = createDependency( - task10, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)) - .andReturn(dependencyEndEnd1).anyTimes(); + .andReturn(dependencyStartStart1) + .anyTimes(); + + IDependency dependencyEndEnd1 = + createDependency(task10, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task10, taskContainer1)).andReturn(dependencyEndEnd1).anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer1, task5, DependencyType.START_START); - IDependency dependencyStartStart2 = createDependency( - taskContainer1, task5, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, task5)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - task5, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)) - .andReturn(dependencyEndEnd2).anyTimes(); + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(task5, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task5, taskContainer1)).andReturn(dependencyEndEnd2).anyTimes(); + + IDependency dependencyStartStart3 = + createDependency(taskContainer2, task8, DependencyType.START_START); - IDependency dependencyStartStart3 = createDependency( - taskContainer2, task8, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer2, task8)) - .andReturn(dependencyStartStart3).anyTimes(); - IDependency dependencyEndEnd3 = createDependency( - task8, taskContainer2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task8, taskContainer2)) - .andReturn(dependencyEndEnd3).anyTimes(); + .andReturn(dependencyStartStart3) + .anyTimes(); + + IDependency dependencyEndEnd3 = + createDependency(task8, taskContainer2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task8, taskContainer2)).andReturn(dependencyEndEnd3).anyTimes(); + + IDependency dependencyStartStart4 = + createDependency(taskContainer2, task4, DependencyType.START_START); - IDependency dependencyStartStart4 = createDependency( - taskContainer2, task4, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer2, task4)) - .andReturn(dependencyStartStart4).anyTimes(); - IDependency dependencyEndEnd4 = createDependency( - task4, taskContainer2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(task4, taskContainer2)) - .andReturn(dependencyEndEnd4).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + .andReturn(dependencyStartStart4) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task10)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(task10, task5)).anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true) - .anyTimes(); - expect(diagramGraphExample.contains(taskContainer2, task8)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer2, task4)).andReturn( - true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer2)).andReturn( - Arrays.asList(task8, task4)).anyTimes(); + IDependency dependencyEndEnd4 = + createDependency(task4, taskContainer2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(task4, taskContainer2)).andReturn(dependencyEndEnd4).anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task10)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, task5)).andReturn(true).anyTimes(); + expect(diagramGraphExample.getChildren(taskContainer1)).andReturn(Arrays.asList(task10, task5)).anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer2, task8)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer2, task4)).andReturn(true).anyTimes(); + expect(diagramGraphExample.getChildren(taskContainer2)).andReturn(Arrays.asList(task8, task4)).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task10, task5))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task5)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, task8, task4))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task8)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task4)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task10, task5))) + .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task9)).andReturn( - new HashSet(Arrays.asList(task4))) + expect(diagramGraphExample.getIncomingTasksFor(task10)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, task8, task4))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task8)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task4)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task9)) + .andReturn(new HashSet<>(Arrays.asList(task4))) .anyTimes(); expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task10, task5, taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task10)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task5)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task10, task5, taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task10)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task5)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - task8, task4))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task8)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task4)).andReturn( - new HashSet(Arrays.asList( - taskContainer2, task9))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task9)).andReturn( - new HashSet()).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task8, task4))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task8)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task4)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer2, task9))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task9)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -1875,98 +1812,105 @@ public class CriticalPathCalculatorTest { * |- #### S2 #### -| * */ - private void givenTaskContainerWithAnotherContainer(int daysSubtask1, - int daysSubtask2) { + private void givenTaskContainerWithAnotherContainer(int daysSubtask1, int daysSubtask2) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer1 = createTask(START, Math.max( - daysSubtask1, daysSubtask2)); + ITaskFundamentalProperties taskContainer1 = createTask(START, Math.max(daysSubtask1, daysSubtask2)); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - ITaskFundamentalProperties taskContainer2 = createTask(START, - daysSubtask2); + ITaskFundamentalProperties taskContainer2 = createTask(START, daysSubtask2); ITaskFundamentalProperties subtask2 = createTask(START, daysSubtask2); - List listOfTasks = Arrays.asList( - taskContainer1, subtask1, taskContainer2, subtask2); + List listOfTasks = + Arrays.asList(taskContainer1, subtask1, taskContainer2, subtask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer1, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer1, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer1)) - .andReturn(dependencyEndEnd).anyTimes(); + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer1)).andReturn(dependencyEndEnd).anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer1, taskContainer2, DependencyType.START_START); - IDependency dependencyStartStart2 = createDependency( - taskContainer1, taskContainer2, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer1, taskContainer2)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - taskContainer2, taskContainer1, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(taskContainer2, taskContainer1)) - .andReturn(dependencyEndEnd2).anyTimes(); + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(taskContainer2, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(taskContainer2, taskContainer1)) + .andReturn(dependencyEndEnd2) + .anyTimes(); + + IDependency dependencyStartStart3 = + createDependency(taskContainer2, subtask2, DependencyType.START_START); - IDependency dependencyStartStart3 = createDependency( - taskContainer2, subtask2, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer2, subtask2)) - .andReturn(dependencyStartStart3).anyTimes(); - IDependency dependencyEndEnd3 = createDependency( - subtask2, taskContainer2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask2, taskContainer2)) - .andReturn(dependencyEndEnd3).anyTimes(); + .andReturn(dependencyStartStart3) + .anyTimes(); + + IDependency dependencyEndEnd3 = + createDependency(subtask2, taskContainer2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask2, taskContainer2)).andReturn(dependencyEndEnd3).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, taskContainer2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(subtask1, taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask2)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask2)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(subtask1, taskContainer2))) + .anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, taskContainer2)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(subtask1, taskContainer2)).anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true) + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask2)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, subtask1)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer1, taskContainer2)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer1)) + .andReturn(Arrays.asList(subtask1, taskContainer2)) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer2, subtask2)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer2)) + .andReturn(Collections.singletonList(subtask2)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer2, subtask2)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer2)).andReturn( - Arrays.asList(subtask2)).anyTimes(); addTaskMethods(listOfTasks); @@ -1986,61 +1930,62 @@ public class CriticalPathCalculatorTest { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); - ITaskFundamentalProperties taskContainer = createTask(START, - daysSubTask1); + ITaskFundamentalProperties taskContainer = createTask(START, daysSubTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubTask1); - List listOfTasks = Arrays.asList(task1, - taskContainer, subtask1); + List listOfTasks = Arrays.asList(task1, taskContainer, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task1, taskContainer)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Arrays.asList(task1, taskContainer)).anyTimes(); + + IDependency dependencyStartStartTaskContainer = + createDependency(task1, taskContainer, DependencyType.START_START); - IDependency dependencyStartStartTaskContainer = createDependency( - task1, taskContainer, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(task1, taskContainer)) - .andReturn(dependencyStartStartTaskContainer).anyTimes(); + .andReturn(dependencyStartStartTaskContainer) + .anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - task1, subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))) + .andReturn(new HashSet<>(Arrays.asList(task1, subtask1))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer)) + .andReturn(Collections.singletonList(subtask1)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1)).anyTimes(); addTaskMethods(listOfTasks); @@ -2059,61 +2004,63 @@ public class CriticalPathCalculatorTest { private void givenEndEndContainerExample(int daysSubTask1, int daysTask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer = createTask(START, - daysSubTask1); + ITaskFundamentalProperties taskContainer = createTask(START, daysSubTask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubTask1); ITaskFundamentalProperties task1 = createTask(START, daysTask1); - List listOfTasks = Arrays.asList( - taskContainer, subtask1, task1); + List listOfTasks = Arrays.asList(taskContainer, subtask1, task1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer, task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Arrays.asList(taskContainer, task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + + IDependency dependencyEndEndContainerTask = + createDependency(taskContainer, task1, DependencyType.END_END); - IDependency dependencyEndEndContainerTask = createDependency( - taskContainer, task1, DependencyType.END_END); expect(diagramGraphExample.getDependencyFrom(taskContainer, task1)) - .andReturn(dependencyEndEndContainerTask).anyTimes(); - - IDependency dependencyStartStart = createDependency( - taskContainer, subtask1, DependencyType.START_START); - expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) - .andReturn(dependencyStartStart).anyTimes(); - IDependency dependencyEndEnd = createDependency( - subtask1, taskContainer, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)) - .andReturn(dependencyEndEnd).anyTimes(); - - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays - .asList(subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) - .andReturn( - new HashSet(Arrays.asList( - subtask1, task1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer))).anyTimes(); - - expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true) + .andReturn(dependencyEndEndContainerTask) + .anyTimes(); + + IDependency dependencyStartStart = + createDependency(taskContainer, subtask1, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(taskContainer, subtask1)) + .andReturn(dependencyStartStart) + .anyTimes(); + + IDependency dependencyEndEnd = + createDependency(subtask1, taskContainer, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer)).andReturn(dependencyEndEnd).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Collections.singletonList(subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer)) + .andReturn(new HashSet<>(Arrays.asList(subtask1, task1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer)).andReturn(true).anyTimes(); + expect(diagramGraphExample.contains(taskContainer, subtask1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer)) + .andReturn(Collections.singletonList(subtask1)) .anyTimes(); - expect(diagramGraphExample.contains(taskContainer, subtask1)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer)).andReturn( - Arrays.asList(subtask1)).anyTimes(); addTaskMethods(listOfTasks); @@ -2132,77 +2079,80 @@ public class CriticalPathCalculatorTest { private void givenTaskContainerWithContainerWithSubtask(int daysSubtask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties taskContainer1 = createTask(START, - daysSubtask1); - ITaskFundamentalProperties taskContainer2 = createTask(START, - daysSubtask1); + ITaskFundamentalProperties taskContainer1 = createTask(START, daysSubtask1); + ITaskFundamentalProperties taskContainer2 = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList( - taskContainer1, taskContainer2, subtask1); + List listOfTasks = Arrays.asList(taskContainer1, taskContainer2, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); - IDependency dependencyStartStart1 = createDependency( - taskContainer1, taskContainer2, DependencyType.START_START); - expect( - diagramGraphExample.getDependencyFrom(taskContainer1, - taskContainer2)).andReturn(dependencyStartStart1) + IDependency dependencyStartStart1 = + createDependency(taskContainer1, taskContainer2, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(taskContainer1, taskContainer2)) + .andReturn(dependencyStartStart1) .anyTimes(); - IDependency dependencyEndEnd1 = createDependency( - taskContainer2, taskContainer1, DependencyType.END_END); - expect( - diagramGraphExample.getDependencyFrom(taskContainer2, - taskContainer1)).andReturn(dependencyEndEnd1).anyTimes(); - IDependency dependencyStartStart2 = createDependency( - taskContainer2, subtask1, DependencyType.START_START); + + IDependency dependencyEndEnd1 = + createDependency(taskContainer2, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(taskContainer2, taskContainer1)) + .andReturn(dependencyEndEnd1) + .anyTimes(); + + IDependency dependencyStartStart2 = + createDependency(taskContainer2, subtask1, DependencyType.START_START); + expect(diagramGraphExample.getDependencyFrom(taskContainer2, subtask1)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - subtask1, taskContainer2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer2)) - .andReturn(dependencyEndEnd2).anyTimes(); + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(subtask1, taskContainer2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer2)).andReturn(dependencyEndEnd2).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask1))) .anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(taskContainer2)).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, taskContainer2)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true) + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) .anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer2)).andReturn( - Arrays.asList(subtask1)).anyTimes(); - expect(diagramGraphExample.contains(taskContainer2, subtask1)) - .andReturn(true).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer1)) + .andReturn(Collections.singletonList(taskContainer2)) + .anyTimes(); + + expect(diagramGraphExample.contains(taskContainer1, taskContainer2)).andReturn(true).anyTimes(); + expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer2)) + .andReturn(Collections.singletonList(subtask1)) + .anyTimes(); + + expect(diagramGraphExample.contains(taskContainer2, subtask1)).andReturn(true).anyTimes(); addTaskMethods(listOfTasks); @@ -2218,88 +2168,90 @@ public class CriticalPathCalculatorTest { * |- #### S2 #### -| * */ - private void givenExampleContainersWithContainers(int daysTask1, - int daysSubtask1) { + private void givenExampleContainersWithContainers(int daysTask1, int daysSubtask1) { diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); ITaskFundamentalProperties task1 = createTask(START, daysTask1); - ITaskFundamentalProperties taskContainer1 = createTask(START, - daysSubtask1); - ITaskFundamentalProperties taskContainer2 = createTask(START, - daysSubtask1); + ITaskFundamentalProperties taskContainer1 = createTask(START, daysSubtask1); + ITaskFundamentalProperties taskContainer2 = createTask(START, daysSubtask1); ITaskFundamentalProperties subtask1 = createTask(START, daysSubtask1); - List listOfTasks = Arrays.asList(task1, - taskContainer1, taskContainer2, subtask1); + List listOfTasks = Arrays.asList(task1, taskContainer1, taskContainer2, subtask1); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) - .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(taskContainer1)).anyTimes(); + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(taskContainer1)).anyTimes(); - IDependency dependencyStartStart1 = createDependency( - taskContainer1, taskContainer2, DependencyType.START_START); - expect( - diagramGraphExample.getDependencyFrom(taskContainer1, - taskContainer2)).andReturn(dependencyStartStart1) + IDependency dependencyStartStart1 = + createDependency(taskContainer1, taskContainer2, DependencyType.START_START); + + expect(diagramGraphExample.getDependencyFrom(taskContainer1, taskContainer2)) + .andReturn(dependencyStartStart1) .anyTimes(); - IDependency dependencyEndEnd1 = createDependency( - taskContainer2, taskContainer1, DependencyType.END_END); - expect( - diagramGraphExample.getDependencyFrom(taskContainer2, - taskContainer1)).andReturn(dependencyEndEnd1) + + IDependency dependencyEndEnd1 = + createDependency(taskContainer2, taskContainer1, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(taskContainer2, taskContainer1)) + .andReturn(dependencyEndEnd1) .anyTimes(); - IDependency dependencyStartStart2 = createDependency( - taskContainer2, subtask1, DependencyType.START_START); + + IDependency dependencyStartStart2 = + createDependency(taskContainer2, subtask1, DependencyType.START_START); + expect(diagramGraphExample.getDependencyFrom(taskContainer2, subtask1)) - .andReturn(dependencyStartStart2).anyTimes(); - IDependency dependencyEndEnd2 = createDependency( - subtask1, taskContainer2, DependencyType.END_END); - expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer2)) - .andReturn(dependencyEndEnd2).anyTimes(); + .andReturn(dependencyStartStart2) + .anyTimes(); + + IDependency dependencyEndEnd2 = + createDependency(subtask1, taskContainer2, DependencyType.END_END); + + expect(diagramGraphExample.getDependencyFrom(subtask1, taskContainer2)).andReturn(dependencyEndEnd2).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); expect(diagramGraphExample.getIncomingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays.asList( - task1, taskContainer2))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask1))).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays - .asList(taskContainer1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) - .andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) - .andReturn( - new HashSet(Arrays.asList( - taskContainer1, subtask1))).anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(subtask1)).andReturn( - new HashSet(Arrays - .asList(taskContainer2))).anyTimes(); + .andReturn(new HashSet<>(Arrays.asList(task1, taskContainer2))) + .anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true) + expect(diagramGraphExample.getIncomingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask1))) .anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer1)).andReturn( - Arrays.asList(taskContainer2)).anyTimes(); - expect(diagramGraphExample.contains(taskContainer1, taskContainer2)) - .andReturn(true).anyTimes(); - expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true) + + expect(diagramGraphExample.getIncomingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) .anyTimes(); - expect(diagramGraphExample.getChildren(taskContainer2)).andReturn( - Arrays.asList(subtask1)).anyTimes(); - expect(diagramGraphExample.contains(taskContainer2, subtask1)) - .andReturn(true).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(taskContainer2)) + .andReturn(new HashSet<>(Arrays.asList(taskContainer1, subtask1))) + .anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(subtask1)) + .andReturn(new HashSet<>(Collections.singletonList(taskContainer2))) + .anyTimes(); + + expect(diagramGraphExample.isContainer(taskContainer1)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer1)) + .andReturn(Collections.singletonList(taskContainer2)) + .anyTimes(); + + expect(diagramGraphExample.contains(taskContainer1, taskContainer2)).andReturn(true).anyTimes(); + expect(diagramGraphExample.isContainer(taskContainer2)).andReturn(true).anyTimes(); + + expect(diagramGraphExample.getChildren(taskContainer2)) + .andReturn(Collections.singletonList(subtask1)) + .anyTimes(); + + expect(diagramGraphExample.contains(taskContainer2, subtask1)).andReturn(true).anyTimes(); addTaskMethods(listOfTasks); @@ -2309,8 +2261,7 @@ public class CriticalPathCalculatorTest { @Test public void trivialBaseCaseWithTwoTasksNotConnected() { givenTwoTasksNotConnected(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(10)); @@ -2319,60 +2270,55 @@ public class CriticalPathCalculatorTest { @Test public void pairOfTasks() { givenPairOfTasks(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(10), equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); } } @Test public void twoPairOfTasksNotConnected() { givenTwoPairOfTasksNotConnected(10, 5, 6, 4); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(10), equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); } } @Test public void twoPairOfTasksNotConnected2() { givenTwoPairOfTasksNotConnected(8, 1, 6, 4); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(6), equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } @Test public void twoTaskConnectedAndOneIndependentTask() { givenTwoTaskConnectedAndOneIndependentTask(5, 10, 12); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(10))); } } @Test public void twoTaskConnectedAndOneIndependentTask2() { givenTwoTaskConnectedAndOneIndependentTask(5, 10, 20); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(20)); @@ -2381,8 +2327,7 @@ public class CriticalPathCalculatorTest { @Test public void twoTaskConnectedAndOneIndependentTaskWithTheSameDuration() { givenTwoTaskConnectedAndOneIndependentTask(10, 10, 20); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); } @@ -2390,36 +2335,34 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskWithTwoDependantTasks() { givenOneTaskWithTwoDependantTasks(4, 5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(10))); } } @Test public void oneTaskWithTwoDependantTasks2() { givenOneTaskWithTwoDependantTasks(4, 5, 1); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(5))); } } @Test public void twoTaskWithOneCommonDependantTask() { givenTwoTaskWithOneCommonDependantTask(4, 2, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(5))); } @@ -2428,10 +2371,10 @@ public class CriticalPathCalculatorTest { @Test public void twoTaskWithOneCommonDependantTask2() { givenTwoTaskWithOneCommonDependantTask(4, 10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(10))); } @@ -2440,10 +2383,10 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskWithTwoDependantTasksAndOneCommonDependantTask() { givenOneTaskWithTwoDependantTasksAndOneCommonDependantTask(4, 2, 5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(5), equalTo(10))); } @@ -2451,12 +2394,11 @@ public class CriticalPathCalculatorTest { @Test public void twoTaskWithOneCommonDependantTaskWithTwoDependantTasks() { - givenTwoTaskWithOneCommonDependantTaskWithTwoDependantTasks(2, 6, 4, 8, - 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenTwoTaskWithOneCommonDependantTaskWithTwoDependantTasks(2, 6, 4, 8, 10); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4), equalTo(10))); } @@ -2464,12 +2406,11 @@ public class CriticalPathCalculatorTest { @Test public void twoTaskWithOneCommonDependantTaskWithTwoDependantTasks2() { - givenTwoTaskWithOneCommonDependantTaskWithTwoDependantTasks(4, 2, 10, - 8, 6); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenTwoTaskWithOneCommonDependantTaskWithTwoDependantTasks(4, 2, 10, 8, 6); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(10), equalTo(8))); } @@ -2478,10 +2419,10 @@ public class CriticalPathCalculatorTest { @Test public void example() { givenExample(20); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(20))); } @@ -2490,10 +2431,10 @@ public class CriticalPathCalculatorTest { @Test public void example2() { givenExample(10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(4)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(8), equalTo(3), equalTo(10))); } @@ -2502,36 +2443,33 @@ public class CriticalPathCalculatorTest { @Test public void example3() { givenExample(19); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(6)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat( daysBetweenStartAndEnd(task), - anyOf(equalTo(4), equalTo(8), equalTo(3), equalTo(10), - equalTo(6), equalTo(19))); + anyOf(equalTo(4), equalTo(8), equalTo(3), equalTo(10), equalTo(6), equalTo(19))); } } @Test public void pairOfTasksStartStart() { givenPairOfTasksStartStart(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(10))); } } @Test public void pairOfTasksStartStart2() { givenPairOfTasksStartStart(8, 4); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(8)); @@ -2540,10 +2478,10 @@ public class CriticalPathCalculatorTest { @Test public void pairOfTasksStartStart3() { givenPairOfTasksStartStart(5, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(5)); } @@ -2552,132 +2490,115 @@ public class CriticalPathCalculatorTest { @Test public void pairOfTasksStartStartFirstOfThemWithOneSubtask() { givenPairOfTasksStartStartFirstOfThemWithOneSubtask(4, 6, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), - equalTo(6))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(6))); } } @Test public void pairOfTasksStartStartFirstOfThemWithOneSubtask2() { givenPairOfTasksStartStartFirstOfThemWithOneSubtask(4, 6, 15); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), - equalTo(15))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(15))); } } @Test public void twoTasksWithSubtasksRelatedWithStartStart() { givenTwoTasksWithSubtasksRelatedWithStartStart(4, 3, 5, 6); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), equalTo(6))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(6))); } } @Test public void twoTasksWithSubtasksRelatedWithStartStart2() { givenTwoTasksWithSubtasksRelatedWithStartStart(2, 10, 4, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(2), - equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(2), equalTo(10))); } } @Test public void twoTasksWithSubtasksRelatedWithStartStart3() { givenTwoTasksWithSubtasksRelatedWithStartStart(4, 7, 5, 6); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(4)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), - equalTo(7), equalTo(5), equalTo(6))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(7), equalTo(5), equalTo(6))); } } @Test public void exampleStartStart() { givenExampleStartStart(5, 3, 10, 2); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(10))); } } @Test public void exampleStartStart2() { givenExampleStartStart(5, 3, 4, 8); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(4), equalTo(8))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(4), equalTo(8))); } } @Test public void exampleStartStart3() { givenExampleStartStart(5, 8, 4, 2); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(8))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(8))); } } @Test public void pairOfTasksEndEnd() { givenPairOfTasksEndEnd(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(10), - equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); } } @Test public void pairOfTasksEndEnd2() { givenPairOfTasksEndEnd(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(10)); @@ -2686,22 +2607,19 @@ public class CriticalPathCalculatorTest { @Test public void pairOfTasksEndEndFirstOfThemWithOneSubtask() { givenPairOfTasksEndEndFirstOfThemWithOneSubtask(4, 3, 2); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), - equalTo(3))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(3))); } } @Test public void pairOfTasksEndEndFirstOfThemWithOneSubtask2() { givenPairOfTasksEndEndFirstOfThemWithOneSubtask(2, 3, 6); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(6)); @@ -2710,64 +2628,55 @@ public class CriticalPathCalculatorTest { @Test public void twoTasksWithSubtasksRelatedWithEndEnd() { givenTwoTasksWithSubtasksRelatedWithEndEnd(5, 3, 4, 2); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(3), equalTo(2))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(3), equalTo(2))); } } @Test public void twoTasksWithSubtasksRelatedWithEndEnd2() { givenTwoTasksWithSubtasksRelatedWithEndEnd(5, 2, 4, 6); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(4), - equalTo(6))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(4), equalTo(6))); } } @Test public void exampleEndEnd() { givenExampleEndEnd(5, 4, 2, 3); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(4))); } } @Test public void exampleEndEnd2() { givenExampleEndEnd(5, 2, 4, 3); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(5), - equalTo(4), equalTo(3))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(4), equalTo(3))); } } @Test public void exampleEndEnd3() { givenExampleEndEnd(2, 4, 3, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(10)); @@ -2775,10 +2684,8 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskWithTwoDependantTasksLastOneWithEqualConstraint() { - givenOneTaskWithTwoDependantTasksLastOneWithEqualConstraint(2, 5, 3, - START.plusDays(5)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenOneTaskWithTwoDependantTasksLastOneWithEqualConstraint(2, 5, 3, START.plusDays(5)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(3)); @@ -2786,25 +2693,20 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskWithTwoDependantTasksLastOneWithEqualConstraint2() { - givenOneTaskWithTwoDependantTasksLastOneWithEqualConstraint(2, 5, 3, - START.plusDays(4)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenOneTaskWithTwoDependantTasksLastOneWithEqualConstraint(2, 5, 3, START.plusDays(4)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(2), - equalTo(5), equalTo(3))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(2), equalTo(5), equalTo(3))); } } @Test public void oneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint() { - givenOneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint( - 2, 5, 3, START.plusDays(5)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenOneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint(2, 5, 3, START.plusDays(5)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(3)); @@ -2812,29 +2714,25 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint2() { - givenOneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint( - 2, 6, 4, START.plusDays(3)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenOneTaskWithTwoDependantTasksLastOneWithBiggerOrEqualThanConstraint(2, 6, 4, START.plusDays(3)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(2), - equalTo(6))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(2), equalTo(6))); } } @Test public void taskContainerWithOneSubtask() { givenTaskContainerWithOneSubtask(10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - equalTo(10)); + assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2842,13 +2740,12 @@ public class CriticalPathCalculatorTest { @Test public void taskContainerWithTwoSubtasks() { givenTaskContainerWithTwoSubtasks(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - equalTo(10)); + assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2856,14 +2753,12 @@ public class CriticalPathCalculatorTest { @Test public void taskContainerWithOneSubtaskDependingOnOneTask() { givenTaskContainerWithOneSubtaskDependingOnOneTask(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(10), - equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2871,13 +2766,12 @@ public class CriticalPathCalculatorTest { @Test public void oneTaskDependingOnTaskContainerWithOneSubtask() { givenOneTaskDependingOnTaskContainerWithOneSubtask(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), - anyOf(equalTo(10), equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2885,13 +2779,12 @@ public class CriticalPathCalculatorTest { @Test public void exampleWithContainers() { givenExampleWithContainers(); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), - equalTo(8))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(8))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2899,13 +2792,12 @@ public class CriticalPathCalculatorTest { @Test public void anotherExampleWithContiners() { givenAnotherWithContainers(); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(8), - equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(8), equalTo(5))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2913,13 +2805,12 @@ public class CriticalPathCalculatorTest { @Test public void complexExample() { givenComplexExample(); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(3)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), - equalTo(4), equalTo(9))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(4), equalTo(9))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2927,10 +2818,10 @@ public class CriticalPathCalculatorTest { @Test public void taskContainerWithAnotherContainer() { givenTaskContainerWithAnotherContainer(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); @@ -2940,10 +2831,10 @@ public class CriticalPathCalculatorTest { @Test public void taskContainerWithAnotherContainer2() { givenTaskContainerWithAnotherContainer(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); @@ -2953,10 +2844,10 @@ public class CriticalPathCalculatorTest { @Test public void startStartContainerExample() { givenStartStartContainerExample(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); @@ -2966,13 +2857,12 @@ public class CriticalPathCalculatorTest { @Test public void startStartContainerExample2() { givenStartStartContainerExample(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), - equalTo(10))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(5), equalTo(10))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -2980,23 +2870,22 @@ public class CriticalPathCalculatorTest { @Test public void endEndContainerExample() { givenEndEndContainerExample(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), - equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); } } @Test public void endEndContainerExample2() { givenEndEndContainerExample(5, 10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); @@ -3006,10 +2895,10 @@ public class CriticalPathCalculatorTest { @Test public void taskContainerWithContainerWithSubtask() { givenTaskContainerWithContainerWithSubtask(10); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); + for (ITaskFundamentalProperties task : criticalPath) { assertThat(daysBetweenStartAndEnd(task), equalTo(10)); assertFalse(diagramGraphExample.isContainer(task)); @@ -3019,13 +2908,12 @@ public class CriticalPathCalculatorTest { @Test public void exampleContainersWithContainers() { givenExampleContainersWithContainers(10, 5); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), - equalTo(5))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(10), equalTo(5))); assertFalse(diagramGraphExample.isContainer(task)); } } @@ -3037,39 +2925,40 @@ public class CriticalPathCalculatorTest { * */ private void givenPairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint( - int daysTask1, LocalDate dateBiggerOrEqualConstraintTask1, - int daysTask2, LocalDate dateEqualConstraintTask2) { + int daysTask1, + LocalDate dateBiggerOrEqualConstraintTask1, + int daysTask2, + LocalDate dateEqualConstraintTask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties task1 = createTaskWithBiggerOrEqualThanConstraint( - START, daysTask1, dateBiggerOrEqualConstraintTask1); - ITaskFundamentalProperties task2 = createTaskWithEqualConstraint(START, - daysTask2, dateEqualConstraintTask2); + ITaskFundamentalProperties task1 = + createTaskWithBiggerOrEqualThanConstraint(START, daysTask1, dateBiggerOrEqualConstraintTask1); - List listOfTasks = Arrays.asList(task1, - task2); + ITaskFundamentalProperties task2 = createTaskWithEqualConstraint(START, daysTask2, dateEqualConstraintTask2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + List listOfTasks = Arrays.asList(task1, task2); + + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(task2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(task2))) - .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -3080,13 +2969,13 @@ public class CriticalPathCalculatorTest { public void examplePairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint1() { givenPairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint( 6, START.plusDays(2), 4, START); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } @@ -3094,13 +2983,13 @@ public class CriticalPathCalculatorTest { public void examplePairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint2() { givenPairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint( 6, START, 4, START.plusDays(5)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } @@ -3108,8 +2997,8 @@ public class CriticalPathCalculatorTest { public void examplePairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint3() { givenPairOfTasksWithDependencyFirstWithBiggerConstraintAndSecondWithEqualConstraint( 6, START, 4, START.plusDays(10)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(1)); assertThat(daysBetweenStartAndEnd(criticalPath.get(0)), equalTo(4)); @@ -3122,39 +3011,35 @@ public class CriticalPathCalculatorTest { * */ private void givenPairOfTasksWithDependencyBothWithEqualConstraint( - int daysTask1, LocalDate dateEqualConstraintTask1, int daysTask2, - LocalDate dateEqualConstraintTask2) { + int daysTask1, LocalDate dateEqualConstraintTask1, int daysTask2, LocalDate dateEqualConstraintTask2) { + diagramGraphExample = createNiceMock(ICriticalPathCalculable.class); - ITaskFundamentalProperties task1 = createTaskWithEqualConstraint( - START, daysTask1, dateEqualConstraintTask1); - ITaskFundamentalProperties task2 = createTaskWithEqualConstraint(START, - daysTask2, dateEqualConstraintTask2); + ITaskFundamentalProperties task1 = createTaskWithEqualConstraint(START, daysTask1, dateEqualConstraintTask1); + ITaskFundamentalProperties task2 = createTaskWithEqualConstraint(START, daysTask2, dateEqualConstraintTask2); - List listOfTasks = Arrays.asList(task1, - task2); + List listOfTasks = Arrays.asList(task1, task2); - expect(diagramGraphExample.getTasks()).andReturn(listOfTasks) + expect(diagramGraphExample.getTasks()).andReturn(listOfTasks).anyTimes(); + expect(diagramGraphExample.getInitialTasks()).andReturn(Collections.singletonList(task1)).anyTimes(); + expect(diagramGraphExample.getLatestTasks()).andReturn(Collections.singletonList(task2)).anyTimes(); + + expect(diagramGraphExample.getDependencyFrom( + isA(ITaskFundamentalProperties.class), + isA(ITaskFundamentalProperties.class))).andReturn(null) .anyTimes(); - expect(diagramGraphExample.getInitialTasks()).andReturn( - Arrays.asList(task1)).anyTimes(); - expect(diagramGraphExample.getLatestTasks()).andReturn( - Arrays.asList(task2)).anyTimes(); - expect( - diagramGraphExample.getDependencyFrom( - isA(ITaskFundamentalProperties.class), - isA(ITaskFundamentalProperties.class))).andReturn(null) + + expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn(new HashSet<>()).anyTimes(); + + expect(diagramGraphExample.getIncomingTasksFor(task2)) + .andReturn(new HashSet<>(Collections.singletonList(task1))) .anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task1)).andReturn( - new HashSet()).anyTimes(); - expect(diagramGraphExample.getIncomingTasksFor(task2)).andReturn( - new HashSet(Arrays.asList(task1))) + + expect(diagramGraphExample.getOutgoingTasksFor(task1)) + .andReturn(new HashSet<>(Collections.singletonList(task2))) .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task1)).andReturn( - new HashSet(Arrays.asList(task2))) - .anyTimes(); - expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn( - new HashSet()).anyTimes(); + + expect(diagramGraphExample.getOutgoingTasksFor(task2)).andReturn(new HashSet<>()).anyTimes(); addTaskMethods(listOfTasks); @@ -3163,43 +3048,37 @@ public class CriticalPathCalculatorTest { @Test public void examplePairOfTasksWithDependencyBothWithEqualConstraint1() { - givenPairOfTasksWithDependencyBothWithEqualConstraint( - 6, START.plusDays(2), 4, START); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenPairOfTasksWithDependencyBothWithEqualConstraint(6, START.plusDays(2), 4, START); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } @Test public void examplePairOfTasksWithDependencyBothWithEqualConstraint2() { - givenPairOfTasksWithDependencyBothWithEqualConstraint( - 6, START, 4, START.plusDays(5)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenPairOfTasksWithDependencyBothWithEqualConstraint(6, START, 4, START.plusDays(5)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } @Test public void examplePairOfTasksWithDependencyBothWithEqualConstraint3() { - givenPairOfTasksWithDependencyBothWithEqualConstraint( - 6, START, 4, START.plusDays(10)); - List criticalPath = buildCalculator() - .calculateCriticalPath(diagramGraphExample); + givenPairOfTasksWithDependencyBothWithEqualConstraint(6, START, 4, START.plusDays(10)); + List criticalPath = buildCalculator().calculateCriticalPath(diagramGraphExample); assertThat(criticalPath.size(), equalTo(2)); + for (ITaskFundamentalProperties task : criticalPath) { - assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), - equalTo(4))); + assertThat(daysBetweenStartAndEnd(task), anyOf(equalTo(6), equalTo(4))); } } diff --git a/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java b/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java index 4eb7b72fc..e857cbd3d 100644 --- a/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java +++ b/ganttzk/src/test/java/org/zkoss/ganttz/timetracker/OnColumnsRowRendererTest.java @@ -69,8 +69,6 @@ public class OnColumnsRowRendererTest { private OnColumnsRowRenderer rowRenderer; - private DateTime start; - private List data; private void givenOnDetailItemsRowRenderer(ICellForDetailItemRenderer cellRenderer) { @@ -82,7 +80,7 @@ public class OnColumnsRowRendererTest { private void givenDetailItems() { detailItems = new ArrayList<>(); - start = new LocalDate(2010, 1, 1).toDateTimeAtStartOfDay().toDateTime(); + DateTime start = new LocalDate(2010, 1, 1).toDateTimeAtStartOfDay().toDateTime(); DateTime current = start; Period period = Period.months(2); @@ -107,32 +105,32 @@ public class OnColumnsRowRendererTest { @Test(expected = NullPointerException.class) public void itNeedsNotNullCellRenderer() { - OnColumnsRowRenderer.create(Data.class, null, new ArrayList()); + OnColumnsRowRenderer.create(Data.class, null, new ArrayList<>()); } @Test(expected = NullPointerException.class) public void itNeedsTheTypeAsClass() { - OnColumnsRowRenderer.create(null, createStub(), new ArrayList()); + OnColumnsRowRenderer.create(null, createStub(), new ArrayList<>()); } @Test public void itCanHaveEmptyDetailItems() { - OnColumnsRowRenderer.create(Data.class, createStub(), new ArrayList()); + OnColumnsRowRenderer.create(Data.class, createStub(), new ArrayList<>()); } @Test public void itCanInferTheGenericType() { - OnColumnsRowRenderer.create(new CellRenderer(), new ArrayList()); + OnColumnsRowRenderer.create(new CellRenderer(), new ArrayList<>()); } @Test(expected = IllegalArgumentException.class) public void ifComesFromRawTypeIsNotInferrable() { - OnColumnsRowRenderer.create(createStub(), new ArrayList()); + OnColumnsRowRenderer.create(createStub(), new ArrayList<>()); } @Test(expected = IllegalArgumentException.class) public void ifItNotShowsTheActualTypeIsNotInferrable() { - OnColumnsRowRenderer.create(new CellRendererNotInferable(), new ArrayList()); + OnColumnsRowRenderer.create(new CellRendererNotInferable<>(), new ArrayList<>()); } @SuppressWarnings("serial") diff --git a/ganttzk/src/test/java/org/zkoss/ganttz/util/MutableTreeModelTest.java b/ganttzk/src/test/java/org/zkoss/ganttz/util/MutableTreeModelTest.java index 60404fd15..be6f481f3 100644 --- a/ganttzk/src/test/java/org/zkoss/ganttz/util/MutableTreeModelTest.java +++ b/ganttzk/src/test/java/org/zkoss/ganttz/util/MutableTreeModelTest.java @@ -38,7 +38,6 @@ import org.junit.Test; import org.zkoss.ganttz.util.MutableTreeModel.IChildrenExtractor; import org.zkoss.zul.TreeModel; import org.zkoss.zul.event.TreeDataEvent; -import org.zkoss.zul.event.TreeDataListener; /** * @author Óscar González Fernández @@ -215,12 +214,7 @@ public class MutableTreeModelTest { MutableTreeModel model = MutableTreeModel.create(Prueba.class); final ArrayList eventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - eventsFired.add(event); - } - }); + model.addTreeDataListener(event -> eventsFired.add(event)); Prueba child1 = new Prueba(); Prueba child2 = new Prueba(); @@ -240,12 +234,7 @@ public class MutableTreeModelTest { MutableTreeModel model = MutableTreeModel.create(Prueba.class); final ArrayList eventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - eventsFired.add(event); - } - }); + model.addTreeDataListener(event -> eventsFired.add(event)); Prueba child1 = new Prueba(); Prueba child2 = new Prueba(); @@ -278,12 +267,7 @@ public class MutableTreeModelTest { model.add(model.getRoot(), p1); final ArrayList eventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - eventsFired.add(event); - } - }); + model.addTreeDataListener(event -> eventsFired.add(event)); model.add(model.getRoot(), 0, Arrays.asList(new Prueba(), new Prueba())); TreeDataEvent event = getLast(eventsFired); @@ -305,14 +289,9 @@ public class MutableTreeModelTest { MutableTreeModel model = MutableTreeModel.create(Prueba.class); final List events = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - events.add(event); - } - }); + model.addTreeDataListener(event -> events.add(event)); - model.add(model.getRoot(), new ArrayList()); + model.add(model.getRoot(), new ArrayList<>()); assertThat(events.size(), equalTo(0)); } @@ -330,14 +309,11 @@ public class MutableTreeModelTest { } private IChildrenExtractor childrenFor(final Prueba parent, final Prueba... children) { - return new IChildrenExtractor() { - @Override - public List getChildren(Prueba p) { - if ( parent == p ) { - return Arrays.asList(children); - } else { - return Collections.emptyList(); - } + return p -> { + if ( parent == p ) { + return Arrays.asList(children); + } else { + return Collections.emptyList(); } }; } @@ -350,12 +326,7 @@ public class MutableTreeModelTest { final Prueba child2 = new Prueba(); final List eventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - eventsFired.add(event); - } - }); + model.addTreeDataListener(event -> eventsFired.add(event)); model.add(model.getRoot(), Collections.singletonList(newlyAdded), childrenFor(newlyAdded, child1, child2)); @@ -396,12 +367,9 @@ public class MutableTreeModelTest { final MutableTreeModel model = MutableTreeModel.create(Prueba.class); final List removeEventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - if ( event.getType() == TreeDataEvent.INTERVAL_REMOVED ) { - removeEventsFired.add(event); - } + model.addTreeDataListener(event -> { + if ( event.getType() == TreeDataEvent.INTERVAL_REMOVED ) { + removeEventsFired.add(event); } }); @@ -506,12 +474,7 @@ public class MutableTreeModelTest { model.addToRoot(prueba3); final ArrayList eventsFired = new ArrayList<>(); - model.addTreeDataListener(new TreeDataListener() { - @Override - public void onChange(TreeDataEvent event) { - eventsFired.add(event); - } - }); + model.addTreeDataListener(event -> eventsFired.add(event)); model.up(prueba2); checkIsValid(getPreviousToLast(eventsFired), TreeDataEvent.INTERVAL_REMOVED, model.getRoot(), 0, 1); diff --git a/libreplan-business/pom.xml b/libreplan-business/pom.xml index 469c06819..552d89864 100644 --- a/libreplan-business/pom.xml +++ b/libreplan-business/pom.xml @@ -38,6 +38,12 @@ hibernate-validator + + + javax.el + javax.el-api + + org.jadira.usertype @@ -103,6 +109,12 @@ commons-math3 + + + org.apache.commons + commons-lang3 + + org.slf4j @@ -130,25 +142,22 @@ org.liquibase liquibase-maven-plugin - - org.apache.commons - commons-lang3 - + - + - liquibase-update - - true - - - - - org.liquibase - liquibase-maven-plugin + liquibase-update + + true + + + + + org.liquibase + liquibase-maven-plugin 3.5.1 @@ -162,22 +171,22 @@ - - - - - + + + + + - liquibase-updatesql - - false - - - - - org.liquibase - liquibase-maven-plugin + liquibase-updatesql + + false + + + + + org.liquibase + liquibase-maven-plugin 3.5.1 @@ -191,14 +200,14 @@ - - - - + + + + + - @@ -206,6 +215,5 @@ true - diff --git a/libreplan-business/src/main/java/org/libreplan/business/BootstrapOrder.java b/libreplan-business/src/main/java/org/libreplan/business/BootstrapOrder.java index 757d90302..74e3f3aa9 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/BootstrapOrder.java +++ b/libreplan-business/src/main/java/org/libreplan/business/BootstrapOrder.java @@ -29,12 +29,11 @@ import java.lang.annotation.Target; /** *

- * It can be applied to a {@link IDataBootstrap} to indicate the order in which - * it will be executed. It's ensured that if a data bootstrap has a priority - * value greater than another one it will be executed before. If two data - * bootstraps have the same priority value the order is unspecified. If a data - * bootstrap doesn't have this annotation it's like it would have a value of - * zero. + * It can be applied to a {@link IDataBootstrap} to indicate the order in which it will be executed. + * It's ensured that if a data bootstrap has a priority value greater than another one it will be executed before. + * + * If two data bootstraps have the same priority value the order is unspecified. + * If a data bootstrap doesn't have this annotation it's like it would have a value of zero. *

* * It accepts negative values. @@ -46,5 +45,5 @@ import java.lang.annotation.Target; @Target(ElementType.TYPE) @Retention(RetentionPolicy.RUNTIME) public @interface BootstrapOrder { - public int value(); + int value(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/advance/daos/AdvanceAssignmentDAO.java b/libreplan-business/src/main/java/org/libreplan/business/advance/daos/AdvanceAssignmentDAO.java index 8fb407403..c5842eaf0 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/advance/daos/AdvanceAssignmentDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/advance/daos/AdvanceAssignmentDAO.java @@ -29,11 +29,11 @@ import org.springframework.stereotype.Repository; /** * Dao for {@link AdvanceAssignment} + * * @author Susana Montes Pedreira */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) -public class AdvanceAssignmentDAO extends - GenericDAOHibernate implements - IAdvanceAssignmentDAO { +public class AdvanceAssignmentDAO extends GenericDAOHibernate + implements IAdvanceAssignmentDAO { } \ No newline at end of file diff --git a/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceAssignment.java b/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceAssignment.java index 5e26122d4..3f3df0a4b 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceAssignment.java +++ b/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceAssignment.java @@ -44,7 +44,8 @@ public abstract class AdvanceAssignment extends BaseEntity { public void setReportGlobalAdvance(boolean reportGlobalAdvance) { this.reportGlobalAdvance = reportGlobalAdvance; - if (this.orderElement != null) { + + if ( this.orderElement != null ) { this.orderElement.markAsDirtyLastAdvanceMeasurementForSpreading(); } } @@ -63,12 +64,12 @@ public abstract class AdvanceAssignment extends BaseEntity { public void setAdvanceType(AdvanceType advanceType) { AdvanceType oldType = this.advanceType; - if (advanceType != null) { + if ( advanceType != null ) { this.advanceType = advanceType; } - if (oldType != null && advanceType != null) { - changeAdvanceTypeInParents(oldType, this.advanceType, this); + if ( oldType != null && advanceType != null ) { + changeAdvanceTypeInParents(oldType, this); } } @@ -77,17 +78,16 @@ public abstract class AdvanceAssignment extends BaseEntity { return this.advanceType; } - public void changeAdvanceTypeInParents(final AdvanceType oldType, - AdvanceType newType, AdvanceAssignment advance) { - if (getOrderElement() != null) { + public void changeAdvanceTypeInParents(final AdvanceType oldType, AdvanceAssignment advance) { + if ( getOrderElement() != null ) { OrderLineGroup parent = getOrderElement().getParent(); - if (parent != null) { - IndirectAdvanceAssignment oldIndirect = parent - .getIndirectAdvanceAssignment(oldType); - if (oldIndirect != null) { + + if ( parent != null ) { + IndirectAdvanceAssignment oldIndirect = parent.getIndirectAdvanceAssignment(oldType); + + if ( oldIndirect != null ) { parent.removeIndirectAdvanceAssignment(oldType); - IndirectAdvanceAssignment newIndirect = advance - .createIndirectAdvanceFor(parent); + IndirectAdvanceAssignment newIndirect = advance.createIndirectAdvanceFor(parent); parent.addIndirectAdvanceAssignment(newIndirect); } } @@ -99,6 +99,7 @@ public abstract class AdvanceAssignment extends BaseEntity { result.setAdvanceType(getAdvanceType()); result.setOrderElement(parent); result.setReportGlobalAdvance(noOtherGlobalReportingAdvance(parent)); + return create(result); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceType.java b/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceType.java index 4a3572d2f..269958e8f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceType.java +++ b/libreplan-business/src/main/java/org/libreplan/business/advance/entities/AdvanceType.java @@ -35,7 +35,6 @@ import org.libreplan.business.common.BaseEntity; import org.libreplan.business.common.IHumanIdentifiable; import org.libreplan.business.common.Registry; import org.libreplan.business.common.exceptions.InstanceNotFoundException; -import org.libreplan.business.orders.entities.OrderElement; /** * @author Susana Montes Pedreira @@ -92,7 +91,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ private Boolean qualityForm = false; - private IAdvanceTypeDAO avanceTypeDAO = Registry.getAdvanceTypeDao(); + private IAdvanceTypeDAO avancedTypeDAO = Registry.getAdvanceTypeDao(); private boolean readOnly = false; @@ -100,12 +99,16 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ * Constructor for hibernate. Do not use! */ public AdvanceType() { - } - private AdvanceType(String unitName, BigDecimal defaultMaxValue, - boolean updatable, BigDecimal unitPrecision, boolean active, - boolean percentage, boolean qualityForm) { + private AdvanceType(String unitName, + BigDecimal defaultMaxValue, + boolean updatable, + BigDecimal unitPrecision, + boolean active, + boolean percentage, + boolean qualityForm) { + this.unitName = unitName; this.percentage = percentage; setDefaultMaxValue(defaultMaxValue); @@ -127,16 +130,16 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ } public void setDefaultMaxValue(BigDecimal defaultMaxValue) { - if (defaultMaxValue.compareTo(BigDecimal.ZERO) <= 0) { - throw new IllegalArgumentException( - "The maximum value must be greater than 0"); + if ( defaultMaxValue.compareTo(BigDecimal.ZERO) <= 0 ) { + throw new IllegalArgumentException("The maximum value must be greater than 0"); } - if (percentage) { - if (defaultMaxValue.compareTo(new BigDecimal(100)) > 0) { - throw new IllegalArgumentException( - "The maximum value for percentage is 100"); + + if ( percentage ) { + if ( defaultMaxValue.compareTo(new BigDecimal(100)) > 0 ) { + throw new IllegalArgumentException("The maximum value for percentage is 100"); } } + this.defaultMaxValue = defaultMaxValue; this.defaultMaxValue.setScale(2, BigDecimal.ROUND_HALF_UP); } @@ -171,45 +174,37 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ } public String getType() { - if (isUpdatable()) { + if ( isUpdatable() ) { return _("User"); } - if (isQualityForm()) { + + if ( isQualityForm() ) { return _("Quality form"); } + return _("Predefined"); } - public void doPropagateAdvaceToParent(OrderElement orderElement) { - } - public boolean isPrecisionValid(BigDecimal precision) { - if ((this.defaultMaxValue == null) || (precision == null)) { - return true; - } - return this.defaultMaxValue.compareTo(precision) >= 0; - + return (this.defaultMaxValue == null) || (precision == null) || this.defaultMaxValue.compareTo(precision) >= 0; } public boolean isDefaultMaxValueValid(BigDecimal defaultMaxValue) { - if ((this.unitPrecision == null) || (defaultMaxValue == null)) { - return true; - } - return this.unitPrecision.compareTo(defaultMaxValue) <= 0; + return (this.unitPrecision == null) || + (defaultMaxValue == null) || + this.unitPrecision.compareTo(defaultMaxValue) <= 0; } public static boolean equivalentInDB(AdvanceType type, AdvanceType otherType) { - if (type == null || type.getId() == null || otherType == null - || otherType.getId() == null) { - return false; - } - return type.getId().equals(otherType.getId()); + return !(type == null || type.getId() == null || otherType == null || otherType.getId() == null) && + type.getId().equals(otherType.getId()); } public void setPercentage(boolean percentage) { - if (percentage) { + if ( percentage ) { defaultMaxValue = new BigDecimal(100); } + this.percentage = percentage; } @@ -228,21 +223,23 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ @AssertTrue(message = "progress type marked as quality form but is updatable") public boolean isIfIsQualityFormIsNotUpdatableConstraint() { - if (isQualityForm()) { - if (isUpdatable()) { + if ( isQualityForm() ) { + if ( isUpdatable() ) { return false; } } + return true; } @AssertTrue(message = "default maximum value of percentage progress type must be 100") public boolean isDefaultMaxValueMustBe100ForPercentageConstraint() { - if (percentage) { - if (defaultMaxValue.compareTo(new BigDecimal(100)) != 0) { + if ( percentage ) { + if ( defaultMaxValue.compareTo(new BigDecimal(100)) != 0 ) { return false; } } + return true; } @@ -253,11 +250,12 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ @AssertTrue(message = "progress type name is already in use") public boolean isUniqueNameConstraint() { - if (StringUtils.isBlank(unitName)) { + if ( StringUtils.isBlank(unitName) ) { return true; } - if (isNewObject()) { - return !avanceTypeDAO.existsByNameInAnotherTransaction(unitName); + + if ( isNewObject() ) { + return !avancedTypeDAO.existsByNameInAnotherTransaction(unitName); } else { return checkNotExistsOrIsTheSame(); } @@ -265,8 +263,8 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ private boolean checkNotExistsOrIsTheSame() { try { - AdvanceType advanceType = avanceTypeDAO - .findUniqueByNameInAnotherTransaction(unitName); + AdvanceType advanceType = avancedTypeDAO.findUniqueByNameInAnotherTransaction(unitName); + return advanceType.getId().equals(getId()); } catch (InstanceNotFoundException e) { return true; @@ -275,10 +273,7 @@ public class AdvanceType extends BaseEntity implements IHumanIdentifiable{ @AssertTrue(message = "default maximum value must be greater than precision value") public boolean isDefaultMaxValueGreaterThanPrecisionConstraint() { - if (defaultMaxValue.compareTo(unitPrecision) == -1) { - return false; - } - return true; + return defaultMaxValue.compareTo(unitPrecision) != -1; } public void setReadOnly(boolean readOnly) { diff --git a/libreplan-business/src/main/java/org/libreplan/business/calendars/daos/CalendarExceptionTypeDAO.java b/libreplan-business/src/main/java/org/libreplan/business/calendars/daos/CalendarExceptionTypeDAO.java index a1542e094..c27e08d2c 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/calendars/daos/CalendarExceptionTypeDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/calendars/daos/CalendarExceptionTypeDAO.java @@ -44,9 +44,8 @@ import org.springframework.transaction.annotation.Transactional; */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) -public class CalendarExceptionTypeDAO extends - IntegrationEntityDAO implements - ICalendarExceptionTypeDAO { +public class CalendarExceptionTypeDAO extends IntegrationEntityDAO + implements ICalendarExceptionTypeDAO { @Override public boolean existsByName(CalendarExceptionType type) { @@ -54,6 +53,7 @@ public class CalendarExceptionTypeDAO extends c.add(Restrictions.eq("name", type.getName())); List list = c.list(); + return (list.size() == 1); } @@ -70,6 +70,7 @@ public class CalendarExceptionTypeDAO extends private List getCalendarExceptions(CalendarExceptionType type) { Criteria c = getSession().createCriteria(CalendarException.class); c.add(Restrictions.eq("type.id", type.getId())); + return c.list(); } @@ -92,16 +93,15 @@ public class CalendarExceptionTypeDAO extends @Override @Transactional(readOnly = true) public CalendarExceptionType findUniqueByName(String name) throws InstanceNotFoundException { - if (StringUtils.isBlank(name)) { + if ( StringUtils.isBlank(name) ) { throw new InstanceNotFoundException(null, CalendarExceptionType.class.getName()); } - CalendarExceptionType calendarExceptionType = (CalendarExceptionType) getSession().createCriteria( - CalendarExceptionType.class).add( - Restrictions.eq("name", name.trim()).ignoreCase()) - .uniqueResult(); + CalendarExceptionType calendarExceptionType = (CalendarExceptionType) getSession() + .createCriteria(CalendarExceptionType.class) + .add(Restrictions.eq("name", name.trim()).ignoreCase()).uniqueResult(); - if (calendarExceptionType == null) { + if ( calendarExceptionType == null ) { throw new InstanceNotFoundException(name, CalendarExceptionType.class.getName()); } else { return calendarExceptionType; @@ -111,8 +111,7 @@ public class CalendarExceptionTypeDAO extends @Override @Transactional(readOnly = true, propagation = Propagation.REQUIRES_NEW) - public CalendarExceptionType findUniqueByNameAnotherTransaction(String name) - throws InstanceNotFoundException { + public CalendarExceptionType findUniqueByNameAnotherTransaction(String name) throws InstanceNotFoundException { return findUniqueByName(name); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarBootstrap.java b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarBootstrap.java index fe3c32428..6adb8f709 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarBootstrap.java +++ b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarBootstrap.java @@ -47,35 +47,44 @@ public class CalendarBootstrap implements ICalendarBootstrap { @Override @Transactional public void loadRequiredData() { - if (calendarExceptionTypeDAO.getAll().size() == 0) { - for (PredefinedCalendarExceptionTypes type : PredefinedCalendarExceptionTypes - .values()) { - CalendarExceptionType calendarExceptionType = type - .getCalendarExceptionType(); - calendarExceptionType - .setCode(entitySequenceDAO - .getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + if ( calendarExceptionTypeDAO.getAll().size() == 0 ) { + for (PredefinedCalendarExceptionTypes type : PredefinedCalendarExceptionTypes.values()) { + CalendarExceptionType calendarExceptionType = type.getCalendarExceptionType(); + + calendarExceptionType.setCode( + entitySequenceDAO.getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } } - if (!calendarExceptionTypeDAO.existsByName(PredefinedCalendarExceptionTypes.NOT_WORKING_DAY - .getCalendarExceptionType())) { - CalendarExceptionType calendarExceptionType = PredefinedCalendarExceptionTypes.NOT_WORKING_DAY - .getCalendarExceptionType(); - calendarExceptionType - .setCode(entitySequenceDAO - .getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + + boolean condition = calendarExceptionTypeDAO + .existsByName(PredefinedCalendarExceptionTypes.NOT_WORKING_DAY.getCalendarExceptionType()); + + if ( !condition ) { + + CalendarExceptionType calendarExceptionType = + PredefinedCalendarExceptionTypes.NOT_WORKING_DAY.getCalendarExceptionType(); + + calendarExceptionType.setCode( + entitySequenceDAO.getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } - if (!calendarExceptionTypeDAO.existsByName(PredefinedCalendarExceptionTypes.WORKING_DAY - .getCalendarExceptionType())) { - CalendarExceptionType calendarExceptionType = PredefinedCalendarExceptionTypes.WORKING_DAY - .getCalendarExceptionType(); - calendarExceptionType - .setCode(entitySequenceDAO - .getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + + condition = calendarExceptionTypeDAO + .existsByName(PredefinedCalendarExceptionTypes.WORKING_DAY.getCalendarExceptionType()); + + if ( !condition ) { + + CalendarExceptionType calendarExceptionType = + PredefinedCalendarExceptionTypes.WORKING_DAY.getCalendarExceptionType(); + + calendarExceptionType.setCode( + entitySequenceDAO.getNextEntityCodeWithoutTransaction(EntityNameEnum.CALENDAR_EXCEPTION_TYPE)); + calendarExceptionType.setCodeAutogenerated(true); calendarExceptionTypeDAO.save(calendarExceptionType); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionType.java b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionType.java index 9c0a5f28b..e398071ea 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionType.java +++ b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionType.java @@ -39,15 +39,14 @@ import org.libreplan.business.common.Registry; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.workingday.EffortDuration; import org.libreplan.business.workingday.EffortDuration.Granularity; -import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException; +import org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException; /** * Type of an exception day. * * @author Manuel Rego Casasnovas */ -public class CalendarExceptionType extends IntegrationEntity implements - IHumanIdentifiable { +public class CalendarExceptionType extends IntegrationEntity implements IHumanIdentifiable { private String name; @@ -62,34 +61,34 @@ public class CalendarExceptionType extends IntegrationEntity implements return create(new CalendarExceptionType()); } - public static CalendarExceptionType create(String name, - CalendarExceptionTypeColor color, - Boolean notAssignable) { + public static CalendarExceptionType create(String name, CalendarExceptionTypeColor color, Boolean notAssignable) { return create(new CalendarExceptionType(name, color, notAssignable)); } - public static CalendarExceptionType create(String code, String name, - CalendarExceptionTypeColor color, Boolean notAssignable) { - return create(new CalendarExceptionType(name, color, notAssignable), - code); + public static CalendarExceptionType create( + String code, String name, CalendarExceptionTypeColor color, Boolean notAssignable) { + + return create(new CalendarExceptionType(name, color, notAssignable), code); } - public static CalendarExceptionType create(String code, String name, - CalendarExceptionTypeColor color, Boolean notAssignable, - Boolean updatable) { - CalendarExceptionType calendarExceptionType = new CalendarExceptionType( - name, color, notAssignable); + public static CalendarExceptionType create( + String code, String name, CalendarExceptionTypeColor color, Boolean notAssignable, Boolean updatable) { + + CalendarExceptionType calendarExceptionType = new CalendarExceptionType(name, color, notAssignable); calendarExceptionType.updatable = updatable; - return create(calendarExceptionType, - code); + + return create(calendarExceptionType, code); } - public static CalendarExceptionType create(String code, String name, - CalendarExceptionTypeColor color, Boolean notAssignable, - EffortDuration duration) { - CalendarExceptionType calendarExceptionType = new CalendarExceptionType( - name, color, notAssignable); + public static CalendarExceptionType create(String code, + String name, + CalendarExceptionTypeColor color, + Boolean notAssignable, + EffortDuration duration) { + + CalendarExceptionType calendarExceptionType = new CalendarExceptionType(name, color, notAssignable); calendarExceptionType.setDuration(duration); + return create(calendarExceptionType, code); } @@ -97,16 +96,13 @@ public class CalendarExceptionType extends IntegrationEntity implements * Constructor for hibernate. Do not use! */ protected CalendarExceptionType() { - } - public CalendarExceptionType(String name, CalendarExceptionTypeColor color, - Boolean notOverAssignable) { + public CalendarExceptionType(String name, CalendarExceptionTypeColor color, Boolean notOverAssignable) { this.name = name; this.color = color; this.capacity = Capacity.zero(); - this.capacity = this.capacity.overAssignableWithoutLimit(!BooleanUtils - .isTrue(notOverAssignable)); + this.capacity = this.capacity.overAssignableWithoutLimit(!BooleanUtils.isTrue(notOverAssignable)); } public boolean isUpdatable() { @@ -148,8 +144,7 @@ public class CalendarExceptionType extends IntegrationEntity implements } public void setOverAssignable(Boolean overAssignable) { - this.capacity = capacity.overAssignableWithoutLimit(BooleanUtils - .isTrue(overAssignable)); + this.capacity = capacity.overAssignableWithoutLimit(BooleanUtils.isTrue(overAssignable)); } public String getOverAssignableStr() { @@ -161,12 +156,14 @@ public class CalendarExceptionType extends IntegrationEntity implements } private String asString(EffortDuration duration) { - if (duration == null) { + if ( duration == null ) { return ""; } + EnumMap values = duration.decompose(); Integer hours = values.get(Granularity.HOURS); Integer minutes = values.get(Granularity.MINUTES); + return hours + ":" + minutes; } @@ -181,18 +178,18 @@ public class CalendarExceptionType extends IntegrationEntity implements @AssertTrue(message = "name is already used") public boolean isUniqueNameConstraint() { - if (StringUtils.isBlank(name)) { + if ( StringUtils.isBlank(name) ) { return true; } ICalendarExceptionTypeDAO calendarExceptionTypeDAO = getIntegrationEntityDAO(); - if (isNewObject()) { - return !calendarExceptionTypeDAO.existsByNameAnotherTransaction( - name); + if ( isNewObject() ) { + return !calendarExceptionTypeDAO.existsByNameAnotherTransaction(name); } else { try { - CalendarExceptionType calendarExceptionType = calendarExceptionTypeDAO - .findUniqueByNameAnotherTransaction(name); + CalendarExceptionType calendarExceptionType = + calendarExceptionTypeDAO.findUniqueByNameAnotherTransaction(name); + return calendarExceptionType.getId().equals(getId()); } catch (InstanceNotFoundException e) { return true; diff --git a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionTypeColor.java b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionTypeColor.java index 65811c344..d1eb7f36f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionTypeColor.java +++ b/libreplan-business/src/main/java/org/libreplan/business/calendars/entities/CalendarExceptionTypeColor.java @@ -42,8 +42,7 @@ public enum CalendarExceptionTypeColor { private final String colorOwnException; private final String colorDerivedException; - private CalendarExceptionTypeColor(String name, String colorOwnException, - String colorDerivedException) { + CalendarExceptionTypeColor(String name, String colorOwnException, String colorDerivedException) { this.name = name; this.colorOwnException = colorOwnException; this.colorDerivedException = colorDerivedException; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/AdHocTransactionService.java b/libreplan-business/src/main/java/org/libreplan/business/common/AdHocTransactionService.java index 6523a5d12..7b93dac87 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/AdHocTransactionService.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/AdHocTransactionService.java @@ -32,14 +32,14 @@ import org.springframework.transaction.annotation.Transactional; @Service public class AdHocTransactionService implements IAdHocTransactionService { - private static T proxy(IAdHocTransactionService transactionService, - boolean readOnly, - Class interfaceClass, - T interfaceObject) { + private static T proxy( + IAdHocTransactionService transactionService, boolean readOnly, Class interfaceClass, T interfaceObject) { + Class[] interfaces = { interfaceClass }; - return interfaceClass.cast(Proxy.newProxyInstance(interfaceClass - .getClassLoader(), interfaces, createHandler(interfaceObject, - transactionService, readOnly))); + return interfaceClass.cast(Proxy.newProxyInstance( + interfaceClass.getClassLoader(), + interfaces, + createHandler(interfaceObject, transactionService, readOnly))); } /** @@ -50,8 +50,9 @@ public class AdHocTransactionService implements IAdHocTransactionService { * @param interfaceObject * @return */ - public static T readOnlyProxy(IAdHocTransactionService transactionService, - Class interfaceClass, T interfaceObject) { + public static T readOnlyProxy( + IAdHocTransactionService transactionService, Class interfaceClass, T interfaceObject) { + return proxy(transactionService, true, interfaceClass, interfaceObject); } @@ -63,45 +64,35 @@ public class AdHocTransactionService implements IAdHocTransactionService { * @param interfaceObject * @return */ - public static T proxy(IAdHocTransactionService transactionService, - Class interfaceClass, T interfaceObject) { + public static T proxy(IAdHocTransactionService transactionService, Class interfaceClass, T interfaceObject) { return proxy(transactionService, false, interfaceClass, interfaceObject); } - private static InvocationHandler createHandler(final Object originalObject, - final IAdHocTransactionService transactionService, - final boolean readOnly) { - return new InvocationHandler() { - @Override - public Object invoke(final Object proxy, final Method method, - final Object[] args) throws Throwable { - IOnTransaction onTransaction = createOnTransaction(originalObject, method, args); - try { - if (readOnly) { - return transactionService - .runOnReadOnlyTransaction(onTransaction); - } else { - return transactionService.runOnTransaction(onTransaction); - } - } catch (RuntimeException e) { - throw e.getCause(); + private static InvocationHandler createHandler( + final Object originalObject, final IAdHocTransactionService transactionService, final boolean readOnly) { + + return (proxy, method, args) -> { + IOnTransaction onTransaction = createOnTransaction(originalObject, method, args); + try { + if ( readOnly ) { + return transactionService.runOnReadOnlyTransaction(onTransaction); + } else { + return transactionService.runOnTransaction(onTransaction); } + } catch (RuntimeException e) { + throw e.getCause(); } }; } private static IOnTransaction createOnTransaction( - final Object originalObject, final Method method, - final Object[] args) { - return new IOnTransaction() { + final Object originalObject, final Method method, final Object[] args) { - @Override - public Object execute() { - try { - return method.invoke(originalObject, args); - } catch (Exception e) { - throw new RuntimeException(e); - } + return () -> { + try { + return method.invoke(originalObject, args); + } catch (Exception e) { + throw new RuntimeException(e); } }; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/BaseEntity.java b/libreplan-business/src/main/java/org/libreplan/business/common/BaseEntity.java index c8f6d78c8..235acbdac 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/BaseEntity.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/BaseEntity.java @@ -57,15 +57,16 @@ public abstract class BaseEntity implements INewObject { * @param entities * @return entities grouped by id */ - public static Map> byId( - Collection entities) { - Map> result = new HashMap>(); + public static Map> byId(Collection entities) { + Map> result = new HashMap<>(); + for (T each : entities) { if ( !result.containsKey(each.getId()) ) { - result.put(each.getId(), new HashSet()); + result.put(each.getId(), new HashSet<>()); } result.get(each.getId()).add(each); } + return result; } @@ -89,7 +90,7 @@ public abstract class BaseEntity implements INewObject { } public Long getVersion() { - if (isNewObject()) { + if ( isNewObject() ) { return null; } @@ -119,6 +120,7 @@ public abstract class BaseEntity implements INewObject { protected static T create(T baseEntity) { baseEntity.setNewObject(true); + return baseEntity; } @@ -146,6 +148,7 @@ public abstract class BaseEntity implements INewObject { } catch (Exception e) { final String message = "error doing toString"; LOG.error(message, e); + return message; } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/Configuration.java b/libreplan-business/src/main/java/org/libreplan/business/common/Configuration.java index 8154339ec..ad40e14e5 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/Configuration.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/Configuration.java @@ -29,14 +29,16 @@ import org.apache.commons.lang3.BooleanUtils; * Currently we have three options: *
    *
  • Enable/Disable the warning changing default password
  • - *
  • Enable/Disable default users (such as wsreader, wswriter, - * wssubcontracting, manager, hresources, outsourcing and reports)
  • + * + *
  • Enable/Disable default users + * (such as wsreader, wswriter, wssubcontracting, manager, hresources, outsourcing and reports)
  • + * *
  • Enable/Disable E-mail sending functionality
  • *
* * @author Susana Montes Pedreira * @author Manuel Rego Casasnovas - * @author Vova Perebykivskiy + * @author Vova Perebykivskyi */ public class Configuration { @@ -57,12 +59,10 @@ public class Configuration { } /** - * It returns the current state of the default passwords control in order to - * show or not warnings. + * It returns the current state of the default passwords control in order to show or not warnings. */ public static Boolean isDefaultPasswordsControl() { - return singleton.getDefaultPasswordsControl() != null ? singleton - .getDefaultPasswordsControl() : true; + return singleton.getDefaultPasswordsControl() != null ? singleton.getDefaultPasswordsControl() : true; } public Boolean getDefaultPasswordsControl() { return defaultPasswordsControl; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/IntegrationEntity.java b/libreplan-business/src/main/java/org/libreplan/business/common/IntegrationEntity.java index a4961b2be..099ae6c8f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/IntegrationEntity.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/IntegrationEntity.java @@ -33,9 +33,8 @@ import org.libreplan.business.common.exceptions.InstanceNotFoundException; /** * Base class for all entities to be sent/received to/from other applications. - * These entities have a "code" attribute, which unlike "id" is unique among - * the applications to be integrated ("id" is only unique inside - * "libreplan"). + * These entities have a "code" attribute, which unlike "id" is unique among the applications to be integrated + * ("id" is only unique inside "libreplan"). * * @author Fernando Bellas Permuy */ @@ -63,9 +62,7 @@ public abstract class IntegrationEntity extends BaseEntity { * specifying a specific code (e.g. provided by the end-user or an external * application). */ - protected static T create( - T integrationEntity, String code) { - + protected static T create(T integrationEntity, String code) { BaseEntity.create(integrationEntity); integrationEntity.setCode(code); @@ -78,8 +75,7 @@ public abstract class IntegrationEntity extends BaseEntity { * automatically generate a code. This is a Template method which delegates * code generation by calling on generateCode(). */ - protected static T create( - T integrationEntity) { + protected static T create(T integrationEntity) { BaseEntity.create(integrationEntity); integrationEntity.setCode(generateCode()); @@ -110,21 +106,20 @@ public abstract class IntegrationEntity extends BaseEntity { @AssertTrue(message="code is already used") public boolean isUniqueCodeConstraint() { - /* Check if it makes sense to check the constraint .*/ - if (!iCodeSpecified()) { + // Check if it makes sense to check the constraint + if ( !iCodeSpecified() ) { return true; } /* Check the constraint. */ - IIntegrationEntityDAO - integrationEntityDAO = findIntegrationEntityDAO(); + IIntegrationEntityDAO integrationEntityDAO = findIntegrationEntityDAO(); - if (isNewObject()) { + if ( isNewObject() ) { return !integrationEntityDAO.existsByCodeAnotherTransaction(code); } else { try { - IntegrationEntity entity = - integrationEntityDAO.findByCodeAnotherTransaction(code); + IntegrationEntity entity = integrationEntityDAO.findByCodeAnotherTransaction(code); + return entity.getId().equals(getId()); } catch (InstanceNotFoundException e) { return true; @@ -142,14 +137,14 @@ public abstract class IntegrationEntity extends BaseEntity { protected String getFirstRepeatedCode( Set entities) { - Set codes = new HashSet(); + Set codes = new HashSet<>(); for (IntegrationEntity e : entities) { String code = e.getCode(); - if (!StringUtils.isBlank(code)) { - if (codes.contains(code.toLowerCase())) { + if ( !StringUtils.isBlank(code) ) { + if ( codes.contains(code.toLowerCase()) ) { return code; } else { codes.add(code.toLowerCase()); @@ -165,20 +160,17 @@ public abstract class IntegrationEntity extends BaseEntity { /** * It returns the DAO of this entity. */ - protected abstract IIntegrationEntityDAO - getIntegrationEntityDAO(); + protected abstract IIntegrationEntityDAO getIntegrationEntityDAO(); - private IIntegrationEntityDAO - findIntegrationEntityDAO() { + private IIntegrationEntityDAO findIntegrationEntityDAO() { - IIntegrationEntityDAO - integrationEntityDAO = getIntegrationEntityDAO(); + IIntegrationEntityDAO integrationEntityDAO = getIntegrationEntityDAO(); - if (!integrationEntityDAO.getEntityClass().isAssignableFrom( - this.getClass())) { - throw new RuntimeException(this.getClass().getName() + "::" + - "getIntegrationEntityDAO returns an incompatible " + - "DAO: " + integrationEntityDAO.getClass().getName()); + if ( !integrationEntityDAO.getEntityClass().isAssignableFrom(this.getClass())) { + throw new RuntimeException( + this.getClass().getName() + + ":: getIntegrationEntityDAO returns an incompatible DAO: " + + integrationEntityDAO.getClass().getName()); } else { return integrationEntityDAO; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java b/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java index 0d50523e7..f519dcb75 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/Registry.java @@ -69,11 +69,10 @@ import org.libreplan.business.workreports.daos.IWorkReportTypeDAO; import org.springframework.beans.factory.annotation.Autowired; /** - * A registry, AKA service locator, for objects in which dependency injection - * (DI) is not directly supported by Spring (e.g. entities) must use this class - * to access DAOs. For the rest of classes (e.g. services, tests, etc.), Spring - * DI is a more convenient option. The DAOs or services are added to the - * registry as needed. + * A registry, AKA service locator, for objects in which dependency injection (DI) is not directly supported by Spring + * (e.g. entities) must use this class to access DAOs. + * For the rest of classes (e.g. services, tests, etc.), Spring DI is a more convenient option. + * The DAOs or services are added to the registry as needed. * * @author Óscar González Fernández * @author Fernando Bellas Permuy @@ -93,7 +92,6 @@ public class Registry { private ICriterionTypeDAO criterionTypeDAO; @Autowired - private IUserDAO userDAO; @Autowired @@ -163,8 +161,7 @@ public class Registry { private ICriterionSatisfactionDAO criterionSatisfactionDAO; @Autowired - private IResourcesCostCategoryAssignmentDAO - resourcesCostCategoryAssignmentDAO; + private IResourcesCostCategoryAssignmentDAO resourcesCostCategoryAssignmentDAO; @Autowired private IOrderElementTemplateDAO orderElementTemplateDAO; @@ -336,11 +333,8 @@ public class Registry { return getInstance().criterionSatisfactionDAO; } - public static IResourcesCostCategoryAssignmentDAO - getResourcesCostCategoryAssignmentDAO() { - + public static IResourcesCostCategoryAssignmentDAO getResourcesCostCategoryAssignmentDAO() { return getInstance().resourcesCostCategoryAssignmentDAO; - } public static IOrderElementTemplateDAO getOrderElementTemplateDAO() { @@ -395,7 +389,9 @@ public class Registry { return getInstance().issueLogDAO; } - public static IRiskLogDAO getRiskLogDAO() {return getInstance().riskLogDAO;} + public static IRiskLogDAO getRiskLogDAO() { + return getInstance().riskLogDAO; + } public static IExpenseSheetLineDAO getExpenseSheetLineDAO() { return getInstance().expenseSheetLineDAO; diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/EntitySequenceDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/EntitySequenceDAO.java index 555c043de..e870b358a 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/EntitySequenceDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/EntitySequenceDAO.java @@ -27,15 +27,13 @@ import java.util.List; import org.apache.commons.lang3.Validate; import org.hibernate.NonUniqueResultException; import org.hibernate.criterion.Restrictions; -import org.libreplan.business.common.IAdHocTransactionService; import org.libreplan.business.common.entities.EntityNameEnum; import org.libreplan.business.common.entities.EntitySequence; import org.libreplan.business.common.exceptions.InstanceNotFoundException; import org.libreplan.business.i18n.I18nHelper; -import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanDefinition; import org.springframework.context.annotation.Scope; -import org.springframework.orm.hibernate4.HibernateOptimisticLockingFailureException; +import org.springframework.orm.hibernate5.HibernateOptimisticLockingFailureException; import org.springframework.stereotype.Repository; import org.springframework.transaction.annotation.Propagation; import org.springframework.transaction.annotation.Transactional; @@ -46,11 +44,7 @@ import org.springframework.transaction.annotation.Transactional; */ @Repository @Scope(BeanDefinition.SCOPE_SINGLETON) -public class EntitySequenceDAO extends - GenericDAOHibernate implements IEntitySequenceDAO { - - @Autowired - private IAdHocTransactionService transactionService; +public class EntitySequenceDAO extends GenericDAOHibernate implements IEntitySequenceDAO { @Override public List getAll() { @@ -59,27 +53,23 @@ public class EntitySequenceDAO extends @Override @SuppressWarnings("unchecked") - public List findEntitySquencesNotIn( - List entitySequences) { - List entitySequenceIds = new ArrayList(); + public List findEntitySquencesNotIn(List entitySequences) { + List entitySequenceIds = new ArrayList<>(); for (EntitySequence entitySequence : entitySequences) { - if (!entitySequence.isNewObject()) { + if ( !entitySequence.isNewObject() ) { entitySequenceIds.add(entitySequence.getId()); } } - return getSession().createCriteria(EntitySequence.class).add( - Restrictions.not(Restrictions.in("id", entitySequenceIds))) - .list(); + return getSession().createCriteria(EntitySequence.class) + .add(Restrictions.not(Restrictions.in("id", entitySequenceIds))).list(); } @Override - public void remove(final EntitySequence entitySequence) - throws InstanceNotFoundException, IllegalArgumentException { - if (entitySequence.getLastValue() > 0) { + public void remove(final EntitySequence entitySequence) throws InstanceNotFoundException, IllegalArgumentException { + if ( entitySequence.getLastValue() > 0 ) { throw new IllegalArgumentException( - I18nHelper - ._("Entity Sequence cannot be deleted. Entity Sequence already in use")); + I18nHelper._("Entity Sequence cannot be deleted. Entity Sequence already in use")); } remove(entitySequence.getId()); @@ -88,15 +78,15 @@ public class EntitySequenceDAO extends @Override public EntitySequence getActiveEntitySequence(EntityNameEnum entityName) throws InstanceNotFoundException, NonUniqueResultException { - EntitySequence entitySequence = (EntitySequence) getSession() - .createCriteria( - EntitySequence.class).add( - Restrictions.eq("entityName", entityName)).add( - Restrictions.eq("active", true)).uniqueResult(); - if (entitySequence == null) { - throw new InstanceNotFoundException(entitySequence, - "Entity sequence not exist"); + + EntitySequence entitySequence = (EntitySequence) getSession().createCriteria(EntitySequence.class) + .add(Restrictions.eq("entityName", entityName)) + .add(Restrictions.eq("active", true)).uniqueResult(); + + if ( entitySequence == null ) { + throw new InstanceNotFoundException(entitySequence, "Entity sequence not exist"); } + return entitySequence; } @@ -115,17 +105,14 @@ public class EntitySequenceDAO extends do { entitySequence.incrementLastValue(); code = entitySequence.getCode(); - } while (entityName.getIntegrationEntityDAO() - .existsByCode(code)); + } while (entityName.getIntegrationEntityDAO().existsByCode(code)); save(entitySequence); return code; - } catch (HibernateOptimisticLockingFailureException e) { + } catch (HibernateOptimisticLockingFailureException | + InstanceNotFoundException | + NonUniqueResultException e) { // Do nothing (optimistic approach 5 attempts) - } catch (InstanceNotFoundException e) { - - } catch (NonUniqueResultException e) { - } } @@ -133,12 +120,11 @@ public class EntitySequenceDAO extends } @Override - public boolean existOtherActiveSequenceByEntityNameForNewObject( - EntitySequence entitySequence) { + public boolean existOtherActiveSequenceByEntityNameForNewObject(EntitySequence entitySequence) { Validate.notNull(entitySequence); try { - EntitySequence t = getActiveEntitySequence(entitySequence - .getEntityName()); + EntitySequence t = getActiveEntitySequence(entitySequence.getEntityName()); + return (t != null && t != entitySequence); } catch (InstanceNotFoundException e) { return false; @@ -149,15 +135,14 @@ public class EntitySequenceDAO extends @Override public Integer getNumberOfDigitsCode(EntityNameEnum entityName) { - int numberOfDigits = 5; + int numberOfDigits; try { EntitySequence entitySequence = getActiveEntitySequence(entityName); numberOfDigits = entitySequence.getNumberOfDigits(); - } catch (InstanceNotFoundException e) { - throw new RuntimeException(e); - } catch (NonUniqueResultException e) { + } catch (InstanceNotFoundException | NonUniqueResultException e) { throw new RuntimeException(e); } + return numberOfDigits; } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/GenericDAOHibernate.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/GenericDAOHibernate.java index cb38bb367..9c522e772 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/GenericDAOHibernate.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/GenericDAOHibernate.java @@ -41,17 +41,17 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.transaction.annotation.Transactional; /** - * An implementation of IGenericDao based on Hibernate's native - * API. Concrete DAOs must extend directly from this class. This constraint is - * imposed by the constructor of this class that must infer the type of the - * entity from the declaration of the concrete DAO. + * An implementation of IGenericDao based on Hibernate's native API. + * Concrete DAOs must extend directly from this class. + * This constraint is imposed by the constructor of this class that must infer the + * type of the entity from the declaration of the concrete DAO. *

- * This class autowires a SessionFactory bean and allows to - * implement DAOs with Hibernate's native API. Subclasses access Hibernate's - * Session by calling on getSession() method. + * This class autowires a SessionFactory bean and allows to implement DAOs with Hibernate's native API. + * Subclasses access Hibernate's Session by calling on getSession() method. * Operations must be implemented by catching HibernateException - * and rethrowing it by using convertHibernateAccessException() - * method. See source code of this class for an example. + * and rethrowing it by using convertHibernateAccessException() method. + * See source code of this class for an example. + * * @author Fernando Bellas Permuy * @param * Entity class @@ -87,8 +87,9 @@ public class GenericDAOHibernate /** * It's necessary to save and validate later. * - * Validate may retrieve the entity from DB and put it into the Session, which can eventually lead to - * a NonUniqueObject exception. Save works here to reattach the object as well as saving. + * Validate may retrieve the entity from DB and put it into the Session, + * which can eventually lead to a NonUniqueObject exception. + * Save works here to reattach the object as well as saving. */ public void save(E entity) throws ValidationException { getSession().saveOrUpdate(entity); @@ -108,9 +109,7 @@ public class GenericDAOHibernate } public E merge(E entity) { - return entityClass.cast(getSession().merge(entity)); - } public void checkVersion(E entity) { @@ -155,7 +154,7 @@ public class GenericDAOHibernate } public void lock(E entity) { - + // TODO resolve deprecated getSession().lock(entity, LockMode.UPGRADE); } @@ -168,7 +167,7 @@ public class GenericDAOHibernate @Transactional(readOnly = true) public E find(PK id) throws InstanceNotFoundException { - E entity = (E) getSession().get(entityClass, id); + E entity = getSession().get(entityClass, id); if ( entity == null ) { throw new InstanceNotFoundException(id, entityClass.getName()); @@ -189,8 +188,9 @@ public class GenericDAOHibernate public boolean exists(final PK id) { - return getSession().createCriteria(entityClass).add( - Restrictions.idEq(id)).setProjection(Projections.id()) + return getSession().createCriteria(entityClass) + .add(Restrictions.idEq(id)) + .setProjection(Projections.id()) .uniqueResult() != null; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/common/daos/IGenericDAO.java b/libreplan-business/src/main/java/org/libreplan/business/common/daos/IGenericDAO.java index f3bf94747..363c3b704 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/common/daos/IGenericDAO.java +++ b/libreplan-business/src/main/java/org/libreplan/business/common/daos/IGenericDAO.java @@ -29,9 +29,9 @@ import org.libreplan.business.common.exceptions.ValidationException; import org.springframework.dao.OptimisticLockingFailureException; /** - * The interface all DAOs (Data Access Objects) must implement. In general, - * a DAO must be implemented for each persistent entity. Concrete DAOs may - * provide (and usually will provide) additional methods. + * The interface all DAOs (Data Access Objects) must implement. + * In general, a DAO must be implemented for each persistent entity. + * Concrete DAOs may provide (and usually will provide) additional methods. * * @author Fernando Bellas Permuy * @@ -40,116 +40,120 @@ import org.springframework.dao.OptimisticLockingFailureException; */ public interface IGenericDAO { - public Class getEntityClass(); + Class getEntityClass(); /** - * It inserts the object passed as a parameter in the ORM session, planning - * it for updating (even though it is not modified before or after the call - * to this method) or insertion, depending if it is was detached or - * transient. If another instance with the same key already exists in the - * ORM session, an exception is thrown. When updating, version check is - * executed (if the entity has version control enabled) with the possible - * org.springframework.dao.OptimisticLockingFailureException - * being thrown. + * It inserts the object passed as a parameter in the ORM session, + * planning it for updating (even though it is not modified before or after the call to this method) + * or insertion, depending if it is was detached or transient. + * + * If another instance with the same key already exists in the ORM session, an exception is thrown. + * When updating, version check is executed + * (if the entity has version control enabled) with + * the possible org.springframework.dao.OptimisticLockingFailureException being thrown. * * @throws ValidationException * if the entity has some invalid values */ - public void save(E entity) throws ValidationException; + void save(E entity) throws ValidationException; /** * Unlike save, it does not execute validations. */ - public void saveWithoutValidating(E entity); + void saveWithoutValidating(E entity); /** - * It reattaches the entity to the current session. This method bypasses - * hibernate validations and must only be used on read only transaction - * {@link OptimisticLockingFailureException} can be thrown if the entity has - * been updated for another transaction + * It reattaches the entity to the current session. + * This method bypasses hibernate validations and must only be used on read only + * transaction {@link OptimisticLockingFailureException} can be thrown if the entity has + * been updated for another transaction. * @param entity */ - public void reattach(E entity); + void reattach(E entity); /** - * It inserts the object passed as a parameter in the ORM session. Unlike - * save, the entity passed as a parameter must not have been - * modified, and after calling the method, the entity is not considered - * dirty (but it will be considered dirty if it is modified after calling - * the method). Like save, if another instance with the same - * key already exists in the ORM session, an exception is thrown. + * It inserts the object passed as a parameter in the ORM session. + * + * Unlike save, the entity passed as a parameter must not have been modified, + * and after calling the method, the entity is not considered dirty + * (but it will be considered dirty if it is modified after calling the method). + * + * Like save, if another instance with the same key already exists in the ORM session, + * an exception is thrown. *

- * The intended use of the method is for reattachment of detached objects - * which have not been modified before calling this method and will not - * be modified during the transaction. + * The intended use of the method is for reattachment of detached objects which have not been modified + * before calling this method and will not be modified during the transaction. */ - public void reattachUnmodifiedEntity(E entity); + void reattachUnmodifiedEntity(E entity); /** - * It merges an entity. The caller must discard the reference passed as - * a parameter and work with the returned reference. Merging is an - * alternative technique to reattachment with save, which must - * be used when it cannot be assessed another instance with the same - * identifier as the one passed as a parameter already exists in the - * underlying ORM session. Like save, version check is - * executed when updating. + * It merges an entity. + * + * The caller must discard the reference passed as a parameter and work with the returned reference. + * Merging is analternative technique to reattachment with save, + * which must be used when it cannot be assessed another instance with the same identifier + * as the one passed as a parameter already exists in the underlying ORM session. + * + * Like save, version check is executed when updating. *

- * Since the caller must discard the reference passed as a parameter and - * work with the returned reference, merging is a technique more complicated - * than reattachmnent. Reattachment (by using save and/or - * reattachUnmodifiedEntity) should be the preferred technique. + * Since the caller must discard the reference passed as a parameter and work with the returned reference, + * merging is a technique more complicated than reattachment. + * Reattachment (by using save and/or reattachUnmodifiedEntity) + * should be the preferred technique. * * @param entity */ - public E merge(E entity); + E merge(E entity); /** - * It checks if the version of the instance passed as a parameter is equal - * to the one in the database. The instance must have methods conforming to - * the following signatures: java.io.Serializable getId() (to - * get the key) and [long|Long] getVersion() (to get the - * version). + * It checks if the version of the instance passed as a parameter is equal to the one in the database. + * + * The instance must have methods conforming to the following signatures: + * java.io.Serializable getId() (to get the key) and [long|Long] getVersion() + * (to get the version). *
* If the check is not passed, - * org.springframework.dao.OptimisticLockingFailureException - * is thrown. If the key or the version of the entity is null, - * or the entity does not exist in database, the check is considered to be - * successful. This lets client code to treat creation and modification of - * instances in a unified way. + * org.springframework.dao.OptimisticLockingFailureException is thrown. + * + * If the key or the version of the entity is null, or the entity does not exist in database, + * the check is considered to be successful. + * + * This lets client code to treat creation and modification of instances in a unified way. */ - public void checkVersion(E entity); + void checkVersion(E entity); /** - * It sets a WRITE lock on the instance passed as a parameter, causing the - * same kind of reattachment as reattachUnmodifiedEntity. - * Other concurrent transactions will be blocked if they try to write or - * set a WRITE lock (but they can read) on the same persistent instance. If - * the version field is not equal to the one in the database, - * org.springframework.dao.OptimisticLockingFailureException - * is thrown. The lock is released when the transaction finishes. + * It sets a WRITE lock on the instance passed as a parameter, causing the same kind of reattachment + * as reattachUnmodifiedEntity. + * + * Other concurrent transactions will be blocked if they try to write or set a WRITE lock + * (but they can read) on the same persistent instance. + * + * If the version field is not equal to the one in the database, + * org.springframework.dao.OptimisticLockingFailureException is thrown. + * The lock is released when the transaction finishes. *

* The intended use of this method is to enable pessimistic locking when - * the version check mechanism is not enough for controlling concurrent - * access. Most concurrent cases can be automatically managed with the usual - * version check mechanism. + * the version check mechanism is not enough for controlling concurrent access. + * + * Most concurrent cases can be automatically managed with the usual version check mechanism. */ - public void lock(E entity); + void lock(E entity); - public E find(PK id) throws InstanceNotFoundException; + E find(PK id) throws InstanceNotFoundException; /** - * Unlike find(PK), it returns a runtime exception if the - * entity does not exist. So, this method should be used when the entity - * with the key passed as a parameter is supposed to exist. + * Unlike find(PK), it returns a runtime exception if the entity does not exist. + * So, this method should be used when the entity with the key passed as a parameter is supposed to exist. */ - public E findExistingEntity(PK id); + E findExistingEntity(PK id); - public boolean exists(PK id); + boolean exists(PK id); - public void remove(PK id) throws InstanceNotFoundException; + void remove(PK id) throws InstanceNotFoundException; - public List list(Class klass); + List list(Class klass); - public void flush(); + void flush(); } diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java index 817fb4dc2..747de25b1 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailNotification.java @@ -32,8 +32,8 @@ import java.util.Date; * It represents the Email notification to be send to user. * * Created by - * @author Vova Perebykivskiy - * on 19.10.15. + * @author Vova Perebykivskyi + * on 19.10.2015. */ public class EmailNotification extends BaseEntity { diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java index 6ba95b0dd..10b56d801 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplate.java @@ -28,7 +28,7 @@ import org.libreplan.business.settings.entities.Language; * It represents the E-mail template to be modified by admin and send to user. * * Created by - * @author Vova Perebykivskiy + * @author Vova Perebykivskyi * on 29.09.2015. */ public class EmailTemplate extends BaseEntity { diff --git a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java index 74e4f7ac0..38c67cef5 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java +++ b/libreplan-business/src/main/java/org/libreplan/business/email/entities/EmailTemplateEnum.java @@ -25,7 +25,7 @@ import static org.libreplan.business.i18n.I18nHelper._; * Available E-mail templates. * * Created by - * @author Vova Perebykivskiy + * @author Vova Perebykivskyi * on 28.09.2015. * * TEMPLATE_N(_("Template N")) - for i18n diff --git a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CommunicationType.java b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CommunicationType.java index 48ce55856..606fcd358 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CommunicationType.java +++ b/libreplan-business/src/main/java/org/libreplan/business/externalcompanies/entities/CommunicationType.java @@ -28,12 +28,14 @@ import static org.libreplan.business.i18n.I18nHelper._; */ public enum CommunicationType { - NEW_PROJECT(_("New project")), PROGRESS_UPDATE(_("Progress Update")), UPDATE_DELIVERING_DATE( - _("Update Delivering Date")), END_DATE_UPDATE(_("End date update")); + NEW_PROJECT(_("New project")), + PROGRESS_UPDATE(_("Progress Update")), + UPDATE_DELIVERING_DATE(_("Update Delivering Date")), + END_DATE_UPDATE(_("End date update")); private String description; - private CommunicationType(String description) { + CommunicationType(String description) { this.description = description; } diff --git a/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/HibernateDatabaseModificationsListener.java b/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/HibernateDatabaseModificationsListener.java index f6ee45d82..78aff0fed 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/HibernateDatabaseModificationsListener.java +++ b/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/HibernateDatabaseModificationsListener.java @@ -58,45 +58,45 @@ import org.springframework.stereotype.Component; /** * @author Óscar González Fernández - * */ @Component public class HibernateDatabaseModificationsListener implements - PostInsertEventListener, PostUpdateEventListener, - PostDeleteEventListener, ISnapshotRefresherService { + PostInsertEventListener, + PostUpdateEventListener, + PostDeleteEventListener, + ISnapshotRefresherService { - private static final Log LOG = LogFactory - .getLog(HibernateDatabaseModificationsListener.class); + private static final Log LOG = LogFactory.getLog(HibernateDatabaseModificationsListener.class); private final ExecutorService executor = Executors.newFixedThreadPool(3); private final ConcurrentMap, BlockingQueue>> interested; - private ConcurrentMap pending = new ConcurrentHashMap(); + private ConcurrentMap pending = new ConcurrentHashMap<>(); - private Set> snapshotsInterestedOn( - Class entityClass) { - List> list = new ArrayList>(1); + private Set> snapshotsInterestedOn(Class entityClass) { + List> list = new ArrayList<>(1); list.add(entityClass); + return snapshotsInterestedOn(list); } - private Set> snapshotsInterestedOn( - Collection> classesList) { - Set> result = new HashSet>(); - for (Class each : new HashSet>(classesList)) { - BlockingQueue> queue = interested - .get(each); - if (queue != null) { + private Set> snapshotsInterestedOn(Collection> classesList) { + Set> result = new HashSet<>(); + + for (Class each : new HashSet<>(classesList)) { + BlockingQueue> queue = interested.get(each); + if ( queue != null ) { result.addAll(queue); } } + return result; } private final class Dispatcher implements Synchronization { - private BlockingQueue> classes = new LinkedBlockingQueue>(); + private BlockingQueue> classes = new LinkedBlockingQueue<>(); private final Transaction transaction; public Dispatcher(Transaction transaction, Class entityClass) { @@ -116,21 +116,22 @@ public class HibernateDatabaseModificationsListener implements public void afterCompletion(int status) { LOG.debug("transaction completed with status: " + status); pending.remove(transaction); - if (isProbablySucessful(status)) { - List> list = new ArrayList>(); + + if ( isProbablySucessful(status) ) { + List> list = new ArrayList<>(); classes.drainTo(list); LOG.debug(list.size() + " modification events recorded"); Set> toDispatch = snapshotsInterestedOn(list); - LOG.debug("dispatching " - + toDispatch - + " snapshots to reload due to transaction successful completion"); + + LOG.debug( + "dispatching " + toDispatch + " snapshots to reload due to transaction successful completion"); + dispatch(toDispatch); } } private boolean isProbablySucessful(int status) { - return status != Status.STATUS_ROLLEDBACK - && status != Status.STATUS_ROLLING_BACK; + return status != Status.STATUS_ROLLEDBACK && status != Status.STATUS_ROLLING_BACK; } } @@ -141,7 +142,7 @@ public class HibernateDatabaseModificationsListener implements private volatile boolean hibernateListenersRegistered = false; public HibernateDatabaseModificationsListener() { - interested = new ConcurrentHashMap, BlockingQueue>>(); + interested = new ConcurrentHashMap<>(); } @PostConstruct @@ -163,20 +164,17 @@ public class HibernateDatabaseModificationsListener implements @Override public void onPostDelete(PostDeleteEvent event) { - modificationOn(inferTransaction(event), - inferEntityClass(getEntityObject(event))); + modificationOn(inferTransaction(event), inferEntityClass(getEntityObject(event))); } @Override public void onPostUpdate(PostUpdateEvent event) { - modificationOn(inferTransaction(event), - inferEntityClass(getEntityObject(event))); + modificationOn(inferTransaction(event), inferEntityClass(getEntityObject(event))); } @Override public void onPostInsert(PostInsertEvent event) { - modificationOn(inferTransaction(event), - inferEntityClass(getEntityObject(event))); + modificationOn(inferTransaction(event), inferEntityClass(getEntityObject(event))); } @@ -197,24 +195,27 @@ public class HibernateDatabaseModificationsListener implements } private static Class inferEntityClass(Object entity) { - if (entity instanceof HibernateProxy) { + if ( entity instanceof HibernateProxy ) { HibernateProxy proxy = (HibernateProxy) entity; + return proxy.getHibernateLazyInitializer().getPersistentClass(); } + return entity.getClass(); } void modificationOn(Transaction transaction, Class entityClass) { - if (transaction == null) { + if ( transaction == null ) { dispatch(snapshotsInterestedOn(entityClass)); + return; } Dispatcher newDispatcher = new Dispatcher(transaction, entityClass); - Dispatcher previous = null; + Dispatcher previous; previous = pending.putIfAbsent(transaction, newDispatcher); boolean dispatcherAlreadyExisted = previous != null; - if (dispatcherAlreadyExisted) { + if ( dispatcherAlreadyExisted ) { previous.add(entityClass); } else { transaction.registerSynchronization(newDispatcher); @@ -222,9 +223,7 @@ public class HibernateDatabaseModificationsListener implements } private void dispatch(Set> toBeDispatched) { - for (NotBlockingAutoUpdatedSnapshot each : toBeDispatched) { - dispatch(each); - } + toBeDispatched.forEach(this::dispatch); } private void dispatch(NotBlockingAutoUpdatedSnapshot each) { @@ -232,28 +231,28 @@ public class HibernateDatabaseModificationsListener implements } @Override - public IAutoUpdatedSnapshot takeSnapshot(String name, - Callable callable, ReloadOn reloadOn) { - if (!hibernateListenersRegistered) { + public IAutoUpdatedSnapshot takeSnapshot(String name, Callable callable, ReloadOn reloadOn) { + if ( !hibernateListenersRegistered ) { throw new IllegalStateException( "The hibernate listeners has not been registered. There is some configuration problem."); } final NotBlockingAutoUpdatedSnapshot result; - result = new NotBlockingAutoUpdatedSnapshot(name, callable); + result = new NotBlockingAutoUpdatedSnapshot<>(name, callable); + for (Class each : reloadOn.getClassesOnWhichToReload()) { interested.putIfAbsent(each, emptyQueue()); - BlockingQueue> queue = interested - .get(each); + BlockingQueue> queue = interested.get(each); boolean success = queue.add(result); assert success : "the type of queue used must not have restricted capacity"; } result.ensureFirstLoad(executor); + return result; } private BlockingQueue> emptyQueue() { - return new LinkedBlockingQueue>(); + return new LinkedBlockingQueue<>(); } } diff --git a/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/PredefinedDatabaseSnapshots.java b/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/PredefinedDatabaseSnapshots.java index c5a8b5f32..6806a4a2f 100644 --- a/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/PredefinedDatabaseSnapshots.java +++ b/libreplan-business/src/main/java/org/libreplan/business/hibernate/notification/PredefinedDatabaseSnapshots.java @@ -80,14 +80,12 @@ import org.springframework.stereotype.Component; /** * @author Óscar González Fernández - * */ @Component @Scope(BeanDefinition.SCOPE_SINGLETON) public class PredefinedDatabaseSnapshots { - private static final Log LOG = LogFactory - .getLog(PredefinedDatabaseSnapshots.class); + private static final Log LOG = LogFactory.getLog(PredefinedDatabaseSnapshots.class); @Autowired private IAdHocTransactionService transactionService; @@ -179,59 +177,69 @@ public class PredefinedDatabaseSnapshots { private boolean snapshotsRegistered = false; public void registerSnapshots() { - if (snapshotsRegistered) { + if ( snapshotsRegistered ) { LOG.warn("snapshots have already been registered"); + return; } + snapshotsRegistered = true; - criterionsMap = snapshot("criterions map", calculateCriterionsMap(), - CriterionType.class, Criterion.class); - labelsMap = snapshot("labels map", calculateLabelsMap(), - LabelType.class, Label.class); + criterionsMap = snapshot("criterions map", calculateCriterionsMap(), CriterionType.class, Criterion.class); + labelsMap = snapshot("labels map", calculateLabelsMap(), LabelType.class, Label.class); listWorkers = snapshot("workers", calculateWorkers(), Worker.class); - listCostCategories = snapshot("list cost categories", - calculateListCostCategories(), - CostCategory.class); - listCriterion = snapshot("list criterions", calculateListCriterion(), - Criterion.class); - mapResources = snapshot("map resources", calculateMapResources(), - Resource.class, Worker.class, Machine.class, + listCostCategories = snapshot("list cost categories", calculateListCostCategories(), CostCategory.class); + listCriterion = snapshot("list criterions", calculateListCriterion(), Criterion.class); + + mapResources = snapshot( + "map resources", + calculateMapResources(), + Resource.class, + Worker.class, + Machine.class, VirtualWorker.class); - externalCompanies = snapshot("external companies", - calculateExternalCompanies(), - ExternalCompany.class); - customerReferences = snapshot("customer references", - calculateCustomerReferences(), Order.class); - ordersCodes = snapshot("order codes", calculateOrdersCodes(), - Order.class); - resourceLoadChartData = snapshot("resource load grouped by date", + + externalCompanies = snapshot("external companies", calculateExternalCompanies(), ExternalCompany.class); + customerReferences = snapshot("customer references", calculateCustomerReferences(), Order.class); + ordersCodes = snapshot("order codes", calculateOrdersCodes(), Order.class); + + resourceLoadChartData = snapshot( + "resource load grouped by date", calculateResourceLoadChartData(), - CalendarAvailability.class, CalendarException.class, - CalendarData.class, TaskElement.class, SpecificResourceAllocation.class, - GenericResourceAllocation.class, ResourceAllocation.class); - workReportLines = snapshot("work report lines", calculateWorkReportLines(), - WorkReportLine.class); - estimatedCostPerTask = snapshot("estimated cost per task", + CalendarAvailability.class, + CalendarException.class, + CalendarData.class, + TaskElement.class, + SpecificResourceAllocation.class, + GenericResourceAllocation.class, + ResourceAllocation.class); + + workReportLines = snapshot("work report lines", calculateWorkReportLines(), WorkReportLine.class); + + estimatedCostPerTask = snapshot( + "estimated cost per task", calculateEstimatedCostPerTask(), - TaskElement.class, Task.class, TaskGroup.class, DayAssignment.class); - advanceCostPerTask = snapshot("advance cost per task", + TaskElement.class, + Task.class, + TaskGroup.class, + DayAssignment.class); + + advanceCostPerTask = snapshot( + "advance cost per task", calculateAdvanceCostPerTask(), - TaskElement.class, Task.class, TaskGroup.class, + TaskElement.class, + Task.class, + TaskGroup.class, DirectAdvanceAssignment.class); } - private IAutoUpdatedSnapshot snapshot(String name, - Callable callable, - Class... reloadOnChangesOf) { - return snapshotRefresherService.takeSnapshot(name, - callableOnReadOnlyTransaction(callable), - ReloadOn.onChangeOf(reloadOnChangesOf)); + private IAutoUpdatedSnapshot snapshot(String name, Callable callable, Class... reloadOnChangesOf) { + return snapshotRefresherService + .takeSnapshot(name, callableOnReadOnlyTransaction(callable), ReloadOn.onChangeOf(reloadOnChangesOf)); } @SuppressWarnings("unchecked") private Callable callableOnReadOnlyTransaction(Callable callable) { - return AdHocTransactionService.readOnlyProxy(transactionService, - Callable.class, callable); + return AdHocTransactionService.readOnlyProxy(transactionService, Callable.class, callable); } @Autowired @@ -241,31 +249,20 @@ public class PredefinedDatabaseSnapshots { private ICriterionDAO criterionDAO; private Callable>> calculateCriterionsMap() { - return new Callable>>() { - @Override - public SortedMap> call() { - SortedMap> result = new TreeMap>( - getComparatorByName()); - for (CriterionType criterionType : criterionTypeDAO - .getSortedCriterionTypes()) { - if (criterionType.isEnabled()) { - List criterions = criterionType - .getSortCriterions(); - result.put(criterionType, criterions); - } + return () -> { + SortedMap> result = new TreeMap<>(getComparatorByName()); + for (CriterionType criterionType : criterionTypeDAO.getSortedCriterionTypes()) { + if ( criterionType.isEnabled() ) { + List criterions = criterionType.getSortCriterions(); + result.put(criterionType, criterions); } - return result; } + return result; }; } private Comparator getComparatorByName(){ - return new Comparator() { - @Override - public int compare(CriterionType arg0, CriterionType arg1) { - return (arg0.getName().compareTo(arg1.getName())); - } - }; + return (arg0, arg1) -> (arg0.getName().compareTo(arg1.getName())); } @Autowired @@ -275,17 +272,13 @@ public class PredefinedDatabaseSnapshots { private ILabelDAO labelDAO; private Callable>> calculateLabelsMap() { - return new Callable>>() { - @Override - public Map> call() { - Map> result = new HashMap>(); - for (LabelType labelType : labelTypeDAO.getAll()) { - List