2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017-2018 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 package org.onap.aai.util;
23 import static org.junit.Assert.assertEquals;
24 import static org.junit.Assert.assertNotNull;
25 import static org.junit.Assert.assertTrue;
26 import static org.junit.Assert.fail;
28 import java.text.DateFormat;
29 import java.text.ParseException;
30 import java.text.SimpleDateFormat;
31 import java.util.ArrayList;
32 import java.util.Collections;
33 import java.util.Date;
34 import java.util.List;
35 import java.util.TimeZone;
36 import java.util.concurrent.TimeUnit;
38 import org.junit.Test;
40 public class AAIUtilsTest {
43 public void testNullCheckWithNull() {
44 List<String> newList = null;
45 Iterable<String> res = AAIUtils.nullCheck(newList);
46 assertNotNull("nullCheck() should return empty list", res);
47 assertEquals(Collections.<String>emptyList(), res);
51 public void testNullCheckWithList() {
52 List<String> newList = new ArrayList<String>();
53 newList.add("testString");
55 Iterable<String> res = AAIUtils.nullCheck(newList);
57 assertNotNull("nullCheck() should return back list", res);
58 assertEquals(newList, res);
62 public void testGenDate() {
64 Date d1 = new Date(0);
66 DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
67 formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
68 formatter.setLenient(false);
73 d2 = formatter.parse(AAIUtils.genDate());
74 } catch (ParseException e) {
75 fail("Date parsing exception");
80 TimeUnit.SECONDS.sleep(1);
81 } catch (InterruptedException e1) {
86 assertTrue("Generated date is not after a past date", d2.after(d1));
87 assertTrue("Generated date is not before a future date", d2.before(d3));