2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright © 2017 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 * ECOMP is a trademark and service mark of AT&T Intellectual Property.
22 package org.onap.aai.util;
24 import static org.junit.Assert.assertEquals;
25 import static org.junit.Assert.assertNotNull;
26 import static org.junit.Assert.assertTrue;
28 import java.time.LocalDateTime;
29 import java.time.Month;
31 import org.junit.Test;
32 import org.mockito.Mockito;
34 public class PojoUtilsTest {
37 public void testGetJsonFromObject_Clazz_MockTest() throws Exception {
39 String obj = "helloWorld";
40 PojoUtils pojoUtils = Mockito.mock(PojoUtils.class);
41 Mockito.doCallRealMethod().when(pojoUtils).getJsonFromObject(Mockito.anyString());
43 pojoUtils.getJsonFromObject(obj);
45 Mockito.verify(pojoUtils, Mockito.times(1)).getJsonFromObject(Mockito.anyString(), Mockito.eq(false), Mockito.eq(true));
49 public void testGetJsonFromObject_Clazz() throws Exception {
51 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
52 LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
54 String res = pojoUtils.getJsonFromObject(date);
57 assertTrue(res.contains("\"dayOfMonth\" : 18"));
58 assertTrue(res.contains("\"dayOfWeek\" : \"MONDAY\""));
59 assertTrue(res.contains("\"dayOfYear\" : 261"));
60 assertTrue(res.contains("\"hour\" : 10"));
61 assertTrue(res.contains("\"minute\" : 55"));
62 assertTrue(res.contains("\"month\" : \"SEPTEMBER\""));
63 assertTrue(res.contains("\"monthValue\" : 9"));
64 assertTrue(res.contains("\"nano\" : 300"));
65 assertTrue(res.contains("\"second\" : 0"));
66 assertTrue(res.contains("\"year\" : 2017"));
70 public void testGetJsonFromObject_Clazz_null() throws Exception {
71 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
73 String res = pojoUtils.getJsonFromObject(null);
76 assertEquals("null", res);
80 public void testGetJsonFromObject_null() throws Exception {
81 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
83 String res = pojoUtils.getJsonFromObject(null, false, true);
86 assertEquals("null", res);
90 public void testGetJsonFromObject() throws Exception {
91 PojoUtils pojoUtils = PojoUtilsTest.getInstance();
92 LocalDateTime date = LocalDateTime.of(2017, Month.SEPTEMBER, 18, 10, 55, 0, 300);
94 String res = pojoUtils.getJsonFromObject(date, false, false);
97 res = pojoUtils.getJsonFromObject(date, true, false);
100 res = pojoUtils.getJsonFromObject(date, true, true);
104 static PojoUtils getInstance() {
105 return new PojoUtils();