diff options
author | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-22 19:03:46 +0300 |
---|---|---|
committer | vempo <vitaliy.emporopulo@amdocs.com> | 2017-10-23 12:38:26 +0300 |
commit | b118cd814ea0a230486c4179d0bcdc27d39d92b1 (patch) | |
tree | e61517052aab52e3a99e399e979456a2ef60bafd /openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java | |
parent | 30e46525c1406fb3b10603606c4efcc033ee58c4 (diff) |
Additinal fixes for resources not being released
More fixes for input streams not being properly closed,
with unit tests and other minor improvements (code cleanup and coding conventions).
Change-Id: I6751f924a1469d49b996e4f1d6c61371af6714b1
Issue-ID: SDC-291
Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java')
-rw-r--r-- | openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java new file mode 100644 index 0000000000..e32aa39904 --- /dev/null +++ b/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java @@ -0,0 +1,48 @@ +package org.openecomp.core.utilities.file; + +import org.testng.annotations.Test; + +import java.io.IOException; +import java.io.InputStream; +import java.util.function.Function; + +import static org.testng.Assert.assertTrue; + +/** + * @author EVITALIY + * @since 22 Oct 17 + */ +public class FileUtilsTest { + + private static final String TEST_RESOURCE = FileUtilsTest.class.getPackage().getName() + .replace('.', '/') + "/test-resource.txt"; + + private static final Function<InputStream, Integer> TEST_FUNCTION = (s) -> { + + try { + return s.available(); + } catch (IOException e) { + throw new RuntimeException(e); + } + }; + + @Test + public void testReadViaInputStreamWithSlash() throws Exception { + assertTrue(FileUtils.readViaInputStream(TEST_RESOURCE, TEST_FUNCTION) > 0); + } + + @Test + public void testReadViaInputStreamWithoutSlash() throws Exception { + assertTrue(FileUtils.readViaInputStream(TEST_RESOURCE, TEST_FUNCTION) > 0); + } + + @Test(expectedExceptions = NullPointerException.class) + public void testReadViaInputStreamNull() throws Exception { + FileUtils.readViaInputStream((String) null, TEST_FUNCTION); + } + + @Test(expectedExceptions = IllegalArgumentException.class) + public void testReadViaInputStreamNotFound() throws Exception { + FileUtils.readViaInputStream("notfound.txt", TEST_FUNCTION); + } +}
\ No newline at end of file |