|
From: Jeff M. <je...@mk...> - 2002-11-08 09:49:14
|
Actually the MockObject class is a just a convenience, it handles the
reflection stuff that verifies the expectations. The important point is
that objects should be verifiable (i.e. implement the Verifiable
interface).
The other useful class is the Verifier class which will use reflection
to verify each expectation.
So you get this.
public class MockHandlerContext extends HandlerContext implements
Verifiable {
ExpectationValue logMsg = new ExpectationValue("log");
public void log(String message, Throwable t) {
super.log(message, t); // want to include behavior of super
mock.logMsg.setActual(message);
}
// Verifiable implemention
public void verify(){
Verifier.verify(this);
}
}
On Fri, 2002-11-08 at 08:34, Immanuel, Gidado-Yisa wrote:
> Hope I have not worn out my welcome :)
>
> I saw how to create a Mock object for an interface:
>
> public class MockMyInterface extends MockObject implements MyInterface
>
> But I did not see anything about how to do it for classes
> (including abstract classes). Below is my attempt to do
> so. My qustions is: is my example a typical mock pattern,
> or are there other/better patterns that I should be aware of?
>
> Thanks,
> Gidado
>
> MOCK ___________________________
>
> public class MockHandlerContext extends HandlerContext {
> public innerMock mock = new innerMock();// make it visible
>
> public void log(String message, Throwable t) {
> super.log(message, t); // want to include behavior of super
> mock.logMsg.setActual(message);
> }
>
> class innerMock extends MockObject {
> ExpectationValue logMsg = new ExpectationValue("log");
> public void setExpectedLogMessage(String msg) {
> logMsg.setExpected(msg);
> }
> }
>
> }
>
> TEST ____________________________________
>
> // fixutre stuff....
>
> public void testLog() {
> String val = "hello";
>
> context.mock.setExpectedLogMessage(val);
> handler.log(val);
> context.mock.verify();
> }
>
>
> -------------------------------------------------------
> This sf.net email is sponsored by: See the NEW Palm
> Tungsten T handheld. Power & Color in a compact size!
> http://ads.sourceforge.net/cgi-bin/redirect.pl?palm0001en
> _______________________________________________
> Mockobjects-java-dev mailing list
> Moc...@li...
> https://lists.sourceforge.net/lists/listinfo/mockobjects-java-dev
--
Jeff Martin <je...@mk...>
mkodo
|