aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormark.j.leonard <mark.j.leonard@gmail.com>2018-10-24 17:29:41 +0100
committermark.j.leonard <mark.j.leonard@gmail.com>2018-10-24 17:29:41 +0100
commitc440925424eccd750b4971eb8a10e8ef32929e90 (patch)
tree81928b65f152cc98e618f713c72a4e5da8fa7609
parent2d688bf5cdcfe30447e83e6405c120b1d994922b (diff)
Fix JUnit test for the Info status report
The ZoneOffset was being applied twice, causing the number of hours added to a test Clock to be calculated incorrectly only when Daylight Savings changes were applied during the interval. For example, the status report was showing 4 days 23 hrs instead of 5 days when the clocks had been put back an hour. Change-Id: If6380a8901b2723018dd3a45fcd7df3ffa0168d4 Issue-ID: AAI-1766 Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
-rw-r--r--src/test/java/org/onap/aai/babel/service/TestInfoService.java14
1 files changed, 7 insertions, 7 deletions
diff --git a/src/test/java/org/onap/aai/babel/service/TestInfoService.java b/src/test/java/org/onap/aai/babel/service/TestInfoService.java
index b97aa92..647f1b0 100644
--- a/src/test/java/org/onap/aai/babel/service/TestInfoService.java
+++ b/src/test/java/org/onap/aai/babel/service/TestInfoService.java
@@ -26,7 +26,7 @@ import static org.junit.Assert.assertThat;
import java.time.Clock;
import java.time.LocalDateTime;
-import java.time.OffsetDateTime;
+import java.time.ZoneOffset;
import org.junit.Test;
public class TestInfoService {
@@ -42,28 +42,28 @@ public class TestInfoService {
@Test
public void testStatusReport() {
InfoService infoService = new InfoService();
- LocalDateTime now = LocalDateTime.now();
- Clock clock = buildClock(now);
+ LocalDateTime startTime = LocalDateTime.now();
+ Clock clock = buildClock(startTime);
String info = infoService.statusReport(clock);
assertThat(info, containsString("Started at"));
assertThat(info, containsString("total=1"));
// Skip ahead 1 day
- clock = buildClock(now.plusDays(1));
+ clock = buildClock(startTime.plusDays(1));
info = infoService.statusReport(clock);
assertThat(info, containsString("Up time 1 day "));
assertThat(info, containsString("total=2"));
// Skip ahead 5 days
- clock = buildClock(now.plusDays(5));
+ clock = buildClock(startTime.plusDays(5));
info = infoService.statusReport(clock);
assertThat(info, containsString("Up time 5 days "));
assertThat(info, containsString("total=3"));
}
- private Clock buildClock(LocalDateTime now) {
- return Clock.fixed(now.toInstant(OffsetDateTime.now().getOffset()), Clock.systemDefaultZone().getZone());
+ private Clock buildClock(LocalDateTime dateTime) {
+ return Clock.fixed(dateTime.toInstant(ZoneOffset.UTC), Clock.systemDefaultZone().getZone());
}
}