Skip to content

Commit 46c56e6

Browse files
author
Stephen Colebourne
committed
IO-94 - MockInputStream/MockReader
git-svn-id: https://svn.apache.org/repos/asf/jakarta/commons/proper/io/trunk@462847 13f79535-47bb-0310-9956-ffa450edef68
1 parent 45a0b1f commit 46c56e6

5 files changed

Lines changed: 17 additions & 15 deletions

File tree

src/java/org/apache/commons/io/input/MockInputStream.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
* <code>processBytes()</code> methods can be implemented to generate
3939
* test data.
4040
*
41-
*
4241
* @since Commons IO 1.3
4342
* @version $Revision$
4443
*/
@@ -53,7 +52,8 @@ public class MockInputStream extends InputStream {
5352
private boolean markSupported;
5453

5554
/**
56-
* Create a mock {@link InputStream} of the specified size.
55+
* Create a mock {@link InputStream} of the specified size
56+
* which supports marking and does not throw EOFException.
5757
*
5858
* @param size The size of the mock input stream.
5959
*/
@@ -113,7 +113,7 @@ public int available() {
113113
}
114114

115115
/**
116-
* Close this inputstream - resets the internal state to
116+
* Close this input stream - resets the internal state to
117117
* the initial values.
118118
*
119119
* @throws IOException If an error occurs.
@@ -268,27 +268,27 @@ public long skip(long numberOfBytes) throws IOException {
268268
/**
269269
* Return a byte value for the <code>read()</code> method.
270270
* <p>
271-
* <strong>N.B.</strong> This implementation returns
272-
* zero.
271+
* This implementation returns zero.
273272
*
274273
* @return This implementation always returns zero.
275274
*/
276275
protected int processByte() {
276+
// do nothing - overridable by subclass
277277
return 0;
278278
}
279279

280280
/**
281281
* Process the bytes for the <code>read(byte[], offset, length)</code>
282282
* method.
283283
* <p>
284-
* <strong>N.B.</strong> This implementation leaves the byte
285-
* array unchanged.
284+
* This implementation leaves the byte array unchanged.
286285
*
287286
* @param bytes The byte array
288287
* @param offset The offset to start at.
289288
* @param length The number of bytes.
290289
*/
291290
protected void processBytes(byte[] bytes, int offset, int length) {
291+
// do nothing - overridable by subclass
292292
}
293293

294294
/**
@@ -306,4 +306,5 @@ private int doEndOfFile() throws EOFException {
306306
}
307307
return -1;
308308
}
309+
309310
}

src/java/org/apache/commons/io/input/MockReader.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@
3838
* <code>processChars()</code> methods can be implemented to generate
3939
* test data.
4040
*
41-
*
4241
* @since Commons IO 1.3
4342
* @version $Revision$
4443
*/
@@ -53,7 +52,8 @@ public class MockReader extends Reader {
5352
private boolean markSupported;
5453

5554
/**
56-
* Create a mock {@link Reader} of the specified size.
55+
* Create a mock {@link Reader} of the specified size
56+
* which supports marking and does not throw EOFException.
5757
*
5858
* @param size The size of the mock Reader.
5959
*/
@@ -252,27 +252,27 @@ public long skip(long numberOfChars) throws IOException {
252252
/**
253253
* Return a character value for the <code>read()</code> method.
254254
* <p>
255-
* <strong>N.B.</strong> This implementation returns
256-
* zero.
255+
* This implementation returns zero.
257256
*
258257
* @return This implementation always returns zero.
259258
*/
260259
protected int processChar() {
260+
// do nothing - overridable by subclass
261261
return 0;
262262
}
263263

264264
/**
265265
* Process the characters for the <code>read(char[], offset, length)</code>
266266
* method.
267267
* <p>
268-
* <strong>N.B.</strong> This implementation leaves the character
269-
* array unchanged.
268+
* This implementation leaves the character array unchanged.
270269
*
271270
* @param chars The character array
272271
* @param offset The offset to start at.
273272
* @param length The number of characters.
274273
*/
275274
protected void processChars(char[] chars, int offset, int length) {
275+
// do nothing - overridable by subclass
276276
}
277277

278278
/**
@@ -290,4 +290,5 @@ private int doEndOfFile() throws EOFException {
290290
}
291291
return -1;
292292
}
293+
293294
}

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,6 @@ public void testMarkNotSupported() throws Exception {
214214
* Test <code>skip()</code> method.
215215
*/
216216
public void testSkip() throws Exception {
217-
int skip = 20;
218217
InputStream input = new TestMockInputStream(10, true, false);
219218
assertEquals("Read 1", 0, input.read());
220219
assertEquals("Read 2", 1, input.read());

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,6 @@ public void testMarkNotSupported() throws Exception {
211211
* Test <code>skip()</code> method.
212212
*/
213213
public void testSkip() throws Exception {
214-
int skip = 20;
215214
Reader reader = new TestMockReader(10, true, false);
216215
assertEquals("Read 1", 0, reader.read());
217216
assertEquals("Read 2", 1, reader.read());

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@ public static Test suite() {
3535
TestSuite suite = new TestSuite("IO Utilities - input");
3636
suite.addTest(new TestSuite(ClassLoaderObjectInputStreamTest.class));
3737
suite.addTest(new TestSuite(CountingInputStreamTest.class));
38+
suite.addTest(new TestSuite(MockInputStreamTestCase.class));
39+
suite.addTest(new TestSuite(MockReaderTestCase.class));
3840
suite.addTest(new TestSuite(SwappedDataInputStreamTest.class));
3941
return suite;
4042
}

0 commit comments

Comments
 (0)