ItEr27S07CUVistaRecursosTempoPorProxectoItEr26S08: Adding method to check if a ResourcesPerDay has a zero amount

This commit is contained in:
Óscar González Fernández 2009-09-28 18:27:25 +02:00
parent 49ba6a45d4
commit 740192980d
2 changed files with 25 additions and 0 deletions

View file

@ -48,4 +48,9 @@ public class ResourcesPerDay {
return false;
}
public boolean isZero() {
BigDecimal withoutDecimalpart = amount.movePointRight(2);
return withoutDecimalpart.intValue() == 0;
}
}

View file

@ -2,7 +2,9 @@ package org.navalplanner.business.test.planner.entities;
import static org.hamcrest.CoreMatchers.equalTo;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.math.BigDecimal;
@ -95,4 +97,22 @@ public class ResourcesPerDayTest {
assertEquals(a, b);
}
@Test
public void isZeroIfHaveZeroValue() {
BigDecimal[] examples = { new BigDecimal(0.0001), new BigDecimal(0),
new BigDecimal(00), new BigDecimal(0.00) };
for (BigDecimal example : examples) {
assertTrue(ResourcesPerDay.amount(example).isZero());
}
}
@Test
public void notZeroIfNoZeroValue() {
BigDecimal[] examples = { new BigDecimal(0.01), new BigDecimal(0.009),
new BigDecimal(1), new BigDecimal(0.10) };
for (BigDecimal example : examples) {
assertFalse(ResourcesPerDay.amount(example).isZero());
}
}
}