Skip to content

Commit 5411db0

Browse files
TailerTest: clean-up is done in tearDown so remove clean-up from individual test methods
1 parent 722a5af commit 5411db0

1 file changed

Lines changed: 13 additions & 32 deletions

File tree

src/test/java/org/apache/commons/io/input/TailerTest.java

Lines changed: 13 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ public void testMultiByteBreak() throws Exception {
137137
out.close(); // ensure data is written
138138

139139
final long testDelayMillis = delay * 10;
140-
TestUtils.sleep(testDelayMillis);
140+
TestUtils.sleep(testDelayMillis);
141141
List<String> tailerlines = listener.getLines();
142142
assertEquals("line count",lines.size(),tailerlines.size());
143143
for(int i = 0,len = lines.size();i<len;i++){
@@ -149,8 +149,6 @@ public void testMultiByteBreak() throws Exception {
149149
+ "\nAct: (" + actual.length() + ") "+ actual);
150150
}
151151
}
152-
} finally{
153-
tailer.stop();
154152
}
155153
}
156154

@@ -161,30 +159,25 @@ public void testTailerEof() throws Exception {
161159
final File file = new File(getTestDirectory(), "tailer2-test.txt");
162160
createFile(file, 0);
163161
final TestTailerListener listener = new TestTailerListener();
164-
final Tailer tailer = new Tailer(file, listener, delay, false);
162+
tailer = new Tailer(file, listener, delay, false);
165163
final Thread thread = new Thread(tailer);
166164
thread.start();
167165

168166
// Write some lines to the file
169-
try {
170-
writeString(file, "Line");
167+
writeString(file, "Line");
171168

172-
TestUtils.sleep(delay * 2);
173-
List<String> lines = listener.getLines();
174-
assertEquals("1 line count", 0, lines.size());
169+
TestUtils.sleep(delay * 2);
170+
List<String> lines = listener.getLines();
171+
assertEquals("1 line count", 0, lines.size());
175172

176-
writeString(file, " one\n");
177-
TestUtils.sleep(delay * 2);
178-
lines = listener.getLines();
173+
writeString(file, " one\n");
174+
TestUtils.sleep(delay * 2);
175+
lines = listener.getLines();
179176

180-
assertEquals("1 line count", 1, lines.size());
181-
assertEquals("1 line 1", "Line one", lines.get(0));
177+
assertEquals("1 line count", 1, lines.size());
178+
assertEquals("1 line 1", "Line one", lines.get(0));
182179

183-
listener.clear();
184-
} finally {
185-
tailer.stop();
186-
TestUtils.sleep(delay * 2);
187-
}
180+
listener.clear();
188181
}
189182

190183
@Test
@@ -251,9 +244,6 @@ public void testTailer() throws Exception {
251244
assertEquals("Expected init to be called", 1 , listener.initialised);
252245
assertEquals("fileNotFound should not be called", 0 , listener.notFound);
253246
assertEquals("fileRotated should be be called", 1 , listener.rotated);
254-
tailer.stop();
255-
tailer=null;
256-
257247
}
258248

259249
@Test
@@ -345,7 +335,6 @@ public void testStopWithNoFile() throws Exception {
345335
tailer = Tailer.create(file, listener, delay, false);
346336
TestUtils.sleep(idle);
347337
tailer.stop();
348-
tailer=null;
349338
TestUtils.sleep(delay+idle);
350339
assertNull("Should not generate Exception", listener.exception);
351340
assertEquals("Expected init to be called", 1 , listener.initialised);
@@ -365,13 +354,12 @@ public void testInterrupt() throws Exception {
365354
// Use a long delay to try to make sure the test thread calls interrupt() while the tailer thread is sleeping.
366355
final int delay = 1000;
367356
final int idle = 50; // allow time for thread to work
368-
Tailer tailer = new Tailer(file, listener, delay, false, 4096);
357+
tailer = new Tailer(file, listener, delay, false, 4096);
369358
final Thread thread = new Thread(tailer);
370359
thread.setDaemon(true);
371360
thread.start();
372361
TestUtils.sleep(idle);
373362
thread.interrupt();
374-
tailer = null;
375363
TestUtils.sleep(delay + idle);
376364
assertNotNull("Missing InterruptedException", listener.exception);
377365
assertTrue("Unexpected Exception: " + listener.exception, listener.exception instanceof InterruptedException);
@@ -393,7 +381,6 @@ public void testStopWithNoFileUsingExecutor() throws Exception {
393381
exec.execute(tailer);
394382
TestUtils.sleep(idle);
395383
tailer.stop();
396-
tailer=null;
397384
TestUtils.sleep(delay+idle);
398385
assertNull("Should not generate Exception", listener.exception);
399386
assertEquals("Expected init to be called", 1 , listener.initialised);
@@ -423,12 +410,6 @@ public void testIO335() throws Exception { // test CR behaviour
423410
assertEquals("line 2", "LF", lines.get(1));
424411
assertEquals("line 3", "CR", lines.get(2));
425412
assertEquals("line 4", "CRCR\r", lines.get(3));
426-
427-
// Stop
428-
tailer.stop();
429-
tailer=null;
430-
thread.interrupt();
431-
TestUtils.sleep(testDelayMillis);
432413
}
433414

434415
/**

0 commit comments

Comments
 (0)