From 2f156e88b2c433ee2d3c404c1595f174ce13f878 Mon Sep 17 00:00:00 2001 From: "k.kedron" Date: Tue, 2 Jul 2019 12:01:42 +0200 Subject: Improved unit tests for the DaoUtils class. Issue-ID: SDC-2327 Signed-off-by: Krystian Kedron Change-Id: I634fc1ccccbfa5b1fec5f2612782f00990438c6b --- .../openecomp/sdc/be/dao/utils/DaoUtilsTest.java | 68 +++++++++++----------- 1 file changed, 35 insertions(+), 33 deletions(-) (limited to 'catalog-dao/src/test') 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 TEST_OBJECT = Collections.singletonMap("key", "value"); + + private static final String JSON = "{\"key\":\"value\"}"; + private static final Class 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); + } } -- cgit 1.2.3-korg