28
28
import java .util .function .Predicate ;
29
29
30
30
import static java .util .concurrent .CompletableFuture .supplyAsync ;
31
- import static org .assertj .core .api .Assertions .assertThat ;
32
- import static org .assertj .core .api .Assertions .assertThatThrownBy ;
31
+ import static org .assertj .core .api .Assertions .*;
33
32
34
33
/**
35
34
* Unit tests for the {@link CountedAspect} aspect.
36
35
*
37
36
* @author Ali Dehghani
38
37
* @author Tommy Ludwig
39
38
* @author Johnny Lim
39
+ * @author Yanming Zhou
40
40
*/
41
41
class CountedAspectTest {
42
42
@@ -327,6 +327,24 @@ void countClassWithFailure() {
327
327
.count ()).isEqualTo (1 );
328
328
}
329
329
330
+ @ Test
331
+ void ignoreClassLevelAnnotationIfMethodLevelPresent () {
332
+ CountedClassService service = getAdvisedService (new CountedClassService ());
333
+
334
+ service .greet ();
335
+
336
+ assertThatExceptionOfType (MeterNotFoundException .class )
337
+ .isThrownBy (() -> meterRegistry .get ("class.counted" ).counter ());
338
+
339
+ assertThat (meterRegistry .get ("method.counted" )
340
+ .tag ("class" , "io.micrometer.core.aop.CountedAspectTest$CountedClassService" )
341
+ .tag ("method" , "greet" )
342
+ .tag ("result" , "success" )
343
+ .tag ("exception" , "none" )
344
+ .counter ()
345
+ .count ()).isEqualTo (1 );
346
+ }
347
+
330
348
@ Counted ("class.counted" )
331
349
static class CountedClassService {
332
350
@@ -338,6 +356,11 @@ void fail() {
338
356
throw new RuntimeException ("Oops" );
339
357
}
340
358
359
+ @ Counted ("method.counted" )
360
+ String greet () {
361
+ return "hello" ;
362
+ }
363
+
341
364
}
342
365
343
366
}
0 commit comments