diff options
author | 2021-03-22 11:22:47 +0100 | |
---|---|---|
committer | 2021-03-24 08:25:00 +0100 | |
commit | 134ca5667da901a703ecb0c78d96873712a9d0d3 (patch) | |
tree | 38738cddb2798a54d1f81c22d005b9ff1e0c79f0 /common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java | |
parent | eb57d1efc197968a4073b331b2dc8f40d8109847 (diff) |
Improve test coverage
Add unit tests to improve test coverage.
Issue-ID: SDC-3428
Change-Id: I9e00af2824366ae45d47d2dcecf322fd3e9a6fea
Signed-off-by: xuegao <xue.gao@intl.att.com>
Diffstat (limited to 'common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java')
-rw-r--r-- | common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java | 44 |
1 files changed, 32 insertions, 12 deletions
diff --git a/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java b/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java index b5036060eb..837be1d0ca 100644 --- a/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java +++ b/common-app-api/src/test/java/org/openecomp/sdc/common/util/GeneralUtilityTest.java @@ -23,17 +23,22 @@ package org.openecomp.sdc.common.util; import com.google.common.collect.Lists; import org.apache.commons.io.FileUtils; -import org.junit.Test; +import org.junit.jupiter.api.Test; +import org.mockito.Mockito; import java.io.File; import java.io.IOException; import java.util.Base64; +import java.util.LinkedList; import java.util.List; +import java.util.Map; + +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.when; -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; public class GeneralUtilityTest { @@ -56,14 +61,12 @@ public class GeneralUtilityTest { @Test public void validateIsBase64EncodedReturnsProperResponseFromByteArray() { - final String testString = "testDataToEncode"; final byte[] testBytes = testString.getBytes(); final byte[] testEncodedBytes = Base64.getEncoder().encode(testBytes); - boolean result = GeneralUtility.isBase64Encoded(testEncodedBytes); - - assertTrue(result); + assertTrue(GeneralUtility.isBase64Encoded(testEncodedBytes)); + assertTrue(GeneralUtility.isBase64Encoded(testString)); } @Test @@ -191,7 +194,7 @@ public class GeneralUtilityTest { final String encodedString = org.apache.commons.codec.digest.DigestUtils.md5Hex(testStringToEncode.getBytes()); - assertArrayEquals(encodedString.getBytes(), Base64.getDecoder().decode(result)); + assertEquals(encodedString, new String(Base64.getDecoder().decode(result))); } @Test @@ -204,7 +207,7 @@ public class GeneralUtilityTest { final String encodedString = org.apache.commons.codec.digest.DigestUtils.md5Hex(testStringToEncode.getBytes()); - assertArrayEquals(encodedString.getBytes(), Base64.getDecoder().decode(result)); + assertEquals(encodedString, new String(Base64.getDecoder().decode(result))); } @Test @@ -243,8 +246,25 @@ public class GeneralUtilityTest { final String empty = " \ttest "; boolean result = GeneralUtility.isEmptyString(empty); - + assertTrue(GeneralUtility.isEmptyString(null)); assertFalse(result); } + @Test + public void getCategorizedComponentsTest() { + + List<ICategorizedElement> components = new LinkedList<>(); + ICategorizedElement componentService = Mockito.mock(ICategorizedElement.class); + when(componentService.getComponentTypeAsString()).thenReturn("SERVICE"); + + ICategorizedElement componentResource = Mockito.mock(ICategorizedElement.class); + when(componentResource.getComponentTypeAsString()).thenReturn("RESOURCE"); + + components.add(componentService); + components.add(componentResource); + Map<String, Map<String, List<ICategorizedElement>>> result = GeneralUtility.getCategorizedComponents(components); + verify(componentService, Mockito.times(1)).getComponentTypeAsString(); + verify(componentResource, Mockito.times(2)).getComponentTypeAsString(); + assertEquals(2, result.size()); + } } |