Source:
void receivesAndAutoCompletes() { final ReceiverOptions options = new ReceiverOptions(ReceiveMode.PEEK_LOCK, PREFETCH); final ServiceBusReceiverAsyncClient consumer2 = new ServiceBusReceiverAsyncClient( NAMESPACE, ENTITY_PATH, MessagingEntityType.QUEUE, options, connectionProcessor, tracerProvider, messageSerializer, messageContainer, onClientClose); final UUID lockToken1 = UUID.randomUUID(); final UUID lockToken2 = UUID.randomUUID(); final Instant expiration = Instant.now().plus(Duration.ofMinutes(1)); final MessageWithLockToken message = mock(MessageWithLockToken.class); final MessageWithLockToken message2 = mock(MessageWithLockToken.class); when(message.getLockToken()).thenReturn(lockToken1); when(message2.getLockToken()).thenReturn(lockToken2); when(messageSerializer.deserialize(message, ServiceBusReceivedMessage.class)).thenReturn(receivedMessage); when(messageSerializer.deserialize(message2, ServiceBusReceivedMessage.class)).thenReturn(receivedMessage2); when(receivedMessage.getLockToken()).thenReturn(lockToken1.toString()); when(receivedMessage.getLockedUntil()).thenReturn(expiration); when(receivedMessage2.getLockToken()).thenReturn(lockToken2.toString()); when(receivedMessage2.getLockedUntil()).thenReturn(expiration); when(connection.getManagementNode(ENTITY_PATH, ENTITY_TYPE)) .thenReturn(Mono.just(managementNode)); when(managementNode.updateDisposition(eq(lockToken1.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull())) .thenReturn(Mono.empty()); when(managementNode.updateDisposition(eq(lockToken2.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull())) .thenReturn(Mono.empty()); StepVerifier.create(consumer2.receive().take(2)) .then(() -> { messageSink.next(message); messageSink.next(message2); }) .expectNext(receivedMessage) .expectNext(receivedMessage2) .thenAwait(Duration.ofSeconds(5)) .verifyComplete(); logger.info("Verifying assertions."); verify(managementNode).updateDisposition(eq(lockToken1.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull()); }

Target:
void receivesAndAutoCompletes() { final ReceiverOptions options = new ReceiverOptions(ReceiveMode.PEEK_LOCK, PREFETCH, null); final ServiceBusReceiverAsyncClient consumer2 = new ServiceBusReceiverAsyncClient( NAMESPACE, ENTITY_PATH, MessagingEntityType.QUEUE, options, connectionProcessor, tracerProvider, messageSerializer, messageContainer, onClientClose); final UUID lockToken1 = UUID.randomUUID(); final UUID lockToken2 = UUID.randomUUID(); final Instant expiration = Instant.now().plus(Duration.ofMinutes(1)); final MessageWithLockToken message = mock(MessageWithLockToken.class); final MessageWithLockToken message2 = mock(MessageWithLockToken.class); when(message.getLockToken()).thenReturn(lockToken1); when(message2.getLockToken()).thenReturn(lockToken2); when(messageSerializer.deserialize(message, ServiceBusReceivedMessage.class)).thenReturn(receivedMessage); when(messageSerializer.deserialize(message2, ServiceBusReceivedMessage.class)).thenReturn(receivedMessage2); when(receivedMessage.getLockToken()).thenReturn(lockToken1.toString()); when(receivedMessage.getLockedUntil()).thenReturn(expiration); when(receivedMessage2.getLockToken()).thenReturn(lockToken2.toString()); when(receivedMessage2.getLockedUntil()).thenReturn(expiration); when(connection.getManagementNode(ENTITY_PATH, ENTITY_TYPE)) .thenReturn(Mono.just(managementNode)); when(managementNode.updateDisposition(eq(lockToken1.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull())) .thenReturn(Mono.empty()); when(managementNode.updateDisposition(eq(lockToken2.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull())) .thenReturn(Mono.empty()); StepVerifier.create(consumer2.receive().take(2)) .then(() -> { messageSink.next(message); messageSink.next(message2); }) .expectNext(receivedMessage) .expectNext(receivedMessage2) .thenAwait(Duration.ofSeconds(5)) .verifyComplete(); logger.info("Verifying assertions."); verify(managementNode).updateDisposition(eq(lockToken1.toString()), eq(DispositionStatus.COMPLETED), isNull(), isNull(), isNull()); }