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=========================================================
20 package org.onap.aai.util;
22 import static org.junit.Assert.assertEquals;
23 import static org.junit.Assert.assertNotNull;
24 import static org.junit.Assert.assertTrue;
25 import static org.junit.Assert.fail;
27 import java.text.DateFormat;
28 import java.text.ParseException;
29 import java.text.SimpleDateFormat;
30 import java.util.ArrayList;
31 import java.util.Collections;
32 import java.util.Date;
33 import java.util.List;
34 import java.util.TimeZone;
35 import java.util.concurrent.TimeUnit;
37 import org.junit.Test;
39 public class AAIUtilsTest {
42 public void testNullCheckWithNull() {
43 List<String> newList = null;
44 Iterable<String> res = AAIUtils.nullCheck(newList);
45 assertNotNull("nullCheck() should return empty list", res);
46 assertEquals(Collections.<String>emptyList(), res);
50 public void testNullCheckWithList() {
51 List<String> newList = new ArrayList<String>();
52 newList.add("testString");
54 Iterable<String> res = AAIUtils.nullCheck(newList);
56 assertNotNull("nullCheck() should return back list", res);
57 assertEquals(newList, res);
61 public void testGenDate() {
63 Date d1 = new Date(0);
65 DateFormat formatter = new SimpleDateFormat("YYMMdd-HH:mm:ss:SSS");
66 formatter.setTimeZone(TimeZone.getTimeZone("GMT"));
67 formatter.setLenient(false);
72 d2 = formatter.parse(AAIUtils.genDate());
73 } catch (ParseException e) {
74 fail("Date parsing exception");
79 TimeUnit.SECONDS.sleep(1);
80 } catch (InterruptedException e1) {}
84 assertTrue("Generated date is not after a past date", d2.after(d1));
85 assertTrue("Generated date is not before a future date", d2.before(d3));