|
|
@@ -22,18 +22,18 @@ import static org.junit.Assert.*;
|
|
|
*
|
|
|
* @author Ranides Atterwim <ranides@gmail.com>
|
|
|
*/
|
|
|
-public class StringIOTest {
|
|
|
+public class IOStringsTest {
|
|
|
|
|
|
private static final String TEXT = "źrebię skacze po łące patrząc na słońce";
|
|
|
|
|
|
@Test
|
|
|
public void testFromReader() throws IOException {
|
|
|
String inp1 = "Hello world";
|
|
|
- String out1 = StringIO.read(new StringReader(inp1));
|
|
|
+ String out1 = IOStrings.read(new StringReader(inp1));
|
|
|
assertEquals(inp1, out1);
|
|
|
|
|
|
String inp2 = random(10247) ;
|
|
|
- String out2 = StringIO.read(new StringReader(inp2));
|
|
|
+ String out2 = IOStrings.read(new StringReader(inp2));
|
|
|
assertEquals(inp2, out2);
|
|
|
}
|
|
|
|
|
|
@@ -42,13 +42,13 @@ public class StringIOTest {
|
|
|
ByteArrayInputStream istream1 = new ByteArrayInputStream(TEXT.getBytes(Charsets.UTF8));
|
|
|
ByteArrayInputStream istream2 = new ByteArrayInputStream(TEXT.getBytes(Charsets.PL_WINDOWS));
|
|
|
|
|
|
- assertNotEquals(TEXT, StringIO.read(istream1, Charsets.PL_WINDOWS));
|
|
|
+ assertNotEquals(TEXT, IOStrings.read(istream1, Charsets.PL_WINDOWS));
|
|
|
istream1.reset();
|
|
|
- assertEquals(TEXT, StringIO.read(istream1, Charsets.UTF8));
|
|
|
+ assertEquals(TEXT, IOStrings.read(istream1, Charsets.UTF8));
|
|
|
|
|
|
- assertNotEquals(TEXT, StringIO.read(istream2, Charsets.UTF8));
|
|
|
+ assertNotEquals(TEXT, IOStrings.read(istream2, Charsets.UTF8));
|
|
|
istream2.reset();
|
|
|
- assertEquals(TEXT, StringIO.read(istream2, Charsets.PL_WINDOWS));
|
|
|
+ assertEquals(TEXT, IOStrings.read(istream2, Charsets.PL_WINDOWS));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -57,8 +57,8 @@ public class StringIOTest {
|
|
|
String c2 = "1\n2\n3\n4\n5\n";
|
|
|
List<String> expected = Arrays.asList("1","2", "3", "4", "5");
|
|
|
|
|
|
- assertEquals(expected, StringIO.readLines(new StringReader(c1)));
|
|
|
- assertEquals(expected, StringIO.readLines(new StringReader(c2)));
|
|
|
+ assertEquals(expected, IOStrings.readLines(new StringReader(c1)));
|
|
|
+ assertEquals(expected, IOStrings.readLines(new StringReader(c2)));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -67,8 +67,8 @@ public class StringIOTest {
|
|
|
ByteArrayInputStream s2 = new ByteArrayInputStream("słońce\nźrebię\nłąka\ndom\n".getBytes(Charsets.UTF8));
|
|
|
List<String> expected = Arrays.asList("słońce", "źrebię", "łąka", "dom");
|
|
|
|
|
|
- assertEquals(expected, StringIO.readLines(s1, Charsets.UTF8));
|
|
|
- assertEquals(expected, StringIO.readLines(s2, Charsets.UTF8));
|
|
|
+ assertEquals(expected, IOStrings.readLines(s1, Charsets.UTF8));
|
|
|
+ assertEquals(expected, IOStrings.readLines(s2, Charsets.UTF8));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -77,8 +77,8 @@ public class StringIOTest {
|
|
|
ByteArrayInputStream s2 = new ByteArrayInputStream("słońce\nźrebię\nłąka\ndom\n".getBytes(Charsets.PL_DOS));
|
|
|
List<String> expected = Arrays.asList("słońce", "źrebię", "łąka", "dom");
|
|
|
|
|
|
- assertEquals(expected, StringIO.readLines(s1, Charsets.PL_DOS));
|
|
|
- assertEquals(expected, StringIO.readLines(s2, Charsets.PL_DOS));
|
|
|
+ assertEquals(expected, IOStrings.readLines(s1, Charsets.PL_DOS));
|
|
|
+ assertEquals(expected, IOStrings.readLines(s2, Charsets.PL_DOS));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -86,46 +86,46 @@ public class StringIOTest {
|
|
|
File file1 = File.createTempFile("StringIO.LFF1", ".txt");
|
|
|
File file2 = File.createTempFile("StringIO.LFF1", ".txt");
|
|
|
|
|
|
- StringIO.write(file1, "słońce\nźrebię\nłąka\ndom", Charsets.PL_DOS);
|
|
|
- StringIO.write(file2, "słońce\nźrebię\nłąka\ndom\n", Charsets.PL_DOS);
|
|
|
+ IOStrings.write(file1, "słońce\nźrebię\nłąka\ndom", Charsets.PL_DOS);
|
|
|
+ IOStrings.write(file2, "słońce\nźrebię\nłąka\ndom\n", Charsets.PL_DOS);
|
|
|
|
|
|
List<String> expected = Arrays.asList("słońce", "źrebię", "łąka", "dom");
|
|
|
|
|
|
- assertEquals(expected, StringIO.readLines(file1, Charsets.PL_DOS));
|
|
|
- assertEquals(expected, StringIO.readLines(file2, Charsets.PL_DOS));
|
|
|
+ assertEquals(expected, IOStrings.readLines(file1, Charsets.PL_DOS));
|
|
|
+ assertEquals(expected, IOStrings.readLines(file2, Charsets.PL_DOS));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testToWriter() throws IOException {
|
|
|
StringWriter writer = new StringWriter();
|
|
|
- StringIO.write(writer, TEXT);
|
|
|
+ IOStrings.write(writer, TEXT);
|
|
|
assertEquals(TEXT, writer.toString());
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testToStream() throws IOException {
|
|
|
ByteArrayOutputStream ostream1 = new ByteArrayOutputStream();
|
|
|
- StringIO.write(ostream1, TEXT, Charsets.PL_DOS);
|
|
|
+ IOStrings.write(ostream1, TEXT, Charsets.PL_DOS);
|
|
|
assertArrayEquals(ostream1.toByteArray(), TEXT.getBytes(Charsets.PL_DOS));
|
|
|
|
|
|
ByteArrayOutputStream ostream2 = new ByteArrayOutputStream();
|
|
|
- StringIO.write(ostream2, TEXT, Charsets.PL_ISO);
|
|
|
+ IOStrings.write(ostream2, TEXT, Charsets.PL_ISO);
|
|
|
assertArrayEquals(ostream2.toByteArray(), TEXT.getBytes(Charsets.PL_ISO));
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
public void testToFile() throws IOException {
|
|
|
File file1 = File.createTempFile("StringIOF1", ".txt");
|
|
|
- StringIO.write(file1, TEXT, Charsets.PL_DOS);
|
|
|
+ IOStrings.write(file1, TEXT, Charsets.PL_DOS);
|
|
|
|
|
|
- assertNotEquals(TEXT, StringIO.read(file1, Charsets.PL_ISO));
|
|
|
- assertEquals(TEXT, StringIO.read(file1, Charsets.PL_DOS));
|
|
|
+ assertNotEquals(TEXT, IOStrings.read(file1, Charsets.PL_ISO));
|
|
|
+ assertEquals(TEXT, IOStrings.read(file1, Charsets.PL_DOS));
|
|
|
|
|
|
File file2 = File.createTempFile("StringIOF1", ".txt");
|
|
|
- StringIO.write(file2, TEXT, Charsets.PL_ISO);
|
|
|
+ IOStrings.write(file2, TEXT, Charsets.PL_ISO);
|
|
|
|
|
|
- assertNotEquals(TEXT, StringIO.read(file2, Charsets.PL_DOS));
|
|
|
- assertEquals(TEXT, StringIO.read(file2, Charsets.PL_ISO));
|
|
|
+ assertNotEquals(TEXT, IOStrings.read(file2, Charsets.PL_DOS));
|
|
|
+ assertEquals(TEXT, IOStrings.read(file2, Charsets.PL_ISO));
|
|
|
}
|
|
|
|
|
|
private String random(int size) {
|