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.

While both versions of `interceptResponseWriter` should be equivalent,
the previous version would sometimes fail with an
`UnfinishedStubbingException`.
  • Loading branch information
oleschoenburg committed Oct 7, 2022
1 parent f6ca10e commit e7821af
Showing 1 changed file with 11 additions and 6 deletions.
Expand Up @@ -41,21 +41,25 @@ public final class CreateProcessInstanceWithResultTest {
public final RecordingExporterTestWatcher recordingExporterTestWatcher =
new RecordingExporterTestWatcher();

private ProcessInstanceResultRecord response;
private CommandResponseWriter mockCommandResponseWriter;
private static ProcessInstanceResultRecord response;
private static 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 +163,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 e7821af

Please sign in to comment.