ItEr39S16CUConfiguracionMaquinasItEr35S09: Fixing wrong assertion. The resource must be a worker.

This commit is contained in:
Óscar González Fernández 2009-12-19 21:25:20 +01:00
parent 97470cf0c4
commit bf72c68318
3 changed files with 10 additions and 14 deletions

View file

@ -111,12 +111,6 @@ public class DerivedAllocation extends BaseEntity {
private void checkIsValid(DerivedDayAssignment dayAssingment) {
Machine machine = configurationUnit.getMachine();
if (!dayAssingment.getResource().equals(machine)) {
throw new IllegalArgumentException(dayAssingment
+ " has the resource: " + dayAssingment.getResource()
+ " but this derived allocation has the resource: "
+ machine);
}
if (!dayAssingment.getAllocation().equals(this)) {
throw new IllegalArgumentException(dayAssingment
+ " is related to " + dayAssingment.getAllocation()

View file

@ -22,8 +22,8 @@ package org.navalplanner.business.planner.entities;
import org.apache.commons.lang.Validate;
import org.hibernate.validator.NotNull;
import org.joda.time.LocalDate;
import org.navalplanner.business.resources.entities.Machine;
import org.navalplanner.business.resources.entities.Resource;
import org.navalplanner.business.resources.entities.Worker;
/**
@ -51,7 +51,7 @@ public class DerivedDayAssignment extends DayAssignment {
DerivedAllocation derivedAllocation) {
super(day, hours, resource);
Validate.notNull(derivedAllocation);
Validate.isTrue(resource instanceof Machine);
Validate.isTrue(resource instanceof Worker);
this.allocation = derivedAllocation;
}

View file

@ -49,6 +49,8 @@ import org.navalplanner.business.resources.entities.Worker;
*/
public class DerivedAllocationTest {
private Worker worker = Worker.create();
private Machine machine = Machine.create();
private MachineWorkersConfigurationUnit configurationUnit;
@ -165,7 +167,7 @@ public class DerivedAllocationTest {
@Test
public void aDerivedAllocationCanBeResetToSomeDayAssignmentsAndIsOrderedByDay() {
givenADerivedAllocation();
givenDayAssignments(new LocalDate(2008, 12, 1), machine, 8, 8, 8, 8);
givenDayAssignments(new LocalDate(2008, 12, 1), worker, 8, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
assertThat(derivedAllocation.getAssignments(), equalTo(dayAssignments));
}
@ -184,7 +186,7 @@ public class DerivedAllocationTest {
givenADerivedAllocation();
DerivedAllocation another = DerivedAllocation.create(derivedFrom,
configurationUnit);
givenDayAssignments(another, new LocalDate(2008, 12, 1), machine, 8, 8,
givenDayAssignments(another, new LocalDate(2008, 12, 1), worker, 8, 8,
8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
}
@ -193,12 +195,12 @@ public class DerivedAllocationTest {
public void theAssignmentsCanBeResetOnAnInterval() {
givenADerivedAllocation();
LocalDate start = new LocalDate(2008, 12, 1);
givenDayAssignments(start, machine, 8, 8, 8, 8);
givenDayAssignments(start, worker, 8, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
final LocalDate startInterval = start.plusDays(2);
final LocalDate finishInterval = start.plusDays(4);
DerivedDayAssignment newAssignment = DerivedDayAssignment.create(
startInterval, 3, machine, derivedAllocation);
startInterval, 3, worker, derivedAllocation);
derivedAllocation.resetAssignmentsTo(startInterval, finishInterval,
Arrays.asList(newAssignment));
assertThat(derivedAllocation.getAssignments(), equalTo(Arrays.asList(
@ -209,10 +211,10 @@ public class DerivedAllocationTest {
public void whenResettingAssignmentsOnIntervalOnlyTheOnesAtTheIntervalAreAdded() {
givenADerivedAllocation();
LocalDate start = new LocalDate(2008, 12, 1);
givenDayAssignments(start, machine, 8, 8, 8, 8);
givenDayAssignments(start, worker, 8, 8, 8, 8);
derivedAllocation.resetAssignmentsTo(dayAssignments);
DerivedDayAssignment newAssignment = DerivedDayAssignment.create(start
.minusDays(1), 3, machine, derivedAllocation);
.minusDays(1), 3, worker, derivedAllocation);
derivedAllocation.resetAssignmentsTo(start, start.plusDays(4), Arrays
.asList(newAssignment));
assertTrue(derivedAllocation.getAssignments().isEmpty());