Vincent
"possibilities for writing a
MO implementation... do not write an implementation at all ! (that's JDK
1.3) or have a very
simple and generic implementation (JDK < 1.3) and delegate the logic of what
the mock method will do to your test case. "
Exactly.
"This means something like :...
"---
MockHttpServletRequest mock = new MockHttpServletRequest();
mock.expectValue("Value expected");
ServletToTest servlet = new SevletToTest();
String result = servlet.doSomething(mock);
assertEquals("Value expected", result);
---
"I seem to like more and more option 2/ ! Which is what I believe you are
saying, right ?"
Actually, no. That is how the EasyMock project you pointed me too works.
With the patterns in my article, you actually provide method implementations
for mock objects *within the scope of the particular test.* That means with
the actual testXXX() method itself. No additional libraries are required
because you are directly using some advanced features of the Java platform.
There are code examples in the article both for doing this with existing
base implementing classes and with the Proxy class of JDK 1.3 for
interfaces.
"Now that I think I understand better what you mean, I'll reread your
article
and give you my feedback."
Please let me know if you have any questions or if you see ways to explain
things more elegantly. I do iterative development on all things, including
articles.
Tom