This is getting a bit off topic for the tapestry user's list... I suggest you do some further reading on mockito
It would probably look something like this: Link link = mock(Link.class); when(link.toAbsoluteURI()).thenReturn("http://test1"); when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, ETSSEnum.SUPERVISOR, 1L).thenReturn(link); There's also the thenAnswer() for more complex cases. Again... check the mockito docs... not really for this list. On 10 September 2014 19:43, George Christman <gchrist...@cardaddy.com> wrote: > Lance, I think I'm really close lol. I think my struggles have to do with > the concept of having to mock a service. > > Anyhow I have the following mock > > public static PageRenderLinkSource buildPageRenderLinkSource() { > PageRenderLinkSource pageRenderLinkSource = > Mockito.mock(PageRenderLinkSource.class); > > when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, > ETSSEnum.SUPERVISOR, 1L).toAbsoluteURI()).thenReturn("http://test1"); > > when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, > ETSSEnum.SUPERVISOR, 2L).toAbsoluteURI()).thenReturn("http://test2"); > > when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, > ETSSEnum.SUPERVISOR, 3L).toAbsoluteURI()).thenReturn("http://test3"); > > when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, > ETSSEnum.SUPERVISOR, 4L).toAbsoluteURI()).thenReturn("http://test4"); > > when(pageRenderLinkSource.createPageRenderLinkWithContext(TimeSheet.class, > ETSSEnum.SUPERVISOR, 5L).toAbsoluteURI()).thenReturn("http://test5"); > return pageRenderLinkSource; > } > > The service calls it like so > > @Override > public String getTimeSheetURL(TimeSheetEntity timeSheet, ETSSEnum role) > { > System.out.println(role + " " + timeSheet.getId()); > return linkSource.createPageRenderLinkWithContext(TimeSheet.class, > role, timeSheet.getId()).toAbsoluteURI(); > } > > And now I get the following exception, any idea what I might be missing? > > [TestNG] Running: > Command line suite > > [WARN ] (ConfigContext.java:257) - HSEARCH000075: Configuration setting > hibernate.search.lucene_version was not specified, using LUCENE_CURRENT. > [WARN ] (Config.java:360) - You should not use LUCENE_CURRENT as > luceneMatchVersion property: if you use this setting, and then Solr > upgrades to a newer release of Lucene, sizable changes may happen. If > precise back compatibility is important then you should instead explicitly > specify an actual Lucene version. > testSendEmailReport size 5 > supervisor 1 > [ERROR] (OperationTrackerImpl.java:192) - Error invoking method public > static org.apache.tapestry5.services.PageRenderLinkSource > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource(): > java.lang.NullPointerException > [ERROR] (OperationTrackerImpl.java:193) - Operations trace: > [ERROR] (OperationTrackerImpl.java:202) - [ 1] Realizing service > PageRenderLinkSource > [ERROR] (OperationTrackerImpl.java:202) - [ 2] Instantiating service > PageRenderLinkSource implementation via > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource() > (at AppModuleTest.java:155) > [ERROR] (OperationTrackerImpl.java:202) - [ 3] Constructing service > implementation via > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource() > (at AppModuleTest.java:155) > [ERROR] (RecursiveServiceCreationCheckWrapper.java:65) - Construction of > service PageRenderLinkSource failed: Error invoking method public static > org.apache.tapestry5.services.PageRenderLinkSource > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource(): > java.lang.NullPointerException > org.apache.tapestry5.ioc.internal.OperationException: Error invoking method > public static org.apache.tapestry5.services.PageRenderLinkSource > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource(): > java.lang.NullPointerException > at > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.logAndRethrow(OperationTrackerImpl.java:184) > at > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:90) > at > > org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:72) > at > > org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1258) > at > > org.apache.tapestry5.ioc.internal.util.ConstructionPlan.createObject(ConstructionPlan.java:61) > at > > org.apache.tapestry5.ioc.internal.ServiceBuilderMethodInvoker.createObject(ServiceBuilderMethodInvoker.java:61) > at > > org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47) > at > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82) > at > > org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:72) > at > > org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1258) > at > > org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:51) > at > > org.apache.tapestry5.ioc.internal.SingletonServiceLifecycle.createService(SingletonServiceLifecycle.java:30) > at > > org.apache.tapestry5.ioc.internal.LifecycleWrappedServiceCreator.createObject(LifecycleWrappedServiceCreator.java:47) > at > > org.apache.tapestry5.ioc.internal.AdvisorStackBuilder.createObject(AdvisorStackBuilder.java:64) > at > > org.apache.tapestry5.ioc.internal.InterceptorStackBuilder.createObject(InterceptorStackBuilder.java:55) > at > > org.apache.tapestry5.ioc.internal.RecursiveServiceCreationCheckWrapper.createObject(RecursiveServiceCreationCheckWrapper.java:61) > at > > org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator$1.invoke(OperationTrackingObjectCreator.java:47) > at > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82) > at > > org.apache.tapestry5.ioc.internal.PerThreadOperationTracker.invoke(PerThreadOperationTracker.java:72) > at > > org.apache.tapestry5.ioc.internal.RegistryImpl.invoke(RegistryImpl.java:1258) > at > > org.apache.tapestry5.ioc.internal.OperationTrackingObjectCreator.createObject(OperationTrackingObjectCreator.java:51) > at > > org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.obtainObjectFromCreator(JustInTimeObjectCreator.java:67) > at > > org.apache.tapestry5.ioc.internal.services.JustInTimeObjectCreator.createObject(JustInTimeObjectCreator.java:55) > at $PageRenderLinkSource_4090b27e85db6.delegate(Unknown Source) > at > $PageRenderLinkSource_4090b27e85db6.createPageRenderLinkWithContext(Unknown > Source) > at > > org.healthresearch.etss.services.email.impl.EmailHelperImpl.getTimeSheetURL(EmailHelperImpl.java:69) > at > > org.healthresearch.etss.services.email.impl.EmailHelperImpl.initiateSupervisorReminder(EmailHelperImpl.java:45) > at $EmailHelper_4090b27e85dbd.initiateSupervisorReminder(Unknown > Source) > at $EmailHelper_4090b27e85dbc.initiateSupervisorReminder(Unknown > Source) > at > > org.healthresearch.etss.services.email.impl.EmailServiceImpl.sendSupervisorReminderEmail(EmailServiceImpl.java:123) > at $EmailService_4090b27e85db4.sendSupervisorReminderEmail(Unknown > Source) > at $EmailService_4090b27e85d95.sendSupervisorReminderEmail(Unknown > Source) > at > > org.healthresearch.etss.services.email.impl.EmailServiceImplTest.testSendEmailReport(EmailServiceImplTest.java:52) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:601) > at > > org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:80) > at org.testng.internal.Invoker.invokeMethod(Invoker.java:702) > at org.testng.internal.Invoker.invokeTestMethod(Invoker.java:894) > at org.testng.internal.Invoker.invokeTestMethods(Invoker.java:1219) > at > > org.testng.internal.TestMethodWorker.invokeTestMethods(TestMethodWorker.java:127) > at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:111) > at org.testng.TestRunner.privateRun(TestRunner.java:768) > at org.testng.TestRunner.run(TestRunner.java:617) > at org.testng.SuiteRunner.runTest(SuiteRunner.java:334) > at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:329) > at org.testng.SuiteRunner.privateRun(SuiteRunner.java:291) > at org.testng.SuiteRunner.run(SuiteRunner.java:240) > at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:53) > at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:87) > at org.testng.TestNG.runSuitesSequentially(TestNG.java:1188) > at org.testng.TestNG.runSuitesLocally(TestNG.java:1113) > at org.testng.TestNG.run(TestNG.java:1025) > at org.testng.TestNG.privateMain(TestNG.java:1328) > at org.testng.TestNG.main(TestNG.java:1297) > Caused by: java.lang.RuntimeException: Error invoking method public static > org.apache.tapestry5.services.PageRenderLinkSource > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource(): > java.lang.NullPointerException > at > > org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:63) > at > > org.apache.tapestry5.ioc.internal.util.LoggingInvokableWrapper.invoke(LoggingInvokableWrapper.java:43) > at > > org.apache.tapestry5.ioc.internal.OperationTrackerImpl.invoke(OperationTrackerImpl.java:82) > ... 54 more > Caused by: java.lang.NullPointerException > at > > org.healthresearch.etss.services.AppModuleTest.buildPageRenderLinkSource(AppModuleTest.java:156) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at > > sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) > at > > sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) > at java.lang.reflect.Method.invoke(Method.java:601) > at > > org.apache.tapestry5.ioc.internal.util.MethodInvoker.invoke(MethodInvoker.java:52) > ... 56 more > > > > On Wed, Sep 10, 2014 at 1:14 PM, Lance Java <lance.j...@googlemail.com> > wrote: > > > Ah, ok.. > > > > Adding the tapestry web module will cause headaches. I suggest you add > > builder methods to your test module for the specific web dependencies > > required for the service under test. Similar to how the Request is > > currently mocked. > > On 10 Sep 2014 18:09, "George Christman" <gchrist...@cardaddy.com> > wrote: > > > > > Integration testing. > > > > > > On Wed, Sep 10, 2014 at 1:06 PM, Lance Java <lance.j...@googlemail.com > > > > > wrote: > > > > > > > There's 2 types of tests that I feel are getting blurred here > > > > > > > > 1. Unit test - tests a single class. All dependencies are mocked > > > > > > > > 2. Integration test - tests 2 or more services in concert (might > > involve > > > a > > > > tapestry module and an in memory database) > > > > > > > > Which test are you trying to achieve here? > > > > On 10 Sep 2014 17:53, "Lance Java" <lance.j...@googlemail.com> > wrote: > > > > > > > > > Unit tests don't need a module at all. Your colleague could mock > the > > > > > PageRenderLinkSource using Mockito and pass it to the EmailService > > > > > constructor. Then test the hell out of it! > > > > > On 10 Sep 2014 17:41, "George Christman" <gchrist...@cardaddy.com> > > > > wrote: > > > > > > > > > >> Thanks Lance, I figured out the DAO issue :) Anyhow this happens > to > > be > > > > my > > > > >> day job project and my co-worker is looking to test his generated > > > > emails. > > > > >> So if I understand you correctly, I need to include the > > tapestry-core? > > > > If > > > > >> so, is that just a mater of including TapestryModule or no? > > > > >> > > > > >> On Wed, Sep 10, 2014 at 12:29 PM, Lance Java < > > > lance.j...@googlemail.com > > > > > > > > > >> wrote: > > > > >> > > > > >> > Hi George, PageRenderLinkSource is a part of the web framework. > > > > >> > > > > > >> > I mentioned before that you could split your app into 2 modules: > > > > >> > api - depends on tapestry-ioc > > > > >> > web - depends on tapestry-core > > > > >> > > > > > >> > The test case I setup for you only tests the api stuff > > > (tapestry-ioc). > > > > >> If > > > > >> > you split into 2 modules this would be easy to see (since > > > > >> > PageRenderLinkSource would not be on the test classpath). > > > > >> > > > > > >> > > > > >> > > > > >> > > > > >> -- > > > > >> George Christman > > > > >> www.CarDaddy.com > > > > >> P.O. Box 735 > > > > >> Johnstown, New York > > > > >> > > > > > > > > > > > > > > > > > > > > > -- > > > George Christman > > > www.CarDaddy.com > > > P.O. Box 735 > > > Johnstown, New York > > > > > > > > > -- > George Christman > www.CarDaddy.com > P.O. Box 735 > Johnstown, New York >