Skip to content

Commit

Permalink
Remove @mock annotations to future proof test
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanjbaxter committed Oct 16, 2024
1 parent 9d48c8c commit d2f8834
Showing 1 changed file with 15 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import io.github.resilience4j.timelimiter.TimeLimiterConfig;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.After;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;

import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -61,6 +61,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.internal.verification.VerificationModeFactory.times;
import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT;
Expand All @@ -74,16 +75,12 @@
@DirtiesContext
public class Resilience4JBulkheadIntegrationTest {

@Mock
static EventConsumer<CircuitBreakerOnErrorEvent> slowErrorConsumer;

@Mock
static EventConsumer<CircuitBreakerOnSuccessEvent> slowSuccessConsumer;

@Mock
static EventConsumer<CircuitBreakerOnErrorEvent> normalErrorConsumer;

@Mock
static EventConsumer<CircuitBreakerOnSuccessEvent> normalSuccessConsumer;

@Autowired
Expand All @@ -92,6 +89,11 @@ public class Resilience4JBulkheadIntegrationTest {
@Autowired
private TestRestTemplate rest;

@After
public void reset() {
Mockito.clearInvocations(slowErrorConsumer, slowSuccessConsumer, normalErrorConsumer, normalSuccessConsumer);
}

@Test
public void testSlow() {
assertThat(service.slow()).isEqualTo("fallback");
Expand Down Expand Up @@ -201,6 +203,10 @@ public String slowThreadPoolBulkhead() throws InterruptedException {

@Bean
public Customizer<Resilience4JCircuitBreakerFactory> slowCustomizer() {
slowErrorConsumer = mock(EventConsumer.class);
slowSuccessConsumer = mock(EventConsumer.class);
normalErrorConsumer = mock(EventConsumer.class);
normalSuccessConsumer = mock(EventConsumer.class);
doAnswer(invocation -> {
CircuitBreakerOnErrorEvent event = invocation.getArgument(0, CircuitBreakerOnErrorEvent.class);
LOG.info(event.getCircuitBreakerName() + " error: " + event.getEventType() + " duration: "
Expand Down Expand Up @@ -242,8 +248,8 @@ public Customizer<Resilience4JCircuitBreakerFactory> slowCustomizer() {
};
}

static EventConsumer<BulkheadOnCallRejectedEvent> slowRejectedConsumer = Mockito.mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallFinishedEvent> slowFinishedConsumer = Mockito.mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallRejectedEvent> slowRejectedConsumer = mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallFinishedEvent> slowFinishedConsumer = mock(EventConsumer.class);

@Bean
public Customizer<Resilience4jBulkheadProvider> slowBulkheadProviderCustomizer() {
Expand All @@ -267,10 +273,8 @@ public Customizer<Resilience4jBulkheadProvider> slowBulkheadProviderCustomizer()
};
}

static EventConsumer<BulkheadOnCallRejectedEvent> slowThreadPoolRejectedConsumer = Mockito
.mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallFinishedEvent> slowThreadPoolFinishedConsumer = Mockito
.mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallRejectedEvent> slowThreadPoolRejectedConsumer = mock(EventConsumer.class);
static EventConsumer<BulkheadOnCallFinishedEvent> slowThreadPoolFinishedConsumer = mock(EventConsumer.class);

@Bean
Customizer<Resilience4jBulkheadProvider> slowBulkheadThreadPoolProviderCustomizer() {
Expand Down

0 comments on commit d2f8834

Please sign in to comment.