File tree Expand file tree Collapse file tree 4 files changed +14
-0
lines changed
core/src/test/java/io/temporal/samples/nexus/caller Expand file tree Collapse file tree 4 files changed +14
-0
lines changed Original file line number Diff line number Diff line change 1616// This is an example of how to unit test Nexus services in JUnit5. The handlers are mocked,
1717// so that the caller classes interact with the mocks and not the handler classes themselves.
1818
19+ // @@@SNIPSTART java-nexus-sample-junit5-mock
1920public class CallerWorkflowJunit5MockTest {
2021
2122 // Sync Nexus operations run inline in the handler thread — there is no backing workflow to
@@ -77,3 +78,5 @@ public void testEchoWorkflow(
7778 testEnv .shutdown ();
7879 }
7980}
81+
82+ // @@@SNIPEND
Original file line number Diff line number Diff line change 1717// This is an example of how to unit test Nexus services in JUnit4. The handlers are mocked,
1818// so that the caller classes interact with the mocks and not the handler classes themselves.
1919
20+ // @@@SNIPSTART java-nexus-sample-junit4-mock
2021public class CallerWorkflowMockTest {
2122
2223 // Inject a mock EchoClient so sync Nexus operations can be stubbed per test.
@@ -90,3 +91,5 @@ public void testEchoWorkflow() {
9091 testWorkflowRule .getTestEnvironment ().shutdown ();
9192 }
9293}
94+
95+ // @@@SNIPEND
Original file line number Diff line number Diff line change 1818// This is the path to take when you don't have access to the service implementation so
1919// cannot mock it. Since the SampleNexusService itself is mocked,
2020// no handlers need to be set up or mocked.
21+
22+ // @@@SNIPSTART java-nexus-service-sample-junit4-mock
2123public class NexusServiceJunit5Test {
2224
2325 private final SampleNexusService mockNexusService = mock (SampleNexusService .class );
@@ -103,3 +105,5 @@ public void testEchoWorkflow(
103105 verifyNoMoreInteractions (mockNexusService );
104106 }
105107}
108+
109+ // @@@SNIPEND
Original file line number Diff line number Diff line change 1717// This is the path to take when you don't have access to the service implementation so
1818// cannot mock it. Since the SampleNexusService itself is mocked,
1919// no handlers need to be set up or mocked.
20+
21+ // @@@SNIPSTART java-nexus-service-sample-junit4-mock
2022public class NexusServiceMockTest {
2123
2224 private final SampleNexusService mockNexusService = mock (SampleNexusService .class );
@@ -102,3 +104,5 @@ public void testEchoCallerWithMockedService() {
102104 verifyNoMoreInteractions (mockNexusService );
103105 }
104106}
107+
108+ // @@@SNIPEND
You can’t perform that action at this time.
0 commit comments