blob: f03944ff6f8dbee7209bcccf8d45802e49c03517 (
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
|
// Copyright 2017 Yahoo Holdings. 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;
public class FileReadTestCase extends junit.framework.TestCase {
@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 2017 Yahoo Holdings."));
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 2017 Yahoo Holdings."));
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
|