aboutsummaryrefslogtreecommitdiffstats
path: root/vespajlib/src/test/java/com/yahoo/io/FileReadTestCase.java
blob: ce94d4f90e8d0e55ac8710674dde1aab7f91ae1f (plain) (blame)
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
// Copyright Yahoo. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
package com.yahoo.io;

import org.junit.Test;

import java.io.File;
import java.io.IOException;
import java.io.StringReader;
import java.nio.charset.Charset;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

public class FileReadTestCase {

    @Test
    public void testReadByteArray() throws IOException {
        byte[] thisFile = IOUtils.readFileBytes(new File("src/test/java/com/yahoo/io/FileReadTestCase.java"));
        String str = new String(thisFile, Charset.forName("US-ASCII"));
        assertTrue(str.startsWith("// Copyright Yahoo."));
        assertTrue(str.endsWith("// Yeppers\n"));
    }

    @Test
    public void testReadString() throws IOException {
        String str = IOUtils.readFile(new File("src/test/java/com/yahoo/io/FileReadTestCase.java"));
        assertTrue(str.startsWith("// Copyright Yahoo."));
        assertTrue(str.endsWith("// Yeppers\n"));
    }

    @Test
    public void testReadAllFromReader() throws IOException {
        assertEquals(IOUtils.readAll(new StringReader("")), "");
        assertEquals(IOUtils.readAll(new StringReader("hei")), "hei");
        assertEquals(IOUtils.readAll(new StringReader("hei\nhaa")), "hei\nhaa");
        assertEquals(IOUtils.readAll(new StringReader("hei\nhaa\n")), "hei\nhaa\n");
    }

}

// Yeppers