В игре 1.2.4, когда вы расширили свой тестовый класс с помощью UnitTest сеттеров объекта домена, который вызывался во время теста, в игре 2.0 они не вызываются (см. Пример ниже).Что я делаю не так?
Пример:
@Embeddable
public class Amount {
public static Amount zero() {
Amount amount = new Amount();
//setValue should be called here by play framework
amount.value = BigDecimal.ZERO;
return amount;
}
public static Amount of(double amount) {
Amount result = new Amount();
//setValue should be called here by play framework
result.value = BigDecimal.valueOf(amount);
return result;
}
public BigDecimal value;
public void setValue(BigDecimal value) {
this.value = rounded(value);
}
public Amount add(Amount amount) {
Amount result = new Amount();
result.value = rounded(this.value.add(amount.value));
return result;
}
private BigDecimal rounded(BigDecimal aNumber){
return aNumber.setScale(2, RoundingMode.HALF_EVEN);
}
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((value == null) ? 0 : value.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
Amount other = (Amount) obj;
if (value == null) {
if (other.value != null)
return false;
} else if (!value.equals(other.value))
return false;
return true;
}
@Override
public String toString() {
return "Amount [value=" + value + "]";
}
}
тест в 1.2.4 завершается успешно => setValue вызывается из суммы
public class AmountTest extends UnitTest {
@Test
public void shouldBeAbleToRoundedHalfEven(){
Assertions.assertThat(Amount.of(1.055)).isEqualTo(Amount.of(1.06));
Assertions.assertThat(Amount.of(1.025)).isEqualTo(Amount.of(1.02));
Assertions.assertThat(Amount.of(1.016)).isEqualTo(Amount.of(1.02));
Assertions.assertThat(Amount.of(1.011)).isEqualTo(Amount.of(1.01));
Assertions.assertThat(Amount.of(1.010)).isEqualTo(Amount.of(1.01));
}
}
тест в 2.0 не выполняется, потому чтоsetValue не вызывается
public class AmountTest {
@Test
public void shouldBeAbleToRoundedHalfEven(){
running(fakeApplication(), new Runnable() {
public void run() {
assertThat(Amount.of(1.055)).isEqualTo(Amount.of(1.06));
assertThat(Amount.of(1.025)).isEqualTo(Amount.of(1.02));
assertThat(Amount.of(1.016)).isEqualTo(Amount.of(1.02));
assertThat(Amount.of(1.011)).isEqualTo(Amount.of(1.01));
assertThat(Amount.of(1.010)).isEqualTo(Amount.of(1.01));
}
});
}
}