summaryrefslogtreecommitdiffstats
path: root/appc-common/src
diff options
context:
space:
mode:
authorShailendra Borale <sb8915@att.com>2018-03-28 22:33:37 -0400
committerRanda Maher <rx196w@att.com>2018-03-29 16:25:17 +0000
commitace29f38ea5033db1ed347c8068f897530863b0d (patch)
treebb3345602094df8131cffadd814122ddfd3ea4fc /appc-common/src
parente6c85550e118063b075f7d33678fc1720d13b940 (diff)
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 <sb8915@att.com>
Diffstat (limited to 'appc-common/src')
-rw-r--r--appc-common/src/test/java/org/onap/appc/util/TimeTest.java79
1 files changed, 79 insertions, 0 deletions
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);
+ }
+
+}