package com.trafficaudit.holiday.service;
|
|
import org.junit.jupiter.api.Test;
|
|
import java.lang.reflect.Method;
|
import java.math.BigDecimal;
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
class HolidayBulletinServiceTest {
|
|
@Test
|
void formatsTableRatiosAsSignedPercentages() throws Exception {
|
HolidayBulletinService service = new HolidayBulletinService(null);
|
|
assertEquals("-4.7%", ratio(service, "95.3", "100"));
|
assertEquals("1.0%", ratio(service, "101", "100"));
|
assertEquals("0%", ratio(service, "100", "100"));
|
assertEquals("0%", ratio(service, "10004", "10000"));
|
assertEquals("—", ratio(service, "100", null));
|
assertEquals("—", ratio(service, "100", "0"));
|
}
|
|
private String ratio(HolidayBulletinService service, String current, String base) throws Exception {
|
Method method = HolidayBulletinService.class.getDeclaredMethod("ratio", BigDecimal.class, BigDecimal.class);
|
method.setAccessible(true);
|
BigDecimal currentValue = current == null ? null : new BigDecimal(current);
|
BigDecimal baseValue = base == null ? null : new BigDecimal(base);
|
return (String) method.invoke(service, currentValue, baseValue);
|
}
|
}
|