Skip to content

Commit fb9d4d5

Browse files
committed
Add more checks to ensure callbacks called as expected
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/io/trunk@1003112 13f79535-47bb-0310-9956-ffa450edef68
1 parent cdc2dad commit fb9d4d5

1 file changed

Lines changed: 24 additions & 4 deletions

File tree

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

Lines changed: 24 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ public void testTailer() throws Exception {
8787
Thread.sleep(delay * 2);
8888
write(file, "Line five");
8989
assertEquals("4 line count", 0, listener.getLines().size());
90+
assertNull("Should not generate Exception", listener.exception);
91+
assertEquals("Expected init to be called", 1 , listener.initialised);
92+
assertEquals("fileNotFound should not be called", 0 , listener.notFound);
93+
assertEquals("fileRotated should be be called", 1 , listener.rotated);
9094
}
9195

9296
/** Start a tailer */
@@ -120,19 +124,27 @@ public void testStopWithNoFile() throws Exception {
120124
Thread.sleep(idle);
121125
tailer.stop();
122126
Thread.sleep(delay+idle);
123-
assertNull(listener.exception);
127+
assertNull("Should not generate Exception", listener.exception);
128+
assertEquals("Expected init to be called", 1 , listener.initialised);
129+
assertEquals("fileNotFound should be called", 1 , listener.notFound);
130+
assertEquals("fileRotated should be not be called", 0 , listener.rotated);
124131
}
125132

126133
/**
127134
* Test {@link TailerListener} implementation.
128135
*/
129-
private static class TestTailerListener extends TailerListenerAdapter {
136+
private static class TestTailerListener implements TailerListener {
130137

131138
private final List<String> lines = new ArrayList<String>();
132139

133140
volatile Exception exception = null;
134141

135-
@Override
142+
volatile int notFound = 0;
143+
144+
volatile int rotated = 0;
145+
146+
volatile int initialised = 0;
147+
136148
public void handle(String line) {
137149
lines.add(line);
138150
}
@@ -142,9 +154,17 @@ public List<String> getLines() {
142154
public void clear() {
143155
lines.clear();
144156
}
145-
@Override
146157
public void handle(Exception e) {
147158
exception = e;
148159
}
160+
public void init(Tailer tailer) {
161+
initialised++; // not atomic, but OK because only updated here.
162+
}
163+
public void fileNotFound() {
164+
notFound++; // not atomic, but OK because only updated here.
165+
}
166+
public void fileRotated() {
167+
rotated++; // not atomic, but OK because only updated here.
168+
}
149169
}
150170
}

0 commit comments

Comments
 (0)