|
|||||||||
| Home >> All >> com >> mockobjects >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
com.mockobjects.io
Class MockWriter

java.lang.Objectjava.io.Writer
com.mockobjects.io.MockWriter
- All Implemented Interfaces:
- com.mockobjects.Verifiable
- public class MockWriter
- extends java.io.Writer
- implements com.mockobjects.Verifiable
- extends java.io.Writer
A mock Writer.
Example usage
You may use the MockWriter like this:
public void testSomething() throws IOException {
MockWriter out = new MockWriter();
out.setExpectedSegment("some string");
out.setExpectedFlushCalls(1);
out.setExpectedCloseCalls(1);
ObjectUnderTest testee = new ObjectUnderTest(out);
out.verify();
// If we get here, the mock's flush() and close() methods were
// called exactly once each (order cannot be determined) and
// the write() method was called with the string "some string" in it.
}
| Field Summary | |
private com.mockobjects.ExpectationCounter |
closeCallsCount
|
private boolean |
closeShouldThrowException
|
private com.mockobjects.ExpectationCounter |
flushCallsCount
|
private boolean |
flushShouldThrowException
|
private com.mockobjects.ExpectationSegment |
segment
|
private boolean |
writeShouldThrowException
|
| Fields inherited from class java.io.Writer |
lock |
| Constructor Summary | |
MockWriter()
Instantiates a new mock writer which will act as a data sink. |
|
| Method Summary | |
void |
close()
Increments the close counter and asserts that this method was not called too many times. |
void |
flush()
This method will also throw an IOException if asked to do so by calling setFlushShouldThrowException() 55 . |
void |
setCloseShouldThrowException()
Sets the mock's behavior when closing. |
void |
setExpectedCloseCalls(int calls)
Sets the expected number of times that the close() 55 method will be called. |
void |
setExpectedFlushCalls(int calls)
Sets the expected number of times that the flush() 55 method will be called. |
void |
setExpectedSegment(java.lang.String aString)
Sets the value of the expected string segment. |
void |
setFlushShouldThrowException()
Sets the mock's behavior when flushing. |
void |
setWriteShouldThrowException()
Sets the mock's behavior when writing. |
void |
verify()
Throw an AssertionFailedException if any expectations have not been met. |
void |
write(char[] cbuf,
int off,
int len)
Either throws an exception or asserts a string segment for equality. |
| Methods inherited from class java.io.Writer |
write, write, write, write |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
segment
private com.mockobjects.ExpectationSegment segment
flushCallsCount
private com.mockobjects.ExpectationCounter flushCallsCount
closeCallsCount
private com.mockobjects.ExpectationCounter closeCallsCount
writeShouldThrowException
private boolean writeShouldThrowException
flushShouldThrowException
private boolean flushShouldThrowException
closeShouldThrowException
private boolean closeShouldThrowException
| Constructor Detail |
MockWriter
public MockWriter()
- Instantiates a new mock writer which will act as a data sink.
Once instantiated, mocks of this class do not expect anything special.
Once the object is instantiated, you should set your expectations using
the provided methods.
| Method Detail |
setWriteShouldThrowException
public void setWriteShouldThrowException()
- Sets the mock's behavior when writing.
If this method has been called, then
write(char[], int, int) 55 will throw an
IOException.
setFlushShouldThrowException
public void setFlushShouldThrowException()
- Sets the mock's behavior when flushing. If this method has been called,
then flush() 55 will throw
an IOException.
setCloseShouldThrowException
public void setCloseShouldThrowException()
- Sets the mock's behavior when closing.
If this method has been called, then close() 55 will
throw an IOException.
setExpectedFlushCalls
public void setExpectedFlushCalls(int calls)
- Sets the expected number of times that the flush() 55
method will be called.
setExpectedCloseCalls
public void setExpectedCloseCalls(int calls)
- Sets the expected number of times that the close() 55
method will be called.
setExpectedSegment
public void setExpectedSegment(java.lang.String aString)
- Sets the value of the expected string segment.
When the write(char[], int, int) 55 method
is called, a string is instantiated with the passed array and compared
to the
aStringparameter of this method. If the two strings differ, an junit.framework.AssertionFailedError will be thrown.
write
public void write(char[] cbuf,
int off,
int len)
throws java.io.IOException
- Either throws an exception or asserts a string segment for equality.
flush
public void flush()
throws java.io.IOException
- This method will also throw an IOException
if asked to do so by calling
setFlushShouldThrowException() 55 .
Please note that the call count will be incremented before the
check for the exception is done.
close
public void close()
throws java.io.IOException
- Increments the close counter and asserts that this method was not
called too many times.
This method will also throw an IOException
if asked to do so by calling
setCloseShouldThrowException() 55 .
Please note that the call count will be incremented before the
check for the exception is done.
verify
public void verify()
- Description copied from interface:
com.mockobjects.Verifiable - Throw an AssertionFailedException if any expectations have not been met.
- Specified by:
verifyin interfacecom.mockobjects.Verifiable
|
|||||||||
| Home >> All >> com >> mockobjects >> [ io overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC