Skip to content

Commit 94b2092

Browse files
committed
Add base test for StepRegistryPropertiesConfigAdapter
1 parent a70aafd commit 94b2092

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Copyright 2012-2018 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.actuate.autoconfigure.metrics.export.properties;
18+
19+
import java.time.Duration;
20+
21+
import org.junit.Test;
22+
23+
import static org.assertj.core.api.Assertions.assertThat;
24+
25+
/**
26+
* Base test for {@link StepRegistryPropertiesConfigAdapter} implementations.
27+
*
28+
* @author Stephane Nicoll
29+
*/
30+
public abstract class StepRegistryPropertiesConfigAdapterTests<P extends StepRegistryProperties, A extends StepRegistryPropertiesConfigAdapter<P>> {
31+
32+
protected abstract P createProperties();
33+
34+
protected abstract A createConfigAdapter(P properties);
35+
36+
@Test
37+
public void whenPropertiesStepIsSetAdapterStepReturnsIt() {
38+
P properties = createProperties();
39+
properties.setStep(Duration.ofSeconds(42));
40+
assertThat(createConfigAdapter(properties).step())
41+
.isEqualTo(Duration.ofSeconds(42));
42+
}
43+
44+
@Test
45+
public void whenPropertiesEnabledIsSetAdapterEnabledReturnsIt() {
46+
P properties = createProperties();
47+
properties.setEnabled(false);
48+
assertThat(createConfigAdapter(properties).enabled()).isFalse();
49+
}
50+
51+
@Test
52+
public void whenPropertiesConnectTimeoutIsSetAdapterConnectTimeoutReturnsIt() {
53+
P properties = createProperties();
54+
properties.setConnectTimeout(Duration.ofMinutes(42));
55+
assertThat(createConfigAdapter(properties).connectTimeout())
56+
.isEqualTo(Duration.ofMinutes(42));
57+
}
58+
59+
@Test
60+
public void whenPropertiesReadTimeoutIsSetAdapterReadTimeoutReturnsIt() {
61+
P properties = createProperties();
62+
properties.setReadTimeout(Duration.ofMillis(42));
63+
assertThat(createConfigAdapter(properties).readTimeout())
64+
.isEqualTo(Duration.ofMillis(42));
65+
}
66+
67+
@Test
68+
public void whenPropertiesNumThreadsIsSetAdapterNumThreadsReturnsIt() {
69+
P properties = createProperties();
70+
properties.setNumThreads(42);
71+
assertThat(createConfigAdapter(properties).numThreads()).isEqualTo(42);
72+
}
73+
74+
@Test
75+
public void whenPropertiesBatchSizeIsSetAdapterBatchSizeReturnsIt() {
76+
P properties = createProperties();
77+
properties.setBatchSize(10042);
78+
assertThat(createConfigAdapter(properties).batchSize()).isEqualTo(10042);
79+
}
80+
81+
}

0 commit comments

Comments
 (0)