From ace29f38ea5033db1ed347c8068f897530863b0d Mon Sep 17 00:00:00 2001 From: Shailendra Borale Date: Wed, 28 Mar 2018 22:33:37 -0400 Subject: [PATCH] Add junit coverage to Time class Introduce junit-tests for Time class, corrected license Change-Id: If5c3771325d4945f6f1135cfb4df8e923d0a0663 Issue-ID: APPC-809 Signed-off-by: Shailendra Borale --- .../src/test/java/org/onap/appc/util/TimeTest.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 appc-common/src/test/java/org/onap/appc/util/TimeTest.java diff --git a/appc-common/src/test/java/org/onap/appc/util/TimeTest.java b/appc-common/src/test/java/org/onap/appc/util/TimeTest.java new file mode 100644 index 000000000..ab01ad24b --- /dev/null +++ b/appc-common/src/test/java/org/onap/appc/util/TimeTest.java @@ -0,0 +1,79 @@ +/* + * ============LICENSE_START======================================================= + * ONAP : APPC + * ================================================================================ + * Copyright (C) 2018 + * ============================================================================= + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * ============LICENSE_END========================================================= + */ + + +package org.onap.appc.util; + +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import java.time.ZoneOffset; +import java.time.ZonedDateTime; +import java.util.Calendar; +import java.util.Date; + + +public class TimeTest { + + @Test + public void testAddTime() { + + final Date dateNow = new Date(); + long dateNowMSec = dateNow.getTime(); + Date dateSecLater = Time.addTime(dateNow, 0, 0, 0, 0, 1); + long dateSecLaterMSec = dateSecLater.getTime(); + assertEquals(dateNowMSec + 1000, dateSecLaterMSec); + + } + + @Test + public void testDateOnly() { + + final Date dateNow = new Date(); + Calendar cal = Calendar.getInstance(); + cal.setTime(dateNow); + + Time.dateOnly(cal); + + long msecFromBegin = cal.get(Calendar.HOUR_OF_DAY)*60*60*1000 + + cal.get(Calendar.MINUTE)*60*1000 + + cal.get(Calendar.SECOND)*1000 + + cal.get(Calendar.MILLISECOND); + + assertEquals( msecFromBegin, 0); + + } + + @Test + public void testGetCurrentUTCDate() { + + Date utcDate = Time.getCurrentUTCDate(); + + ZonedDateTime utc = ZonedDateTime.now(ZoneOffset.UTC); + + long epochSecs = utc.toEpochSecond(); + + long utcSecs = utcDate.getTime() / 1000; + + assertEquals(epochSecs, utcSecs); + } + +} -- 2.16.6