Skip to content

Commit aca3095

Browse files
committed
Polish "Align prefix match in BufferCounterService with DefaultCounterService"
See gh-10278
1 parent dcb81a3 commit aca3095

File tree

2 files changed

+21
-27
lines changed

2 files changed

+21
-27
lines changed

spring-boot-actuator/src/main/java/org/springframework/boot/actuate/metrics/buffer/BufferCounterService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2016 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2017 the original author or authors.
2+
* Copyright 2012-2017 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -21,12 +21,10 @@
2121
import org.springframework.boot.actuate.metrics.CounterService;
2222
import org.springframework.boot.actuate.metrics.Metric;
2323

24-
import static org.junit.Assert.assertEquals;
25-
import static org.junit.Assert.assertNotNull;
26-
import static org.junit.Assert.assertNull;
24+
import static org.assertj.core.api.Assertions.assertThat;
2725

2826
/**
29-
* Standard tests for {@link BufferCounterService}.
27+
* Tests for {@link BufferCounterService}.
3028
*
3129
* @author Venil Noronha
3230
*/
@@ -36,56 +34,52 @@ public class BufferCounterServiceTests {
3634

3735
private CounterService service = new BufferCounterService(this.counters);
3836

39-
private BufferMetricReader reader = new BufferMetricReader(this.counters, new GaugeBuffers());
37+
private BufferMetricReader reader = new BufferMetricReader(this.counters,
38+
new GaugeBuffers());
4039

4140
@Test
4241
public void matchExtendedPrefix() {
4342
this.service.increment("foo");
44-
Metric<?> fooMetric = this.reader.findOne("foo");
43+
assertThat(this.reader.findOne("foo")).isNull();
4544
Metric<?> counterFooMetric = this.reader.findOne("counter.foo");
46-
assertNull(fooMetric);
47-
assertNotNull(counterFooMetric);
48-
assertEquals(1L, counterFooMetric.getValue());
45+
assertThat(counterFooMetric).isNotNull();
46+
assertThat(counterFooMetric.getValue()).isEqualTo(1L);
4947
}
5048

5149
@Test
5250
public void matchCounterPrefix() {
5351
this.service.increment("counterfoo");
54-
Metric<?> counterfooMetric = this.reader.findOne("counterfoo");
52+
assertThat(this.reader.findOne("counterfoo")).isNull();
5553
Metric<?> counterCounterfooMetric = this.reader.findOne("counter.counterfoo");
56-
assertNull(counterfooMetric);
57-
assertNotNull(counterCounterfooMetric);
58-
assertEquals(1L, counterCounterfooMetric.getValue());
54+
assertThat(counterCounterfooMetric).isNotNull();
55+
assertThat(counterCounterfooMetric.getValue()).isEqualTo(1L);
5956
}
6057

6158
@Test
6259
public void matchCounterDotPrefix() {
6360
this.service.increment("counter.foo");
61+
assertThat(this.reader.findOne("counter.counter.foo")).isNull();
6462
Metric<?> counterFooMetric = this.reader.findOne("counter.foo");
65-
Metric<?> counterCounterFooMetric = this.reader.findOne("counter.counter.foo");
66-
assertNull(counterCounterFooMetric);
67-
assertNotNull(counterFooMetric);
68-
assertEquals(1L, counterFooMetric.getValue());
63+
assertThat(counterFooMetric).isNotNull();
64+
assertThat(counterFooMetric.getValue()).isEqualTo(1L);
6965
}
7066

7167
@Test
7268
public void matchMeterPrefix() {
7369
this.service.increment("meterfoo");
74-
Metric<?> meterfooMetric = this.reader.findOne("meterfoo");
70+
assertThat(this.reader.findOne("meterfoo")).isNull();
7571
Metric<?> counterMeterfooMetric = this.reader.findOne("counter.meterfoo");
76-
assertNull(meterfooMetric);
77-
assertNotNull(counterMeterfooMetric);
78-
assertEquals(1L, counterMeterfooMetric.getValue());
72+
assertThat(counterMeterfooMetric).isNotNull();
73+
assertThat(counterMeterfooMetric.getValue()).isEqualTo(1L);
7974
}
8075

8176
@Test
8277
public void matchMeterDotPrefix() {
8378
this.service.increment("meter.foo");
79+
assertThat(this.reader.findOne("counter.meter.foo")).isNull();
8480
Metric<?> meterFooMetric = this.reader.findOne("meter.foo");
85-
Metric<?> counterMeterFooMetric = this.reader.findOne("counter.meter.foo");
86-
assertNull(counterMeterFooMetric);
87-
assertNotNull(meterFooMetric);
88-
assertEquals(1L, meterFooMetric.getValue());
81+
assertThat(meterFooMetric).isNotNull();
82+
assertThat(meterFooMetric.getValue()).isEqualTo(1L);
8983
}
9084

9185
}

0 commit comments

Comments
 (0)