aboutsummaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-core-lib/openecomp-utilities-lib/src/test/java/org/openecomp/core/utilities/file/FileUtilsTest.java
blob: e32aa39904d2c9aba6587af6e96a842a30ede888 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
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);
    }
}