ItEr43S09ImplantacionAplicacionItEr42S13: [Bug #230] Fixing bug.

Returning at least one hours if the result is any bigger than zero
This commit is contained in:
Óscar González Fernández 2010-01-11 21:33:15 +01:00
parent e4629fd3fb
commit a926da8688
2 changed files with 23 additions and 2 deletions

View file

@ -101,8 +101,14 @@ public class ResourcesPerDay {
public int asHoursGivenResourceWorkingDayOf(
Integer resourceWorkingDayHours) {
return getAmount().multiply(new BigDecimal(resourceWorkingDayHours))
.setScale(0, RoundingMode.HALF_UP).intValue();
BigDecimal multiply = getAmount().multiply(
new BigDecimal(resourceWorkingDayHours));
if(multiply.compareTo(BigDecimal.ZERO)>0){
return Math.max(1, multiply.setScale(0, RoundingMode.HALF_UP)
.intValue());
} else {
return 0;
}
}
@Override

View file

@ -128,6 +128,21 @@ public class ResourcesPerDayTest {
assertEquals(a, b);
}
@Test
public void asHoursMustReturnOneIfAmountIsGreaterThanZero() {
ResourcesPerDay amount = ResourcesPerDay.amount(new BigDecimal(0.05));
int hours = amount
.asHoursGivenResourceWorkingDayOf(8);
assertThat(hours, equalTo(1));
}
@Test
public void ifTheAmountIsZeroMustReturnZero() {
ResourcesPerDay amount = ResourcesPerDay.amount(BigDecimal.ZERO);
int hours = amount.asHoursGivenResourceWorkingDayOf(8);
assertThat(hours, equalTo(0));
}
@Test
public void isZeroIfHaveZeroValue() {
BigDecimal[] examples = { new BigDecimal(0.0001), new BigDecimal(0),