Author Login
Post Reply
Hi all
I am new to jmock(started today) and i need to write a testcase using it.I
have created a testcase and posting the files for your reference.When i run
the test it runs fine,but i am not sure if i did the right testing.Could
some one help me?
package com.abc.testing;
public class Transaction
{
private String id;
public String getId()
{
return id;
}
public void setId(String id)
{
this.id = id;
}
public void fireListeners()
{
throw new UnsupportedOperationException(
"Sorry.. The developer responsible for "
+ "writing this class is not finished. Your test case should
not depend "
+ "on this method being implemented");
}
}
package com.abc.testing;
public class Dao
{
public void save(Transaction tx)
{
throw new UnsupportedOperationException(
"Sorry.. The developer responsible for "
+ "writing this class is not finished. Your test case should
not depend "
+ "on this method being implemented");
}
}
package com.abc.testing;
public class Processor
{
private Dao dao;
public Dao getDao()
{
return dao;
}
public void setDao(Dao dao)
{
this.dao = dao;
}
// TODO Write test cases for this method using JMock
public void process(Transaction tx)
{
tx.setId("1001");
tx.fireListeners();
dao.save(tx);
}
}
Now i need to write testcase for processor.process method.
Here is the code i wrote:
package com.abc.testing.test;
import org.jmock.Mock;
import org.jmock.MockObjectTestCase;
import com.abc.testing.Processor;
public class ProcessorTest extends MockObjectTestCase
{
private Processor processorTest;
private Mock mockTransaction;
private Mock mockDao;
protected void setUp()
{
mockTransaction = mock(Transaction.class);
mockDao = mock(Dao.class);
// transaction = (Transaction) mockTransaction.proxy();
processorTest = new Processor();
}
public void testProcess()
{
mockTransaction.expects(once()).method("setId").with(eq("1001"));
mockTransaction.expects(once()).method("fireListeners").withNoArguments();
mockDao.expects(once()).method("save").with(same(mockTransaction.proxy()));
processorTest.setDao((Dao) mockDao.proxy());
processorTest.process((Transaction) mockTransaction.proxy());
// assertEquals("1001", transaction.getId());
}
}
Please tell me what all i need to add.I wrote the code based on my little
understanding.Also assume the mock constructor params as interfaces.the test
runs successfully but i dont think i am doing what i want.
thanks
Sree
--
Sent from the jMock - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email