Skip to content

Commit

Permalink
test: fix unfinished stubbing of command response writer
Browse files Browse the repository at this point in the history
The engine is shared across multiple tests and not stopped in-between.
With this change we only set up mocking of the response writer once and
not for every test method. This ensures that mocking does not interfere
with engine processing from previous tests which would show up as
unfinished mocking exceptions.
  • Loading branch information
lenaschoenburg committed Oct 7, 2022
1 parent f6ca10e commit 15a55cc
Showing 1 changed file with 11 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,26 +36,29 @@ public final class CreateProcessInstanceWithResultTest {
@ClassRule public static final EngineRule ENGINE = EngineRule.singlePartition();
private static final BpmnModelInstance PROCESS =
Bpmn.createExecutableProcess("PROCESS").startEvent().endEvent().done();
private static ProcessInstanceResultRecord response;
private static CommandResponseWriter mockCommandResponseWriter;

@Rule
public final RecordingExporterTestWatcher recordingExporterTestWatcher =
new RecordingExporterTestWatcher();

private ProcessInstanceResultRecord response;
private CommandResponseWriter mockCommandResponseWriter;

@BeforeClass
public static void init() {
ENGINE.deployment().withXmlResource(PROCESS).deploy();
}

@Before
public void setUp() {
@BeforeClass
public static void setUp() {
mockCommandResponseWriter = ENGINE.getCommandResponseWriter();
Mockito.clearInvocations(mockCommandResponseWriter);
interceptResponseWriter(mockCommandResponseWriter);
}

@Before
public void reset() {
Mockito.clearInvocations(mockCommandResponseWriter);
}

@Test
public void shouldSendResultAfterCompletion() {
// given
Expand Down Expand Up @@ -159,7 +162,8 @@ public void shouldSendRejectionImmediately() {
verify(ENGINE.getCommandResponseWriter(), timeout(1000).times(1)).tryWriteResponse(3, 3);
}

private void interceptResponseWriter(final CommandResponseWriter mockCommandResponseWriter) {
private static void interceptResponseWriter(
final CommandResponseWriter mockCommandResponseWriter) {
doAnswer(
(Answer<CommandResponseWriter>)
(invocation -> {
Expand Down

0 comments on commit 15a55cc

Please sign in to comment.