Versions Compared


  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

JDummy is a thin API which sits above JMock. It allows very succinct expectation setting code when the expectation code would normally involve many stubs.

The sections below illustrate using JDummy for the mocking parts of Using Testing Frameworks with Groovy.

The Item Storer Example

We are going to consider how you might use JDummy as part of testing the Item Storer Example.

Here is how we can test JavaStorer:

Code Block
// require(groupId:'jmock', artifactId:'jmock', version='1.2.0')
// require(groupId:'jmock', artifactId:'jmock-cglib', version='1.2.0')
// require(groupId:'junit', artifactId:'junit', version='3.8.2')
// require(groupId:'cglib', artifactId:'cglib-nodep', version='2.2_beta1')
// require(url:'', jar:'jdummy-1.3.3.jar')
import net.sf.jdummy.JDummyTestCase

class JDummyTest extends JDummyTestCase {
    def mockReverser, storer

    protected void setUp() throws Exception {
        mockReverser = mimicWithDummyValues(Reverser.class)
        storer = new JavaStorer(mockReverser)

    void testStorage() {
        expectReverse(123.456, -123.456)
        expectReverse('hello', 'olleh')
        checkReverse(123.456, -123.456)
        checkReverse('hello', 'olleh')

    def expectReverse(input, output) {
        // with is a keyword in Groovy so we quote it

    def checkReverse(value, reverseValue) {
        assert value == storer.get()
        assert reverseValue == storer.getReverse()

def suite = new junit.framework.TestSuite()

Note: Our example is so simple, that JDummy's power is not really illustrated here.