yes my test class have this setup method. package org.appfuse.tutorial.service.impl;
import java.util.ArrayList; import java.util.List; import org.appfuse.tutorial.dao.PersonDao; import org.appfuse.tutorial.model.Person; import org.appfuse.service.impl.BaseManagerMockTestCase; import org.jmock.Expectations; import org.junit.Before; import org.junit.After; import org.junit.Test; import static org.junit.Assert.*; The following is my test class. public class PersonManagerImplTest extends BaseManagerMockTestCase { private PersonManagerImpl manager = null; private PersonDao dao = null; @Before public void setUp() { dao = context.mock(PersonDao.class); manager = new PersonManagerImpl(dao); } @After public void tearDown() { manager = null; } @Test public void testGetPerson() { log.debug("testing get..."); final Long id = 7L; final Person person = new Person(); // set expected behavior on dao context.checking(new Expectations() {{ one(dao).get(with(equal(id))); will(returnValue(person)); }}); Person result = manager.get(id); assertSame(person, result); } @Test public void testGetPersons() { log.debug("testing getAll..."); final List persons = new ArrayList(); // set expected behavior on dao context.checking(new Expectations() {{ one(dao).getAll(); will(returnValue(persons)); }}); List result = manager.getAll(); assertSame(persons, result); } @Test public void testSavePerson() { log.debug("testing save..."); final Person person = new Person(); // enter all required fields // set expected behavior on dao context.checking(new Expectations() {{ one(dao).save(with(same(person))); }}); manager.save(person); } @Test public void testRemovePerson() { log.debug("testing remove..."); final Long id = -11L; // set expected behavior on dao context.checking(new Expectations() {{ one(dao).remove(with(equal(id))); }}); manager.remove(id); } Thnks Angela Mike Horwitz wrote: > > It looks like the object you are passing to the Expectation is not a mock > object? Does your test class have a setup method like: > > @Before > public void setUp() { > dao = context.mock(PersonDao.class); > manager = new PersonManagerImpl(dao); > } > > Mike > > 2008/8/26 angela leo <[EMAIL PROTECTED]> > >> >> Hai, >> >> I started just few days ago to work with AppFuse.I followed all tutorials >> starting from persistence to web.I am using the Appfuse 2.0.2 version and >> jmock.version 2.4.0.When running the mvn test >> -Dtest=PersonManagerImplTest >> in the appfuse tutorial, it is showing failure as shown below. Am I >> missing >> something ? >> Tests run: 4, Failures: 4, Errors: 0, Time elapsed: 0.095 sec >> >> class org.apache.maven.surefire.battery.JUnitBattery.testGetPerson() >> Time >> elapsed: 0.034 sec <<< FAILURE! >> >> [ stdout ] >> --------------------------------------------------------------- >> >> [ stderr ] >> --------------------------------------------------------------- >> >> [ stacktrace ] >> ----------------------------------------------------------- >> >> java.lang.IllegalArgumentException: can only set expectations on mock >> objects >> at >> >> org.jmock.internal.InvocationExpectationBuilder.captureExpectedObject(InvocationExpectationBuilder.java:67) >> at >> >> org.jmock.internal.InvocationExpectationBuilder.of(InvocationExpectationBuilder.java:107) >> at org.jmock.Expectations.one(Expectations.java:89) >> at >> >> org.appfuse.tutorial.service.impl.PersonManagerImplTest$1.<init>(PersonManagerImplTest.java:53) >> at >> >> org.appfuse.tutorial.service.impl.PersonManagerImplTest.testGetPerson(PersonManagerImplTest.java:52) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> at >> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:597) >> at >> >> org.apache.maven.surefire.battery.AbstractBattery.executeTestMethod(AbstractBattery.java:124) >> at >> >> org.apache.maven.surefire.battery.AbstractBattery.executeTestMethods(AbstractBattery.java:70) >> at >> >> org.apache.maven.surefire.battery.AbstractBattery.execute(AbstractBattery.java:49) >> at >> >> org.apache.maven.surefire.battery.JUnitBattery.execute(JUnitBattery.java:208) >> at >> org.apache.maven.surefire.Surefire.executeBattery(Surefire.java:217) >> at org.apache.maven.surefire.Surefire.run(Surefire.java:165) >> at org.apache.maven.surefire.Surefire.run(Surefire.java:89) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> at >> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:597) >> at >> >> org.apache.maven.surefire.SurefireBooter.runTestsInProcess(SurefireBooter.java:246) >> at >> org.apache.maven.surefire.SurefireBooter.run(SurefireBooter.java:195) >> at >> org.apache.maven.test.SurefirePlugin.execute(SurefirePlugin.java:366) >> at >> >> org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPluginManager.java:443) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(DefaultLifecycleExecutor.java:539) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLifecycle(DefaultLifecycleExecutor.java:480) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(DefaultLifecycleExecutor.java:459) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHandleFailures(DefaultLifecycleExecutor.java:311) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegments(DefaultLifecycleExecutor.java:278) >> at >> >> org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLifecycleExecutor.java:143) >> at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:334) >> at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:125) >> at org.apache.maven.cli.MavenCli.main(MavenCli.java:280) >> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >> at >> >> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) >> at >> >> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) >> at java.lang.reflect.Method.invoke(Method.java:597) >> at >> org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315) >> at org.codehaus.classworlds.Launcher.launch(Launcher.java:255) >> at >> org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430) >> at org.codehaus.classworlds.Launcher.main(Launcher.java:375) >> >> Any ideas or help? Thanks a lot. >> Regards. >> Angela >> >> -- >> View this message in context: >> http://www.nabble.com/can-only-set-expectations-on-mock-objects-tp19156091s2369p19156091.html >> Sent from the AppFuse - User mailing list archive at Nabble.com. >> >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: [EMAIL PROTECTED] >> For additional commands, e-mail: [EMAIL PROTECTED] >> >> > > -- View this message in context: http://www.nabble.com/Re%3A-can-only-set-expectations-on-mock-objects-tp19167715s2369p19195102.html Sent from the AppFuse - User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]