diff --git a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/BulkheadExportsTest.java b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/BulkheadExportsTest.java index 9b82b00c8b..1081343408 100644 --- a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/BulkheadExportsTest.java +++ b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/BulkheadExportsTest.java @@ -18,10 +18,6 @@ */ package io.github.resilience4j.prometheus; -import org.junit.Test; - -import java.util.function.Supplier; - import io.github.resilience4j.bulkhead.Bulkhead; import io.github.resilience4j.bulkhead.BulkheadConfig; import io.github.resilience4j.bulkhead.BulkheadRegistry; @@ -31,6 +27,9 @@ import io.vavr.collection.HashMap; import io.vavr.collection.HashSet; import io.vavr.collection.Map; +import org.junit.Test; + +import java.util.function.Supplier; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; @@ -67,13 +66,13 @@ public void testExportsCircuitBreakerStates() { public void testConstructors() { final BulkheadRegistry registry = new InMemoryBulkheadRegistry(BulkheadConfig.ofDefaults()); - BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo"))); - BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry); - BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo"))); + assertThat(BulkheadExports.ofIterable("boo_bulkheads", singleton(Bulkhead.ofDefaults("foo")))).isNotNull(); + assertThat(BulkheadExports.ofBulkheadRegistry("boo_bulkheads", registry)).isNotNull(); + assertThat(BulkheadExports.ofSupplier("boo_bulkheads", () -> singleton(Bulkhead.ofDefaults("foo")))).isNotNull(); - BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo"))); - BulkheadExports.ofBulkheadRegistry(registry); - BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo"))); + assertThat(BulkheadExports.ofIterable(singleton(Bulkhead.ofDefaults("foo")))).isNotNull(); + assertThat(BulkheadExports.ofBulkheadRegistry(registry)).isNotNull(); + assertThat(BulkheadExports.ofSupplier(() -> singleton(Bulkhead.ofDefaults("foo")))).isNotNull(); } @Test(expected = NullPointerException.class) diff --git a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/CircuitBreakerExportsTest.java b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/CircuitBreakerExportsTest.java index 027fbaa918..a1c954fee1 100644 --- a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/CircuitBreakerExportsTest.java +++ b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/CircuitBreakerExportsTest.java @@ -18,10 +18,6 @@ */ package io.github.resilience4j.prometheus; -import org.junit.Test; - -import java.util.function.Supplier; - import io.github.resilience4j.circuitbreaker.CircuitBreaker; import io.github.resilience4j.circuitbreaker.CircuitBreakerOpenException; import io.github.resilience4j.circuitbreaker.CircuitBreakerRegistry; @@ -31,6 +27,9 @@ import io.vavr.collection.HashMap; import io.vavr.collection.HashSet; import io.vavr.collection.Map; +import org.junit.Test; + +import java.util.function.Supplier; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; @@ -176,13 +175,13 @@ public void testExportsCircuitBreakerMetrics() { public void testConstructors() { final CircuitBreakerRegistry registry = new InMemoryCircuitBreakerRegistry(); - CircuitBreakerExports.ofIterable("boo_breakers", singleton(CircuitBreaker.ofDefaults("foo"))); - CircuitBreakerExports.ofCircuitBreakerRegistry("boo_breakers", registry); - CircuitBreakerExports.ofSupplier("boo_breakers", () -> singleton(CircuitBreaker.ofDefaults("foo"))); + assertThat(CircuitBreakerExports.ofIterable("boo_breakers", singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull(); + assertThat(CircuitBreakerExports.ofCircuitBreakerRegistry("boo_breakers", registry)).isNotNull(); + assertThat(CircuitBreakerExports.ofSupplier("boo_breakers", () -> singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull(); - CircuitBreakerExports.ofIterable(singleton(CircuitBreaker.ofDefaults("foo"))); - CircuitBreakerExports.ofCircuitBreakerRegistry(registry); - CircuitBreakerExports.ofSupplier(() -> singleton(CircuitBreaker.ofDefaults("foo"))); + assertThat(CircuitBreakerExports.ofIterable(singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull(); + assertThat(CircuitBreakerExports.ofCircuitBreakerRegistry(registry)).isNotNull(); + assertThat(CircuitBreakerExports.ofSupplier(() -> singleton(CircuitBreaker.ofDefaults("foo")))).isNotNull(); } @Test(expected = NullPointerException.class) diff --git a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/RateLimiterExportsTest.java b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/RateLimiterExportsTest.java index b8e471cd34..7d8530f047 100644 --- a/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/RateLimiterExportsTest.java +++ b/resilience4j-prometheus/src/test/java/io/github/resilience4j/prometheus/RateLimiterExportsTest.java @@ -18,10 +18,6 @@ */ package io.github.resilience4j.prometheus; -import org.junit.Test; - -import java.util.function.Supplier; - import io.github.resilience4j.ratelimiter.RateLimiter; import io.github.resilience4j.ratelimiter.RateLimiterConfig; import io.github.resilience4j.ratelimiter.RateLimiterRegistry; @@ -31,6 +27,9 @@ import io.vavr.collection.HashMap; import io.vavr.collection.HashSet; import io.vavr.collection.Map; +import org.junit.Test; + +import java.util.function.Supplier; import static java.util.Collections.singleton; import static java.util.Collections.singletonList; @@ -73,13 +72,13 @@ public void testExportsRateLimiterMetrics() { public void testConstructors() { final RateLimiterRegistry registry = new InMemoryRateLimiterRegistry(RateLimiterConfig.ofDefaults()); - RateLimiterExports.ofIterable("boo_limiters", singleton(RateLimiter.ofDefaults("foo"))); - RateLimiterExports.ofRateLimiterRegistry("boo_limiters", registry); - RateLimiterExports.ofSupplier("boo_limiters", () -> singleton(RateLimiter.ofDefaults("foo"))); + assertThat(RateLimiterExports.ofIterable("boo_limiters", singleton(RateLimiter.ofDefaults("foo")))).isNotNull(); + assertThat(RateLimiterExports.ofRateLimiterRegistry("boo_limiters", registry)).isNotNull(); + assertThat(RateLimiterExports.ofSupplier("boo_limiters", () -> singleton(RateLimiter.ofDefaults("foo")))).isNotNull(); - RateLimiterExports.ofIterable(singleton(RateLimiter.ofDefaults("foo"))); - RateLimiterExports.ofRateLimiterRegistry(registry); - RateLimiterExports.ofSupplier(() -> singleton(RateLimiter.ofDefaults("foo"))); + assertThat(RateLimiterExports.ofIterable(singleton(RateLimiter.ofDefaults("foo")))).isNotNull(); + assertThat(RateLimiterExports.ofRateLimiterRegistry(registry)).isNotNull(); + assertThat(RateLimiterExports.ofSupplier(() -> singleton(RateLimiter.ofDefaults("foo")))).isNotNull(); } @Test(expected = NullPointerException.class) diff --git a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/AsyncRetryTest.java b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/AsyncRetryTest.java index 865f2374bf..2bf95005af 100644 --- a/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/AsyncRetryTest.java +++ b/resilience4j-retry/src/test/java/io/github/resilience4j/retry/internal/AsyncRetryTest.java @@ -90,8 +90,6 @@ public void shouldNotRetryWithThatResult(){ // Then the helloWorldService should be invoked 1 time BDDMockito.then(helloWorldService).should(Mockito.times(1)).returnHelloWorld(); Assertions.assertThat(result).isEqualTo("Hello world"); - // for code quality scan , it does not not recognize assertJ do not why - Assert.assertEquals(result, "Hello world"); } @Test diff --git a/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerCompletableObserver.java b/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerCompletableObserver.java index e5b02db46a..e59bbcf5cd 100644 --- a/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerCompletableObserver.java +++ b/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerCompletableObserver.java @@ -8,7 +8,7 @@ * A RxJava {@link CompletableObserver} to protect another observer by a CircuitBreaker. */ final class CircuitBreakerCompletableObserver extends DisposableCircuitBreaker implements CompletableObserver { - private final CompletableObserver childObserver; + private final transient CompletableObserver childObserver; CircuitBreakerCompletableObserver(CircuitBreaker circuitBreaker, CompletableObserver childObserver) { super(circuitBreaker); diff --git a/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerSubscriber.java b/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerSubscriber.java index 1fc23531ee..2bb4642a09 100644 --- a/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerSubscriber.java +++ b/resilience4j-rxjava2/src/main/java/io/github/resilience4j/circuitbreaker/operator/CircuitBreakerSubscriber.java @@ -24,7 +24,7 @@ final class CircuitBreakerSubscriber extends AtomicReference im private final transient Subscriber childSubscriber; private final AtomicReference permitted = new AtomicReference<>(Permit.PENDING); @Nullable - private StopWatch stopWatch; + private transient StopWatch stopWatch; CircuitBreakerSubscriber(CircuitBreaker circuitBreaker, Subscriber childSubscriber) { this.circuitBreaker = requireNonNull(circuitBreaker); @@ -100,13 +100,13 @@ private boolean notCancelled() { private void markFailure(Throwable e) { if (wasCallPermitted()) { - circuitBreaker.onError(stopWatch.stop().toNanos(), e); + circuitBreaker.onError(stopWatch != null ? stopWatch.stop().toNanos() : 0, e); } } private void markSuccess() { if (wasCallPermitted()) { - circuitBreaker.onSuccess(stopWatch.stop().toNanos()); + circuitBreaker.onSuccess(stopWatch != null ? stopWatch.stop().toNanos() : 0); } } diff --git a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java index 15a038cb42..bd151ac34f 100644 --- a/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java +++ b/resilience4j-spring-boot2/src/test/java/io/github/resilience4j/circuitbreaker/CircuitBreakerAutoConfigurationTest.java @@ -15,14 +15,13 @@ */ package io.github.resilience4j.circuitbreaker; -import static org.assertj.core.api.Assertions.assertThat; - -import java.io.IOException; -import java.time.Duration; -import java.util.Map; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.ExecutionException; - +import io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties; +import io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect; +import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEndpointResponse; +import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEventsEndpointResponse; +import io.github.resilience4j.service.test.DummyService; +import io.github.resilience4j.service.test.ReactiveDummyService; +import io.github.resilience4j.service.test.TestApplication; import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; @@ -32,13 +31,13 @@ import org.springframework.test.annotation.DirtiesContext; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -import io.github.resilience4j.circuitbreaker.autoconfigure.CircuitBreakerProperties; -import io.github.resilience4j.circuitbreaker.configure.CircuitBreakerAspect; -import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEndpointResponse; -import io.github.resilience4j.circuitbreaker.monitoring.endpoint.CircuitBreakerEventsEndpointResponse; -import io.github.resilience4j.service.test.DummyService; -import io.github.resilience4j.service.test.ReactiveDummyService; -import io.github.resilience4j.service.test.TestApplication; +import java.io.IOException; +import java.time.Duration; +import java.util.Map; +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutionException; + +import static org.assertj.core.api.Assertions.assertThat; @RunWith(SpringJUnit4ClassRunner.class) @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT, @@ -140,7 +139,7 @@ public void testCircuitBreakerAutoConfigurationAsync() throws IOException, Execu } // The invocation is recorded by the CircuitBreaker as a success. final CompletableFuture stringCompletionStage = dummyService.doSomethingAsync(false); - assertThat(stringCompletionStage.get().equals("Test result")); + assertThat(stringCompletionStage.get()).isEqualTo("Test result"); CircuitBreaker circuitBreaker = circuitBreakerRegistry.circuitBreaker(DummyService.BACKEND); assertThat(circuitBreaker).isNotNull();