Fix JUnit test for the Info status report 66/71166/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Wed, 24 Oct 2018 16:29:41 +0000 (17:29 +0100)
committermark.j.leonard <mark.j.leonard@gmail.com>
Wed, 24 Oct 2018 16:29:41 +0000 (17:29 +0100)
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>
src/test/java/org/onap/aai/babel/service/TestInfoService.java

index b97aa92..647f1b0 100644 (file)
@@ -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());
     }
 
 }