summaryrefslogtreecommitdiffstats
path: root/catalog-dao/src
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-07-02 12:01:42 +0200
committerOfir Sonsino <ofir.sonsino@intl.att.com>2019-07-22 08:09:57 +0000
commit2f156e88b2c433ee2d3c404c1595f174ce13f878 (patch)
tree20264aa3d509842f2c5774d10e2d091d6d2d189c /catalog-dao/src
parent6043f67e7396e662f7814beca9760fdaf5058d6e (diff)
Improved unit tests for the DaoUtils class.
Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com> Change-Id: I634fc1ccccbfa5b1fec5f2612782f00990438c6b
Diffstat (limited to 'catalog-dao/src')
-rw-r--r--catalog-dao/src/test/java/org/openecomp/sdc/be/dao/utils/DaoUtilsTest.java68
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);
+ }
}