ItEr16S12CreacionProxectoPlanificacion: Checking some conditions when creating dependency.
This commit is contained in:
parent
cbde05db74
commit
6ba76c5515
2 changed files with 34 additions and 2 deletions
|
|
@ -1,5 +1,7 @@
|
|||
package org.navalplanner.business.planner.entities;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
|
||||
/**
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
|
|
@ -29,9 +31,14 @@ public class Dependency {
|
|||
public Dependency() {
|
||||
}
|
||||
|
||||
private Dependency(TaskElement origin, TaskElement end, Type type) {
|
||||
private Dependency(TaskElement origin, TaskElement destination, Type type) {
|
||||
Validate.notNull(origin);
|
||||
Validate.notNull(destination);
|
||||
Validate.notNull(type);
|
||||
Validate.isTrue(!origin.equals(destination),
|
||||
"a dependency must have a different origin than destination");
|
||||
this.origin = origin;
|
||||
this.destination = end;
|
||||
this.destination = destination;
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ import static org.hamcrest.CoreMatchers.equalTo;
|
|||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.navalplanner.business.planner.entities.Dependency;
|
||||
|
|
@ -41,6 +42,30 @@ public class DependencyTest {
|
|||
assertThat(dependency.getType(), equalTo(type));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void mustNotAllowANullValuesForAnyOfTheCreationArguments() {
|
||||
Object[] arguments = { origin, destination, type };
|
||||
for (int i = 0; i < arguments.length; i++) {
|
||||
Object[] cloned = arguments.clone();
|
||||
cloned[i] = null;
|
||||
TaskElement origin = (TaskElement) cloned[0];
|
||||
TaskElement destination = (TaskElement) cloned[1];
|
||||
Type type = (Type) cloned[2];
|
||||
try {
|
||||
Dependency.createDependency(origin, destination, type);
|
||||
fail("must send IllegalArgumentException");
|
||||
} catch (IllegalArgumentException e) {
|
||||
// ok
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void dependencyMustNotAllowTheSameOriginAndDestination() {
|
||||
Dependency.createDependency(origin, origin, type);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void creatingDependencyImpliesAssociatingItWithTheRelatedTasks() {
|
||||
assertFalse(origin.getDependenciesWithThisDestination().contains(
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue