|
|
|
@ -31,9 +31,12 @@ import org.mockito.InOrder;
|
|
|
|
|
import org.mockito.Mock;
|
|
|
|
|
import org.mockito.MockitoAnnotations;
|
|
|
|
|
|
|
|
|
|
import org.springframework.beans.factory.ObjectProvider;
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat;
|
|
|
|
|
import static org.mockito.BDDMockito.given;
|
|
|
|
|
import static org.mockito.Mockito.inOrder;
|
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
|
import static org.mockito.Mockito.verify;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -74,8 +77,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void configureWhenCompositeShouldApplyCustomizer() {
|
|
|
|
|
this.customizers.add(this.mockCustomizer);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
CompositeMeterRegistry composite = new CompositeMeterRegistry();
|
|
|
|
|
configurer.configure(composite);
|
|
|
|
|
verify(this.mockCustomizer).customize(composite);
|
|
|
|
@ -84,8 +89,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void configureShouldApplyCustomizer() {
|
|
|
|
|
this.customizers.add(this.mockCustomizer);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
verify(this.mockCustomizer).customize(this.mockRegistry);
|
|
|
|
|
}
|
|
|
|
@ -93,8 +100,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void configureShouldApplyFilter() {
|
|
|
|
|
this.filters.add(this.mockFilter);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
verify(this.mockConfig).meterFilter(this.mockFilter);
|
|
|
|
|
}
|
|
|
|
@ -102,8 +111,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
@Test
|
|
|
|
|
public void configureShouldApplyBinder() {
|
|
|
|
|
this.binders.add(this.mockBinder);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
verify(this.mockBinder).bindTo(this.mockRegistry);
|
|
|
|
|
}
|
|
|
|
@ -113,8 +124,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
this.customizers.add(this.mockCustomizer);
|
|
|
|
|
this.filters.add(this.mockFilter);
|
|
|
|
|
this.binders.add(this.mockBinder);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
InOrder ordered = inOrder(this.mockBinder, this.mockConfig, this.mockCustomizer);
|
|
|
|
|
ordered.verify(this.mockCustomizer).customize(this.mockRegistry);
|
|
|
|
@ -124,8 +137,10 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void configureWhenAddToGlobalRegistryShouldAddToGlobalRegistry() {
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, true);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
true);
|
|
|
|
|
try {
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
assertThat(Metrics.globalRegistry.getRegistries())
|
|
|
|
@ -138,11 +153,20 @@ public class MeterRegistryConfigurerTests {
|
|
|
|
|
|
|
|
|
|
@Test
|
|
|
|
|
public void configureWhenNotAddToGlobalRegistryShouldAddToGlobalRegistry() {
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(this.binders,
|
|
|
|
|
this.filters, this.customizers, false);
|
|
|
|
|
MeterRegistryConfigurer configurer = new MeterRegistryConfigurer(
|
|
|
|
|
createObjectProvider(this.customizers),
|
|
|
|
|
createObjectProvider(this.filters), createObjectProvider(this.binders),
|
|
|
|
|
false);
|
|
|
|
|
configurer.configure(this.mockRegistry);
|
|
|
|
|
assertThat(Metrics.globalRegistry.getRegistries())
|
|
|
|
|
.doesNotContain(this.mockRegistry);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unchecked")
|
|
|
|
|
private <T> ObjectProvider<T> createObjectProvider(List<T> objects) {
|
|
|
|
|
ObjectProvider<T> objectProvider = mock(ObjectProvider.class);
|
|
|
|
|
given(objectProvider.orderedStream()).willReturn(objects.stream());
|
|
|
|
|
return objectProvider;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|