Command Line
To run MockMaker, execute 'java mockmaker.MockMaker INTERFACE_NAME' where INTERFACE_NAME is the name of the java interface for which you want to create a mock object class. MockMaker will then write the source code for the mock object class onto standard output. In order to write to a file, execute 'java mockmaker.MockMaker INTERFACE_NAME > FILE_NAME'.
Stand alone GUI
To run the MockMaker GUI, execute 'java org.subconscious.mockmaker.gui.MockMakerGUI'. This launches a GUI from where you can chose the INTERFACE .class file and the Mock implementation source file.
Configuration
You can change the naming of methods that MockMaker produces, by editing the file "mockmaker.cfg" as appropriate, and making sure it is on the classpath. An example file "old.cfg" gives the naming conventions that version 1.01 of mockmaker used; to use these conventions, delete the file "mockmaker.cfg" and rename "old.cfg" to "mockmaker.cfg" and make sure it is on the classpath.
Example
Execute 'java mockmaker.MockMaker mockmaker.tests.AcceptableInterface' and you should get the some java source code printed on standard output. Save this source code as "MockAcceptableInterface.java".
Alternatively, launch the GUI, and select the .class file "INSTALL_DIR\mockmaker\tests\AcceptableInterface" select directory "INSTALL_DIR" and type "MockAcceptableInterface.java" as the source file name and press the 'Make' button. Compile this source file - note that to compile this source file, you will have to edit it to include an import statement "import mockmaker.tests.*;".
MockAcceptableInterface is a "mock" implementation of the interface AcceptableInterface. An instance of MockAcceptableInterface can be used to test objects that use AcceptableInterface objects. For example, using an instance of AcceptableInterface called "foo":
* to test that method "minimalMethod" of foo is called twice, use "foo.setExpectedMinimalMethodCalls(2)" and "foo.verify()" to test that those calls happened
* to test that method "normalMethod" of foo is called with parameters "new Integer(4)" then "new Integer(2)", use "foo.addExpectedNormalMethodValues(new Integer(4)); foo.addExpectedNormalMethodValues(new Integer(2)); " and "foo.verify();" to test that those calls happened (Note that return values will also have to be set as in the example below, otherwise foo won't know what values to return when normalMethod is called)
* to set up method "normalMethod" to return "Hello" the first time it is called and "World" the second time it is called, use "foo.setupNormalMethod("Hello"); foo.setupNormalMethod("World");"
* NOTE that the line "keepUsingLastReturnValue=false" in the file "mockmaker.cfg" can be modified to "keepUsingLastReturnValue=true" in order to make the MockObjects created by MockMaker continue using the last value set by the appropriate "setup" method rather than running out of return values if enough values have not been set. This allows the "setup" methods the equivalent behaviour of previous versions of MockMaker where a single return value was set and always returned.
To learn more about MockObjects, see the MockObjects web site.
|