Skip to content

Commit 91774ec

Browse files
author
eugenp
committed
guava IO cleanup work
1 parent ffdca4c commit 91774ec

File tree

4 files changed

+31
-51
lines changed

4 files changed

+31
-51
lines changed

guava/src/test/java/org/baeldung/guava/GuavaIOTest.java

Lines changed: 29 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -33,38 +33,25 @@ public class GuavaIOTest {
3333

3434
@Test
3535
public void whenWriteUsingFiles_thenWritten() throws IOException {
36-
final String expected_value = "Hello world";
36+
final String expectedValue = "Hello world";
3737
final File file = new File("src/test/resources/test.out");
3838

39-
Files.write(expected_value, file, Charsets.UTF_8);
39+
Files.write(expectedValue, file, Charsets.UTF_8);
4040

4141
final String result = Files.toString(file, Charsets.UTF_8);
42-
assertEquals(expected_value, result);
43-
}
44-
45-
@Test
46-
public void whenWriteStringBuilderUsingFiles_thenWritten() throws IOException {
47-
final String expected_value = "Hello world";
48-
final File file = new File("src/test/resources/test.out");
49-
final StringBuilder builder = new StringBuilder();
50-
builder.append(expected_value);
51-
52-
Files.write(builder, file, Charsets.UTF_8);
53-
54-
final String result = Files.toString(file, Charsets.UTF_8);
55-
assertEquals(expected_value, result);
42+
assertEquals(expectedValue, result);
5643
}
5744

5845
@Test
5946
public void whenWriteUsingCharSink_thenWritten() throws IOException {
60-
final String expected_value = "Hello world";
47+
final String expectedValue = "Hello world";
6148
final File file = new File("src/test/resources/test.out");
6249
final CharSink sink = Files.asCharSink(file, Charsets.UTF_8);
6350

64-
sink.write(expected_value);
51+
sink.write(expectedValue);
6552

6653
final String result = Files.toString(file, Charsets.UTF_8);
67-
assertEquals(expected_value, result);
54+
assertEquals(expectedValue, result);
6855
}
6956

7057
@Test
@@ -76,30 +63,30 @@ public void whenWriteMultipleLinesUsingCharSink_thenWritten() throws IOException
7663
sink.writeLines(names, " ");
7764

7865
final String result = Files.toString(file, Charsets.UTF_8);
79-
final String expected_value = Joiner.on(" ").join(names);
80-
assertEquals(expected_value, result.trim());
66+
final String expectedValue = Joiner.on(" ").join(names);
67+
assertEquals(expectedValue, result.trim());
8168

8269
}
8370

8471
@Test
8572
public void whenWriteUsingByteSink_thenWritten() throws IOException {
86-
final String expected_value = "Hello world";
73+
final String expectedValue = "Hello world";
8774
final File file = new File("src/test/resources/test.out");
8875
final ByteSink sink = Files.asByteSink(file);
8976

90-
sink.write(expected_value.getBytes());
77+
sink.write(expectedValue.getBytes());
9178

9279
final String result = Files.toString(file, Charsets.UTF_8);
93-
assertEquals(expected_value, result);
80+
assertEquals(expectedValue, result);
9481
}
9582

9683
@Test
9784
public void whenReadUsingFiles_thenRead() throws IOException {
98-
final String expected_value = "Hello world";
85+
final String expectedValue = "Hello world";
9986
final File file = new File("src/test/resources/test1.in");
10087

10188
final String result = Files.toString(file, Charsets.UTF_8);
102-
assertEquals(expected_value, result);
89+
assertEquals(expectedValue, result);
10390
}
10491

10592
@Test
@@ -112,18 +99,18 @@ public void whenReadMultipleLinesUsingFiles_thenRead() throws IOException {
11299

113100
@Test
114101
public void whenReadUsingCharSource_thenRead() throws IOException {
115-
final String expected_value = "Hello world";
102+
final String expectedValue = "Hello world";
116103
final File file = new File("src/test/resources/test1.in");
117104

118105
final CharSource source = Files.asCharSource(file, Charsets.UTF_8);
119106

120107
final String result = source.read();
121-
assertEquals(expected_value, result);
108+
assertEquals(expectedValue, result);
122109
}
123110

124111
@Test
125112
public void whenReadMultipleCharSources_thenRead() throws IOException {
126-
final String expected_value = "Hello worldTest";
113+
final String expectedValue = "Hello worldTest";
127114
final File file1 = new File("src/test/resources/test1.in");
128115
final File file2 = new File("src/test/resources/test1_1.in");
129116

@@ -133,76 +120,76 @@ public void whenReadMultipleCharSources_thenRead() throws IOException {
133120

134121
final String result = source.read();
135122

136-
assertEquals(expected_value, result);
123+
assertEquals(expectedValue, result);
137124
}
138125

139126
@Test
140127
public void whenReadUsingCharStream_thenRead() throws IOException {
141-
final String expected_value = "Hello world";
128+
final String expectedValue = "Hello world";
142129

143130
final FileReader reader = new FileReader("src/test/resources/test1.in");
144131
final String result = CharStreams.toString(reader);
145132
reader.close();
146133

147-
assertEquals(expected_value, result);
134+
assertEquals(expectedValue, result);
148135
}
149136

150137
@Test
151138
public void whenReadUsingByteSource_thenRead() throws IOException {
152-
final String expected_value = "Hello world";
139+
final String expectedValue = "Hello world";
153140
final File file = new File("src/test/resources/test1.in");
154141

155142
final ByteSource source = Files.asByteSource(file);
156143

157144
final byte[] result = source.read();
158-
assertEquals(expected_value, new String(result));
145+
assertEquals(expectedValue, new String(result));
159146
}
160147

161148
@Test
162149
public void whenReadAfterOffsetUsingByteSource_thenRead() throws IOException {
163-
final String expected_value = "lo world";
150+
final String expectedValue = "lo world";
164151
final File file = new File("src/test/resources/test1.in");
165152

166153
final long offset = 3;
167154
final long length = 1000;
168155
final ByteSource source = Files.asByteSource(file).slice(offset, length);
169156

170157
final byte[] result = source.read();
171-
assertEquals(expected_value, new String(result));
158+
assertEquals(expectedValue, new String(result));
172159
}
173160

174161
@Test
175162
public void whenReadUsingByteStream_thenRead() throws IOException {
176-
final String expected_value = "Hello world";
163+
final String expectedValue = "Hello world";
177164

178165
final FileInputStream reader = new FileInputStream("src/test/resources/test1.in");
179166
final byte[] result = ByteStreams.toByteArray(reader);
180167
reader.close();
181168

182-
assertEquals(expected_value, new String(result));
169+
assertEquals(expectedValue, new String(result));
183170
}
184171

185172
@Test
186173
public void whenReadUsingResources_thenRead() throws IOException {
187-
final String expected_value = "Hello world";
174+
final String expectedValue = "Hello world";
188175

189176
final URL url = Resources.getResource("test1.in");
190177
final String result = Resources.toString(url, Charsets.UTF_8);
191178

192-
assertEquals(expected_value, result);
179+
assertEquals(expectedValue, result);
193180
}
194181

195182
@Test
196183
public void whenCopyFileUsingFiles_thenCopied() throws IOException {
197-
final String expected_value = "Hello world";
184+
final String expectedValue = "Hello world";
198185

199186
final File file1 = new File("src/test/resources/test1.in");
200187
final File file2 = new File("src/test/resources/test_copy.in");
201188

202189
Files.copy(file1, file2);
203190
final String result = Files.toString(file2, Charsets.UTF_8);
204191

205-
assertEquals(expected_value, result);
192+
assertEquals(expectedValue, result);
206193
}
207194

208195
@Test
@@ -222,12 +209,3 @@ public void whenWriteReadLittleEndian_thenCorrect() throws IOException {
222209

223210

224211
}
225-
226-
//
227-
228-
//
229-
//
230-
//
231-
//
232-
//
233-

guava/src/test/resources/test.out

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
John Jane Adam Tom
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello world
4 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)