diff options
author | siddharth0905 <siddharth.singh4@amdocs.com> | 2018-08-21 17:55:30 +0530 |
---|---|---|
committer | Vitaly Emporopulo <Vitaliy.Emporopulo@amdocs.com> | 2018-09-13 11:00:08 +0000 |
commit | c58f445fcef56a6440f3b21d54b390700623c48c (patch) | |
tree | 9540ba4f1c7c2ec92c07ce2abcd04d02e06033cc /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java | |
parent | 7678396a1df3122d80d838c958d857f03e2aefbb (diff) |
Test coverage
Increase test coverage
Change-Id: I43e3149d0d4b07dc8e260f3d5fac025197882f3a
Issue-ID: SDC-1673
Signed-off-by: siddharth0905 <siddharth.singh4@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java')
-rw-r--r-- | openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java | 75 |
1 files changed, 69 insertions, 6 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java index 57d69b1b68..1b06f37a16 100644 --- a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileContentHandlerTest.java @@ -1,13 +1,20 @@ package org.openecomp.core.utilities.file; -import org.testng.Assert; -import org.testng.annotations.Test; +import static org.testng.Assert.assertEquals; +import static org.testng.Assert.assertFalse; +import static org.testng.Assert.assertTrue; +import java.io.ByteArrayInputStream; import java.io.IOException; +import java.util.AbstractMap; import java.util.Arrays; +import java.util.Map; import java.util.Optional; +import java.util.stream.Collectors; +import java.util.stream.Stream; -import static org.testng.Assert.*; +import org.testng.Assert; +import org.testng.annotations.Test; /** * @author EVITALIY @@ -18,7 +25,7 @@ public class FileContentHandlerTest { private static final String FILE_NAME = "test-file.txt"; @Test - public void testProcessFileContent() throws Exception { + public void testProcessFileContent() { final int size = 13; FileContentHandler contentHandler = new FileContentHandler(); @@ -42,15 +49,71 @@ public class FileContentHandlerTest { } @Test - public void testProcessEmptyFileContent() throws Exception { + public void testProcessEmptyFileContent() { FileContentHandler contentHandler = new FileContentHandler(); contentHandler.addFile(FILE_NAME, new byte[0]); assertFalse(contentHandler.processFileContent(FILE_NAME, Optional::isPresent)); } @Test - public void testProcessNoFileContent() throws Exception { + public void testProcessNoFileContent() { FileContentHandler contentHandler = new FileContentHandler(); assertFalse(contentHandler.processFileContent("filename", Optional::isPresent)); } + + @Test + public void testAddFiles() { + FileContentHandler contentHandler = new FileContentHandler(); + contentHandler.addFile("org/openecomp/core/utilities/file/testFileUtils.txt", + new ByteArrayInputStream(new byte[100])); + + Assert.assertNotNull(contentHandler.getFiles()); + Assert.assertTrue(contentHandler.getFiles().containsKey("org/openecomp/core/utilities/file/testFileUtils.txt")); + } + + @Test + public void testSetFiles() { + FileContentHandler contentHandler = new FileContentHandler(); + Map<String, byte[]> fileMap = Stream.of(new AbstractMap.SimpleEntry<>("file1", new byte[0]), + new AbstractMap.SimpleEntry<>("file2", new byte[0])) + .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); + + contentHandler.setFiles(fileMap); + + Assert.assertEquals(contentHandler.getFiles().size(), 2); + Assert.assertEquals(contentHandler.getFileList().size(), 2); + Assert.assertFalse(contentHandler.isEmpty()); + contentHandler.remove("file1"); + Assert.assertFalse(contentHandler.containsFile("file1")); + } + + @Test + public void testAddAll() { + FileContentHandler contentHandler = new FileContentHandler(); + FileContentHandler contentHandler1 = createFileHandlerContent(); + + contentHandler.addAll(contentHandler1); + + Assert.assertTrue(contentHandler1.containsFile("file1")); + Assert.assertEquals(contentHandler.getFiles().size(), 2); + } + + @Test + public void testSetFilesUsingFIleContentHandlerObject() { + FileContentHandler contentHandler1 = createFileHandlerContent(); + + FileContentHandler contentHandler = new FileContentHandler(); + contentHandler.setFiles(contentHandler1); + + Assert.assertEquals(contentHandler.getFiles().size(), 2); + } + + private FileContentHandler createFileHandlerContent() { + FileContentHandler contentHandler1 = new FileContentHandler(); + Map<String, byte[]> fileMap = Stream.of(new AbstractMap.SimpleEntry<>("file1", new byte[0]), + new AbstractMap.SimpleEntry<>("file2", new byte[0])) + .collect(Collectors.toMap(AbstractMap.SimpleEntry::getKey, AbstractMap.SimpleEntry::getValue)); + contentHandler1.putAll(fileMap); + return contentHandler1; + } }
\ No newline at end of file |