Skip to content

Commit

Permalink
SynchronousReceiverTest: scoping mock instances to test methods (#39038)
Browse files Browse the repository at this point in the history
  • Loading branch information
anuchandy authored Mar 1, 2024
1 parent 7f736fb commit 94e2276
Showing 1 changed file with 6 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import reactor.core.publisher.Mono;
Expand All @@ -39,10 +37,6 @@ public final class SynchronousReceiverTest {
private static final ClientLogger LOGGER = new ClientLogger(SynchronousReceiverTest.class);
private static final ServiceBusReceiverInstrumentation NO_INSTRUMENTATION = new ServiceBusReceiverInstrumentation(null, null,
NAMESPACE, ENTITY_PATH, null, ReceiverKind.SYNC_RECEIVER);
@Mock
private ServiceBusReceiverAsyncClient asyncClient;
@Captor
private ArgumentCaptor<ServiceBusReceivedMessage> messageCaptor;
private AutoCloseable mocksCloseable;

@BeforeEach
Expand All @@ -63,6 +57,7 @@ void teardown() throws Exception {
public void shouldErrorIterableStreamIfDisposed() {
final int maxMessages = 1;
final Duration maxWaitTime = Duration.ofMillis(500);
final ServiceBusReceiverAsyncClient asyncClient = mock(ServiceBusReceiverAsyncClient.class);
final ReceiverOptions receiverOptions = ReceiverOptions.createNonSessionOptions(PEEK_LOCK, 0, Duration.ZERO, false);

when((asyncClient.getReceiverOptions())).thenReturn(receiverOptions);
Expand All @@ -83,6 +78,7 @@ public void shouldErrorIterableStreamIfDisposed() {
public void shouldSubscribeToUpstreamOnlyOnce() {
final int maxMessages = 1;
final Duration maxWaitTime = Duration.ofMillis(250);
final ServiceBusReceiverAsyncClient asyncClient = mock(ServiceBusReceiverAsyncClient.class);
final ReceiverOptions receiverOptions = ReceiverOptions.createNonSessionOptions(PEEK_LOCK, 0, Duration.ZERO, false);
final TestPublisher<ServiceBusReceivedMessage> upstream = TestPublisher.create();

Expand All @@ -105,8 +101,10 @@ public void shouldInvokeReleaserWhenPrefetchDisabled() {
final int prefetch = 0; // prefetch is disabled
final int maxMessages = 5;
final Duration maxWaitTime = Duration.ofMillis(250);
final ServiceBusReceiverAsyncClient asyncClient = mock(ServiceBusReceiverAsyncClient.class);
final ServiceBusReceivedMessage message0 = mock(ServiceBusReceivedMessage.class);
final ServiceBusReceivedMessage message1 = mock(ServiceBusReceivedMessage.class);
final ArgumentCaptor<ServiceBusReceivedMessage> messageCaptor = ArgumentCaptor.forClass(ServiceBusReceivedMessage.class);
final ReceiverOptions receiverOptions = ReceiverOptions.createNonSessionOptions(PEEK_LOCK, prefetch, Duration.ZERO, false);
final Sinks.Many<ServiceBusReceivedMessage> upstream = Sinks.many().multicast().onBackpressureBuffer();

Expand Down Expand Up @@ -136,6 +134,7 @@ public void shouldNotInvokeReleaserWhenPrefetchEnabled() {
final int prefetch = 1; // prefetch is enabled
final int maxMessages = 5;
final Duration maxWaitTime = Duration.ofMillis(250);
final ServiceBusReceiverAsyncClient asyncClient = mock(ServiceBusReceiverAsyncClient.class);
final ServiceBusReceivedMessage message0 = mock(ServiceBusReceivedMessage.class);
final ServiceBusReceivedMessage message1 = mock(ServiceBusReceivedMessage.class);
final ReceiverOptions receiverOptions = ReceiverOptions.createNonSessionOptions(PEEK_LOCK, prefetch, Duration.ZERO, false);
Expand Down Expand Up @@ -164,6 +163,7 @@ public void shouldCancelUpstreamOnDispose() {
final int prefetch = 0;
final int maxMessages = 2;
final Duration maxWaitTime = Duration.ofMillis(250);
final ServiceBusReceiverAsyncClient asyncClient = mock(ServiceBusReceiverAsyncClient.class);
final ServiceBusReceivedMessage message0 = mock(ServiceBusReceivedMessage.class);
final ServiceBusReceivedMessage message1 = mock(ServiceBusReceivedMessage.class);
final ReceiverOptions receiverOptions = ReceiverOptions.createNonSessionOptions(PEEK_LOCK, prefetch, Duration.ZERO, false);
Expand Down

0 comments on commit 94e2276

Please sign in to comment.