consciouscode.junit
Class MockLogger
java.lang.Object
consciouscode.logging.AbstractLog
consciouscode.junit.MockLogger
- All Implemented Interfaces:
- Log
public class MockLogger
- extends AbstractLog
A Log
, used for testing, that ensures
that only expected errors are logged.
Debugging messages are simply ignored.
Methods inherited from class consciouscode.logging.AbstractLog |
debug, debug, doLog, error, fatal, info, info, isDebugEnabled, isErrorEnabled, isFatalEnabled, isInfoEnabled, isTraceEnabled, isWarnEnabled, setLogLevel, trace, trace, warn, warn |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
ANY_ERROR
public static final String ANY_ERROR
- This constant can by supplied to
expectError(String)
to
indicate that an error of any kind is expected.
- See Also:
- Constant Field Values
MockLogger
public MockLogger()
expectError
public void expectError(String regex)
- Indicate that one error of a particular kind is expected.
The next call to
error
will succeed, thereby meeting
the expectation, if and only if it has a matching message.
Further calls to error
will cause an assertion failure.
The given regex
will automatically be surrounded by
".*"
on both ends, so test cases will be insulated from changes
to code paths etc.
- Parameters:
regex
- the message that must be matched by the
next logged error. If this value is ANY_ERROR
, then
any one error may be logged.- See Also:
expectError()
expectError
public void expectError()
- Indicate that one error of any kind is to be expected.
A single subsequent call to
error
will succeed, thereby
meeting the expectation.
Further calls to error
will cause an assertion failure.
This is equivalent to calling expectError(ANY_ERROR)
.
verify
public void verify()
- Ensure that the error given to
expectedError
actually
occurred. If not, raise an assertion failure.
error
public void error(Object message,
Throwable cause)
- Specified by:
error
in interface Log
- Overrides:
error
in class AbstractLog
fatal
public void fatal(Object message,
Throwable t)
- Specified by:
fatal
in interface Log
- Overrides:
fatal
in class AbstractLog
doLog
protected void doLog(String message,
Throwable exception)
- Specified by:
doLog
in class AbstractLog
Copyright © 2001–2012
Todd V. Jonker. All Rights Reserved.