From f530d87906b42f4e7d48e0218d7be2cf3dfa3324 Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Thu, 19 Sep 2024 15:24:27 -0700 Subject: [PATCH 1/2] Improve assertions in TimedAspectTest --- .../test/java/io/micrometer/core/aop/TimedAspectTest.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java index 668095f63f..6be4e18ddb 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java @@ -201,7 +201,7 @@ void timeMethodWhenCompletedExceptionally() { assertThat(registry.getMeters()).isEmpty(); guardedResult.complete(new IllegalStateException("simulated")); - catchThrowableOfType(completableFuture::join, CompletionException.class); + assertThatThrownBy(completableFuture::join).isInstanceOf(CompletionException.class); assertThat(registry.get("call") .tag("class", getClass().getName() + "$AsyncTimedService") @@ -261,8 +261,8 @@ void timeMethodWithLongTaskTimerWhenCompletedExceptionally() { .longTaskTimer() .activeTasks()).isEqualTo(1); - guardedResult.complete(new NullPointerException()); - catchThrowableOfType(completableFuture::join, CompletionException.class); + guardedResult.complete(new IllegalStateException("simulated")); + assertThatThrownBy(completableFuture::join).isInstanceOf(CompletionException.class); assertThat(registry.get("longCall") .tag("class", getClass().getName() + "$AsyncTimedService") @@ -336,7 +336,7 @@ void timeClassWithSkipPredicate() { service.call(); - assertThat(registry.find("call").timer()).isNull(); + assertThat(registry.getMeters()).isEmpty(); } @Test From 9d1145896ba447c1f48356785d173d77d0bbc8ec Mon Sep 17 00:00:00 2001 From: Jonatan Ivanov Date: Thu, 19 Sep 2024 15:57:03 -0700 Subject: [PATCH 2/2] Improve assertions in TimedAspectTest --- .../test/java/io/micrometer/core/aop/TimedAspectTest.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java index 62d8e679f3..98a725b6e8 100644 --- a/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java +++ b/micrometer-core/src/test/java/io/micrometer/core/aop/TimedAspectTest.java @@ -25,7 +25,6 @@ import io.micrometer.core.instrument.Timer; import io.micrometer.core.instrument.distribution.DistributionStatisticConfig; import io.micrometer.core.instrument.distribution.pause.PauseDetector; -import io.micrometer.core.instrument.search.MeterNotFoundException; import io.micrometer.core.instrument.simple.SimpleMeterRegistry; import org.aspectj.lang.ProceedingJoinPoint; import org.junit.jupiter.api.Nested; @@ -40,7 +39,8 @@ import java.util.function.Predicate; import static java.util.concurrent.CompletableFuture.supplyAsync; -import static org.assertj.core.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class TimedAspectTest { @@ -389,7 +389,7 @@ void ignoreClassLevelAnnotationIfMethodLevelPresent() { service.annotatedOnMethod(); - assertThatExceptionOfType(MeterNotFoundException.class).isThrownBy(() -> registry.get("call").timer()); + assertThat(registry.getMeters()).hasSize(1); assertThat(registry.get("annotatedOnMethod") .tag("class", "io.micrometer.core.aop.TimedAspectTest$TimedClass") .tag("method", "annotatedOnMethod")