diff options
Diffstat (limited to 'appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java')
-rw-r--r-- | appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java | 56 |
1 files changed, 31 insertions, 25 deletions
diff --git a/appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java b/appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java index 3a73d7a2c..129a4aef1 100644 --- a/appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java +++ b/appc-core/appc-common-bundle/src/test/java/org/onap/appc/util/TimeTest.java @@ -5,6 +5,8 @@ * Copyright (C) 2017-2018 AT&T Intellectual Property. All rights reserved. * ================================================================================ * Modifications Copyright (C) 2018 IBM + * ================================================================================ + * Modifications Copyright (C) 2019 Ericsson * ============================================================================= * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,6 +31,8 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; import java.text.ParseException; +import java.time.LocalDate; +import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.Calendar; @@ -46,6 +50,10 @@ import org.junit.Test; public class TimeTest { + private final Date dateForTests = Date.from(LocalDate.of(2004, 2, 9) + .atStartOfDay(ZoneId.systemDefault()).toInstant()); + + @Test public void testAddTime() { @@ -78,10 +86,8 @@ public class TimeTest { @Test public void testGetCurrentUTCDate() { - Date utcDate = Time.getCurrentUTCDate(); - ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC); - + Date utcDate = Date.from(utc.toInstant()); long epochSecs = utc.toEpochSecond(); long utcSecs = utcDate.getTime() / 1000; @@ -94,78 +100,78 @@ public class TimeTest { final Date dateNow = new Date(); assertTrue(Time.endOfDayLocal(dateNow) instanceof Date); } - + @Test public void testGetDateByLocaleAndTimeZone() { - final Date dateNow = new Date("19-Jul-2018"); + final Date dateNow = new Date(); Locale locale = new Locale("fr"); TimeZone timeZone = TimeZone.getTimeZone("Europe/France"); assertNotNull(Time.getDateByLocaleAndTimeZone(dateNow,locale,timeZone)); assertTrue(Time.getDateByLocaleAndTimeZone(dateNow,locale,timeZone) instanceof String); } - + @Test public void testUtcFormat() { - final Date date = new Date("19-Jul-2018"); + final Date date = new Date(); assertNotNull(Time.utcFormat(date)); assertTrue(Time.utcFormat(date) instanceof String); } - + //this test succeeds if localTime() does not throw an exception @Test public void testLocalTime() { Time.localTime(1532083631); } - + @Test public void testSetDate() { Calendar cal = Calendar.getInstance(); cal.set(Calendar.YEAR, 2018); cal.set(Calendar.MONTH, 07); cal.set(Calendar.DAY_OF_MONTH, 03); - Calendar cal1= Time.setDate(cal, 2018, 07, 03); + Calendar cal1 = Time.setDate(cal, 2018, 07, 03); assertEquals(cal, cal1); } - + @Test public void testStartOfDayLocal() { assertTrue(Time.startOfDayLocal() instanceof Date); } - + @Test public void testTimeStamp() { assertTrue(Time.timestamp() instanceof XMLGregorianCalendar); } - + @Test public void testDateToStringConverterMillis() { - String dateString=Time.dateToStringConverterMillis(new Date("02/09/2004")); - String expected="2004-02-09 00:00:00:000"; + String dateString = Time.dateToStringConverterMillis(dateForTests); + String expected = "2004-02-09 00:00:00:000"; assertEquals(expected, dateString); } - + @Test public void testStringToDateConverterMillis() throws ParseException{ - Date date=Time.stringToDateConverterMillis("2004-02-09 00:00:00:000"); - Date expected=new Date("02/09/2004"); + Date date = Time.stringToDateConverterMillis("2004-02-09 00:00:00:000"); + Date expected = dateForTests; assertEquals(expected, date); } - + @Test public void testTruncateDate() throws ParseException{ - Date date=Time.truncDate(new Date("02/09/2004")); - Date expected=new Date("02/09/2004"); + Date date = Time.truncDate(dateForTests); + Date expected = dateForTests; assertEquals(expected, date); } - + @Test public void testToDate() throws ParseException, DatatypeConfigurationException{ - Date date=new Date("02/09/2004"); + Date date = dateForTests; GregorianCalendar c = new GregorianCalendar(); c.setTime(date); XMLGregorianCalendar calendar = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); - Date actual= Time.toDate(calendar); - Date expected=new Date("02/09/2004"); + Date actual = Time.toDate(calendar); + Date expected = dateForTests; assertEquals(expected, actual); } } |