diff options
Diffstat (limited to 'catalog-dao/src/test')
-rw-r--r-- | catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java | 68 |
1 files changed, 35 insertions, 33 deletions
diff --git a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java index 1becea8d4f..512c5dea8f 100644 --- a/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java +++ b/catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java @@ -3,13 +3,14 @@ * SDC * ================================================================================ * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved. + * Modifications Copyright (c) 2019 Samsung * ================================================================================ * 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. @@ -20,40 +21,41 @@ package org.openecomp.sdc.be.dao.utils; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + +import java.util.Collections; +import java.util.Map; + import org.junit.Assert; import org.junit.Test; -import static org.assertj.core.api.Assertions.assertThatThrownBy; - public class DaoUtilsTest { - @Test - public void testConvertToJson() throws Exception { - Object object = new Object(); - String result; - - // test 1 - result = DaoUtils.convertToJson(object); - Assert.assertEquals("{}", result); - - assertThatThrownBy(()->DaoUtils.convertToJson(null)).isInstanceOf(RuntimeException.class); - } - - @Test - public void testConvertFromJson() throws Exception { - Class clazz = Object.class; - String json = null; - Object result; - - // default test - result = DaoUtils.convertFromJson(clazz, json); - Assert.assertEquals(null, result); - - try { - result = DaoUtils.convertFromJson(null, json); - } catch (Exception e) { - // TODO Auto-generated catch block - e.printStackTrace(); - } - } + private static final Map<String, String> TEST_OBJECT = Collections.singletonMap("key", "value"); + + private static final String JSON = "{\"key\":\"value\"}"; + private static final Class<Map> CLAZZ = Map.class; + + @Test + public void testConvertToJson() { + String result = DaoUtils.convertToJson(TEST_OBJECT); + Assert.assertEquals(JSON, result); + } + + @Test(expected = RuntimeException.class) + public void testConvertToJsonNullObject() { + DaoUtils.convertToJson(null); + } + + @Test + public void testConvertFromJson() { + Map result = DaoUtils.convertFromJson(CLAZZ, JSON); + assertEquals(TEST_OBJECT, result); + } + + @Test(expected = RuntimeException.class) + public void testConvertFromNullClassToJson() { + DaoUtils.convertFromJson(null, JSON); + } } |