Code review comment: I agree, it’s easier to read the lambda form and less lines. But the reason for choosing the anonymous form is – the function needs to use a counter which has to be outside the local scope of the function. I was trying to avoid declaring that counter as atomic or array with one element.

Code under review:
void shouldRecoverFromRetriableSendLinkError() {
        
        final int sessionsCnt = 1;
        final int[] linksPerSession = new int[] { 2 };
        try (MockEndpoint endpoint = createMockEndpoint(sessionsCnt, linksPerSession)) {
            
            final Supplier<ServiceBusReactorAmqpConnection> connectionSupplier = singleConnectionSupplier(endpoint);
            
            final Answer<Mono<Void>> sendAnswer = new Answer<Mono<Void>>() {
                private int invocationCount = -1;

                @Override
                public Mono<Void> answer(InvocationOnMock invocation) {
                    invocationCount++;
                    switch (invocationCount) {
                        case 0:
                            
                            endpoint.emitCurrentSendLinkError(RETRIABLE_LINK_ERROR);
                            return Mono.error(RETRIABLE_LINK_ERROR);
                        case 1:
                            
                            return Mono.empty();
                        default:
                            throw new RuntimeException("More than two invocations of send-answer is not expected.");
                    }
                }
            };

            
            when(endpoint.getAmqpSendLink(0, 0).send(anyList())).thenAnswer(sendAnswer);
            when(endpoint.getAmqpSendLink(0, 1).send(anyList())).thenAnswer(sendAnswer);

            final int messagesCount = 4;
            final List<ServiceBusMessage> messagesToSend = createMessagesToSend(messagesCount);

            final ReactorConnectionCache<ServiceBusReactorAmqpConnection> connectionCache = createConnectionCache(connectionSupplier);
            final ServiceBusSenderAsyncClient sender = createSenderAsyncClient(connectionCache, false);
            try {
                
                
                try (VirtualTimeStepVerifier verifier = new VirtualTimeStepVerifier()) {
                    verifier.create(() -> sender.sendMessages(messagesToSend))
                        .thenAwait(VIRTUAL_TIME_SHIFT)
                        .verifyComplete();
                }

                
                
                verify(endpoint.getAmqpSendLink(0, 0)).send(sendMessagesCaptor0.capture());
                final List<Message> messagesSendInSession0Link0 = sendMessagesCaptor0.getValue();
                Assertions.assertEquals(messagesCount, messagesSendInSession0Link0.size());

                verify(endpoint.getAmqpSendLink(0, 1)).send(sendMessagesCaptor1.capture());
                final List<Message> messagesSendInSession0Link1 = sendMessagesCaptor1.getValue();
                Assertions.assertEquals(messagesCount, messagesSendInSession0Link1.size());
            } finally {
                sender.close();
                connectionCache.dispose();
            }
        }
    }

Line commented on: final Answer<Mono<Void>> sendAnswer = new Answer<Mono<Void>>() {

Revised code:
void shouldRecoverFromRetriableSendLinkError() {
        
        final int sessionsCnt = 1;
        final int[] linksPerSession = new int[] { 2 };
        try (MockEndpoint endpoint = createMockEndpoint(sessionsCnt, linksPerSession)) {
            
            final Supplier<ServiceBusReactorAmqpConnection> connectionSupplier = singleConnectionSupplier(endpoint);
            
            final Answer<Mono<Void>> sendAnswer = new Answer<Mono<Void>>() {
                private int invocationCount = -1;

                @Override
                public Mono<Void> answer(InvocationOnMock invocation) {
                    invocationCount++;
                    switch (invocationCount) {
                        case 0:
                            
                            endpoint.emitCurrentSendLinkError(RETRIABLE_LINK_ERROR);
                            return Mono.error(RETRIABLE_LINK_ERROR);
                        case 1:
                            
                            return Mono.empty();
                        default:
                            throw new RuntimeException("More than two invocations of send-answer is not expected.");
                    }
                }
            };

            
            when(endpoint.getAmqpSendLink(0, 0).send(anyList())).thenAnswer(sendAnswer);
            when(endpoint.getAmqpSendLink(0, 1).send(anyList())).thenAnswer(sendAnswer);

            final int messagesCount = 4;
            final List<ServiceBusMessage> messagesToSend = createMessagesToSend(messagesCount);

            final ReactorConnectionCache<ServiceBusReactorAmqpConnection> connectionCache = createConnectionCache(connectionSupplier);
            final ServiceBusSenderAsyncClient sender = createSenderAsyncClient(connectionCache, false);
            try {
                
                
                try (VirtualTimeStepVerifier verifier = new VirtualTimeStepVerifier()) {
                    verifier.create(() -> sender.sendMessages(messagesToSend))
                        .thenAwait(VIRTUAL_TIME_SHIFT)
                        .verifyComplete();
                }

                
                
                verify(endpoint.getAmqpSendLink(0, 0)).send(sendMessagesCaptor0.capture());
                final List<Message> messagesSendInSession0Link0 = sendMessagesCaptor0.getValue();
                Assertions.assertEquals(messagesCount, messagesSendInSession0Link0.size());

                verify(endpoint.getAmqpSendLink(0, 1)).send(sendMessagesCaptor1.capture());
                final List<Message> messagesSendInSession0Link1 = sendMessagesCaptor1.getValue();
                Assertions.assertEquals(messagesCount, messagesSendInSession0Link1.size());
            } finally {
                sender.close();
                connectionCache.dispose();
            }
        }
    }