e32aa39904d2c9aba6587af6e96a842a30ede888
[sdc.git] /
1 package org.openecomp.core.utilities.file;
2
3 import org.testng.annotations.Test;
4
5 import java.io.IOException;
6 import java.io.InputStream;
7 import java.util.function.Function;
8
9 import static org.testng.Assert.assertTrue;
10
11 /**
12  * @author EVITALIY
13  * @since 22 Oct 17
14  */
15 public class FileUtilsTest {
16
17     private static final String TEST_RESOURCE = FileUtilsTest.class.getPackage().getName()
18             .replace('.', '/') + "/test-resource.txt";
19
20     private static final Function<InputStream, Integer> TEST_FUNCTION = (s) -> {
21
22         try {
23             return s.available();
24         } catch (IOException e) {
25             throw new RuntimeException(e);
26         }
27     };
28
29     @Test
30     public void testReadViaInputStreamWithSlash() throws Exception {
31         assertTrue(FileUtils.readViaInputStream(TEST_RESOURCE, TEST_FUNCTION) > 0);
32     }
33
34     @Test
35     public void testReadViaInputStreamWithoutSlash() throws Exception {
36         assertTrue(FileUtils.readViaInputStream(TEST_RESOURCE, TEST_FUNCTION) > 0);
37     }
38
39     @Test(expectedExceptions = NullPointerException.class)
40     public void testReadViaInputStreamNull() throws Exception {
41         FileUtils.readViaInputStream((String) null, TEST_FUNCTION);
42     }
43
44     @Test(expectedExceptions = IllegalArgumentException.class)
45     public void testReadViaInputStreamNotFound() throws Exception {
46         FileUtils.readViaInputStream("notfound.txt", TEST_FUNCTION);
47     }
48 }