From 91774ece756f52443fbba79a8dce65503a8d24a1 Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 26 Oct 2014 20:48:14 +0200 Subject: [PATCH 1/3] guava IO cleanup work --- .../java/org/baeldung/guava/GuavaIOTest.java | 80 +++++++----------- guava/src/test/resources/test.out | 1 + guava/src/test/resources/test_copy.in | 1 + guava/src/test/resources/test_le.txt | Bin 0 -> 4 bytes 4 files changed, 31 insertions(+), 51 deletions(-) create mode 100644 guava/src/test/resources/test.out create mode 100644 guava/src/test/resources/test_copy.in create mode 100644 guava/src/test/resources/test_le.txt diff --git a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java index 64f01c2538..a4115e92e1 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java @@ -33,38 +33,25 @@ public class GuavaIOTest { @Test 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"); - Files.write(expected_value, file, Charsets.UTF_8); + Files.write(expectedValue, file, Charsets.UTF_8); final String result = Files.toString(file, Charsets.UTF_8); - assertEquals(expected_value, 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); + assertEquals(expectedValue, result); } @Test 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 CharSink sink = Files.asCharSink(file, Charsets.UTF_8); - sink.write(expected_value); + sink.write(expectedValue); final String result = Files.toString(file, Charsets.UTF_8); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test @@ -76,30 +63,30 @@ public class GuavaIOTest { sink.writeLines(names, " "); final String result = Files.toString(file, Charsets.UTF_8); - final String expected_value = Joiner.on(" ").join(names); - assertEquals(expected_value, result.trim()); + final String expectedValue = Joiner.on(" ").join(names); + assertEquals(expectedValue, result.trim()); } @Test 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 ByteSink sink = Files.asByteSink(file); - sink.write(expected_value.getBytes()); + sink.write(expectedValue.getBytes()); final String result = Files.toString(file, Charsets.UTF_8); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test 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 String result = Files.toString(file, Charsets.UTF_8); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test @@ -112,18 +99,18 @@ public class GuavaIOTest { @Test 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 CharSource source = Files.asCharSource(file, Charsets.UTF_8); final String result = source.read(); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test 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 file2 = new File("src/test/resources/test1_1.in"); @@ -133,34 +120,34 @@ public class GuavaIOTest { final String result = source.read(); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test 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 String result = CharStreams.toString(reader); reader.close(); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test 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 ByteSource source = Files.asByteSource(file); final byte[] result = source.read(); - assertEquals(expected_value, new String(result)); + assertEquals(expectedValue, new String(result)); } @Test 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 long offset = 3; @@ -168,33 +155,33 @@ public class GuavaIOTest { final ByteSource source = Files.asByteSource(file).slice(offset, length); final byte[] result = source.read(); - assertEquals(expected_value, new String(result)); + assertEquals(expectedValue, new String(result)); } @Test 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 byte[] result = ByteStreams.toByteArray(reader); reader.close(); - assertEquals(expected_value, new String(result)); + assertEquals(expectedValue, new String(result)); } @Test 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 String result = Resources.toString(url, Charsets.UTF_8); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test 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 file2 = new File("src/test/resources/test_copy.in"); @@ -202,7 +189,7 @@ public class GuavaIOTest { Files.copy(file1, file2); final String result = Files.toString(file2, Charsets.UTF_8); - assertEquals(expected_value, result); + assertEquals(expectedValue, result); } @Test @@ -222,12 +209,3 @@ public class GuavaIOTest { } - -// - -// -// -// -// -// - diff --git a/guava/src/test/resources/test.out b/guava/src/test/resources/test.out new file mode 100644 index 0000000000..7a79da3803 --- /dev/null +++ b/guava/src/test/resources/test.out @@ -0,0 +1 @@ +John Jane Adam Tom \ No newline at end of file diff --git a/guava/src/test/resources/test_copy.in b/guava/src/test/resources/test_copy.in new file mode 100644 index 0000000000..70c379b63f --- /dev/null +++ b/guava/src/test/resources/test_copy.in @@ -0,0 +1 @@ +Hello world \ No newline at end of file diff --git a/guava/src/test/resources/test_le.txt b/guava/src/test/resources/test_le.txt new file mode 100644 index 0000000000000000000000000000000000000000..f7cc484bf45e18b3fe4dea78290abf122bedbad1 GIT binary patch literal 4 LcmYdcU|;|M0h9n` literal 0 HcmV?d00001 From 4a0dd47f3647cd3fdec4eb2df6ebe4fa7928854d Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 26 Oct 2014 20:48:37 +0200 Subject: [PATCH 2/3] minor test formatting cleanup --- guava/src/test/java/org/baeldung/guava/GuavaIOTest.java | 1 - 1 file changed, 1 deletion(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java index a4115e92e1..efc5c03d47 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java @@ -207,5 +207,4 @@ public class GuavaIOTest { assertEquals(value, result); } - } From ab113fea22ab6a68c564662fb08cd58bdd6fa4fa Mon Sep 17 00:00:00 2001 From: eugenp Date: Sun, 26 Oct 2014 21:47:14 +0200 Subject: [PATCH 3/3] IO test cleanup --- guava/src/test/java/org/baeldung/guava/GuavaIOTest.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java index efc5c03d47..47fee206dc 100644 --- a/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java +++ b/guava/src/test/java/org/baeldung/guava/GuavaIOTest.java @@ -129,9 +129,9 @@ public class GuavaIOTest { final FileReader reader = new FileReader("src/test/resources/test1.in"); final String result = CharStreams.toString(reader); - reader.close(); assertEquals(expectedValue, result); + reader.close(); } @Test @@ -164,9 +164,9 @@ public class GuavaIOTest { final FileInputStream reader = new FileInputStream("src/test/resources/test1.in"); final byte[] result = ByteStreams.toByteArray(reader); - reader.close(); assertEquals(expectedValue, new String(result)); + reader.close(); } @Test