From: Jeff M. <cus...@us...> - 2002-09-09 09:31:42
|
Update of /cvsroot/mockobjects/mockobjects-java/doc/html In directory usw-pr-cvs1:/tmp/cvs-serv13765/html Modified Files: faq.html Log Message: More answers Index: faq.html =================================================================== RCS file: /cvsroot/mockobjects/mockobjects-java/doc/html/faq.html,v retrieving revision 1.3 retrieving revision 1.4 diff -u -r1.3 -r1.4 --- faq.html 6 Sep 2002 12:53:04 -0000 1.3 +++ faq.html 9 Sep 2002 09:31:39 -0000 1.4 @@ -81,13 +81,11 @@ </p> <h2>About the Mock Object Implementation</h2> - <h3>Why do I have to call setup???? to instead of set??? to add something to a map?</h3> <p> </p> - <h3>How do I contribute changes back to the mock objects project?</h3> <p> If you've made changes to any of the mock objects we'd love to see them an @@ -102,7 +100,7 @@ used we don't write any mock code in them until someone has a need for it. In order to make it easier to tell with methods have been implemented and which haven't any method which has not been implemented will throw a -NotImplementedException when it is called. If this happens during a test you can +<code>NotImplementedException</code> when it is called. If this happens during a test you can either write an implementation for the method and send us a patch for it, or mail us with details of how you'd like to use the method and we'll try(spare time permitting) to implement it. @@ -111,30 +109,77 @@ <h3>How do I write a mock?</h3> <p> + Simple put you just need to extends <code>com.mockobjects.MockObjects</code> implement +your chosen interface and sprinkle some expectations about and your done. +e.g.</p> +<pre> +pubic class MockMyInterface extends MockObject implements MyInterface{ + + private final ExpectationValue something = + new ExpectationValue("something"); + + public void setSomething(SomeClass something){ + this.something.setActual(something); + } + + public void setExpectedSomething(SomeClass something){ + this.something.setExpected(something); + } +} +</pre> + <p> + easy really. </p> <h3>Why don't mocks verify their expectations?</h3> <p> + As you can see in the above example we don't have to explicitly call + <code>verify();</code> on each expectation. This is because the super class MockObject + will auto-magically call verify on an member variables which implement + <code>Expectation</code> </p> <h3>What are the alt.* packages for?</h3> <p> + The <code>alt.*</code> packages are to help get around some of the limitations of other peoples class libraries.</p> + <p>Generally these classes are very simple wrappers around classes which are +constructed in such a way that they cannot be mocked. An example of this is +<code>java.io.File</code> which is concrete class marked as final this provides +us with no way to mock it other than to wrap it in a mockable wrapper. + </p> + <p>Each alt implementation consists of an interface, +an wrapper class and a mock. In some cases there will also be a factory +interface with mock and real implementations. </p> - <h3>What do I do if I can't find a mock for a class?</h3> <p> + Easy one this, write one! Write as little of it as you possibly can, use +<code>notImplemented();</code> for any methods you don't use and send it to us +when your done.</p> + <p>You can try pursuading someone on the developer mailing list to do it for +your but it's probably quicker doing it yourself. </p> <h3>Are there any tools to help create mocks?</h3> <p> + Yes there are, currently we know of three. <a +href="http://www.mockmaker.org/"/>MockMaker</a>, <a +href="http://www.easymock.org/">EasyMock</a>, <a +href="http://www.abstrakt.de/mockcreator.html">MockCreator</a> and <a +href="http://joe.sitemesh.com/mockdoclet.html">MockDoclet</a> </p> <h3>Why are the internals of mock private when there just test class?</h3> + <p> + Because they can be. When your writing a test you shouldn't need to access +any of the internals of a mock objects. If you need to extends one of our mocks +you can just change the source code and send us the patch ;-) + </p> <h3>What is the best practise for integrating mocks into a project?</h3> <h2>Other Questions</h2> |