Merge remote-tracking branch 'upstream/master'
This commit is contained in:
commit
5d25f72397
|
@ -33,38 +33,25 @@ public class GuavaIOTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenWriteUsingFiles_thenWritten() throws IOException {
|
public void whenWriteUsingFiles_thenWritten() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test.out");
|
final File file = new File("src/test/resources/test.out");
|
||||||
|
|
||||||
Files.write(expected_value, file, Charsets.UTF_8);
|
Files.write(expectedValue, file, Charsets.UTF_8);
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
final String result = Files.toString(file, Charsets.UTF_8);
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void whenWriteStringBuilderUsingFiles_thenWritten() throws IOException {
|
|
||||||
final String expected_value = "Hello world";
|
|
||||||
final File file = new File("src/test/resources/test.out");
|
|
||||||
final StringBuilder builder = new StringBuilder();
|
|
||||||
builder.append(expected_value);
|
|
||||||
|
|
||||||
Files.write(builder, file, Charsets.UTF_8);
|
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
|
||||||
assertEquals(expected_value, result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenWriteUsingCharSink_thenWritten() throws IOException {
|
public void whenWriteUsingCharSink_thenWritten() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test.out");
|
final File file = new File("src/test/resources/test.out");
|
||||||
final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);
|
final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);
|
||||||
|
|
||||||
sink.write(expected_value);
|
sink.write(expectedValue);
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
final String result = Files.toString(file, Charsets.UTF_8);
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -76,30 +63,30 @@ public class GuavaIOTest {
|
||||||
sink.writeLines(names, " ");
|
sink.writeLines(names, " ");
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
final String result = Files.toString(file, Charsets.UTF_8);
|
||||||
final String expected_value = Joiner.on(" ").join(names);
|
final String expectedValue = Joiner.on(" ").join(names);
|
||||||
assertEquals(expected_value, result.trim());
|
assertEquals(expectedValue, result.trim());
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenWriteUsingByteSink_thenWritten() throws IOException {
|
public void whenWriteUsingByteSink_thenWritten() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test.out");
|
final File file = new File("src/test/resources/test.out");
|
||||||
final ByteSink sink = Files.asByteSink(file);
|
final ByteSink sink = Files.asByteSink(file);
|
||||||
|
|
||||||
sink.write(expected_value.getBytes());
|
sink.write(expectedValue.getBytes());
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
final String result = Files.toString(file, Charsets.UTF_8);
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingFiles_thenRead() throws IOException {
|
public void whenReadUsingFiles_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test1.in");
|
final File file = new File("src/test/resources/test1.in");
|
||||||
|
|
||||||
final String result = Files.toString(file, Charsets.UTF_8);
|
final String result = Files.toString(file, Charsets.UTF_8);
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -112,18 +99,18 @@ public class GuavaIOTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingCharSource_thenRead() throws IOException {
|
public void whenReadUsingCharSource_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test1.in");
|
final File file = new File("src/test/resources/test1.in");
|
||||||
|
|
||||||
final CharSource source = Files.asCharSource(file, Charsets.UTF_8);
|
final CharSource source = Files.asCharSource(file, Charsets.UTF_8);
|
||||||
|
|
||||||
final String result = source.read();
|
final String result = source.read();
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadMultipleCharSources_thenRead() throws IOException {
|
public void whenReadMultipleCharSources_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello worldTest";
|
final String expectedValue = "Hello worldTest";
|
||||||
final File file1 = new File("src/test/resources/test1.in");
|
final File file1 = new File("src/test/resources/test1.in");
|
||||||
final File file2 = new File("src/test/resources/test1_1.in");
|
final File file2 = new File("src/test/resources/test1_1.in");
|
||||||
|
|
||||||
|
@ -133,34 +120,34 @@ public class GuavaIOTest {
|
||||||
|
|
||||||
final String result = source.read();
|
final String result = source.read();
|
||||||
|
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingCharStream_thenRead() throws IOException {
|
public void whenReadUsingCharStream_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
|
|
||||||
final FileReader reader = new FileReader("src/test/resources/test1.in");
|
final FileReader reader = new FileReader("src/test/resources/test1.in");
|
||||||
final String result = CharStreams.toString(reader);
|
final String result = CharStreams.toString(reader);
|
||||||
reader.close();
|
|
||||||
|
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingByteSource_thenRead() throws IOException {
|
public void whenReadUsingByteSource_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
final File file = new File("src/test/resources/test1.in");
|
final File file = new File("src/test/resources/test1.in");
|
||||||
|
|
||||||
final ByteSource source = Files.asByteSource(file);
|
final ByteSource source = Files.asByteSource(file);
|
||||||
|
|
||||||
final byte[] result = source.read();
|
final byte[] result = source.read();
|
||||||
assertEquals(expected_value, new String(result));
|
assertEquals(expectedValue, new String(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadAfterOffsetUsingByteSource_thenRead() throws IOException {
|
public void whenReadAfterOffsetUsingByteSource_thenRead() throws IOException {
|
||||||
final String expected_value = "lo world";
|
final String expectedValue = "lo world";
|
||||||
final File file = new File("src/test/resources/test1.in");
|
final File file = new File("src/test/resources/test1.in");
|
||||||
|
|
||||||
final long offset = 3;
|
final long offset = 3;
|
||||||
|
@ -168,33 +155,33 @@ public class GuavaIOTest {
|
||||||
final ByteSource source = Files.asByteSource(file).slice(offset, length);
|
final ByteSource source = Files.asByteSource(file).slice(offset, length);
|
||||||
|
|
||||||
final byte[] result = source.read();
|
final byte[] result = source.read();
|
||||||
assertEquals(expected_value, new String(result));
|
assertEquals(expectedValue, new String(result));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingByteStream_thenRead() throws IOException {
|
public void whenReadUsingByteStream_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
|
|
||||||
final FileInputStream reader = new FileInputStream("src/test/resources/test1.in");
|
final FileInputStream reader = new FileInputStream("src/test/resources/test1.in");
|
||||||
final byte[] result = ByteStreams.toByteArray(reader);
|
final byte[] result = ByteStreams.toByteArray(reader);
|
||||||
reader.close();
|
|
||||||
|
|
||||||
assertEquals(expected_value, new String(result));
|
assertEquals(expectedValue, new String(result));
|
||||||
|
reader.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenReadUsingResources_thenRead() throws IOException {
|
public void whenReadUsingResources_thenRead() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
|
|
||||||
final URL url = Resources.getResource("test1.in");
|
final URL url = Resources.getResource("test1.in");
|
||||||
final String result = Resources.toString(url, Charsets.UTF_8);
|
final String result = Resources.toString(url, Charsets.UTF_8);
|
||||||
|
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void whenCopyFileUsingFiles_thenCopied() throws IOException {
|
public void whenCopyFileUsingFiles_thenCopied() throws IOException {
|
||||||
final String expected_value = "Hello world";
|
final String expectedValue = "Hello world";
|
||||||
|
|
||||||
final File file1 = new File("src/test/resources/test1.in");
|
final File file1 = new File("src/test/resources/test1.in");
|
||||||
final File file2 = new File("src/test/resources/test_copy.in");
|
final File file2 = new File("src/test/resources/test_copy.in");
|
||||||
|
@ -202,7 +189,7 @@ public class GuavaIOTest {
|
||||||
Files.copy(file1, file2);
|
Files.copy(file1, file2);
|
||||||
final String result = Files.toString(file2, Charsets.UTF_8);
|
final String result = Files.toString(file2, Charsets.UTF_8);
|
||||||
|
|
||||||
assertEquals(expected_value, result);
|
assertEquals(expectedValue, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -220,14 +207,4 @@ public class GuavaIOTest {
|
||||||
assertEquals(value, result);
|
assertEquals(value, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
//
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
John Jane Adam Tom
|
|
@ -0,0 +1 @@
|
||||||
|
Hello world
|
Binary file not shown.
Loading…
Reference in New Issue