Skip to content

Commit 0624bf3

Browse files
mirogaudiAndrey Strukov
andauthored
clean up more tests (#4480)
Co-authored-by: Andrey Strukov <[email protected]>
1 parent 7f9b5f5 commit 0624bf3

File tree

7 files changed

+35
-44
lines changed

7 files changed

+35
-44
lines changed

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiReactiveApplicationTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@
3131

3232
import de.codecentric.boot.admin.server.config.EnableAdminServer;
3333

34-
public class AdminUiReactiveApplicationTest extends AbstractAdminUiApplicationTest {
34+
class AdminUiReactiveApplicationTest extends AbstractAdminUiApplicationTest {
3535

3636
private static ConfigurableApplicationContext instance;
3737

3838
private static Integer port;
3939

4040
@BeforeAll
41-
public static void setUp() {
41+
static void setUp() {
4242
instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
4343
.web(WebApplicationType.REACTIVE)
4444
.run("--server.port=0",
@@ -49,12 +49,12 @@ public static void setUp() {
4949
}
5050

5151
@AfterAll
52-
public static void shutdown() {
52+
static void shutdown() {
5353
instance.close();
5454
}
5555

5656
@BeforeEach
57-
public void setupEach() {
57+
void setupEach() {
5858
super.setUp(port);
5959
}
6060

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/AdminUiServletApplicationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,12 @@
3232

3333
import de.codecentric.boot.admin.server.config.EnableAdminServer;
3434

35-
public class AdminUiServletApplicationTest extends AbstractAdminUiApplicationTest {
35+
class AdminUiServletApplicationTest extends AbstractAdminUiApplicationTest {
3636

3737
private ConfigurableApplicationContext instance;
3838

3939
@BeforeEach
40-
public void setUp() {
40+
void setUp() {
4141
this.instance = new SpringApplicationBuilder().sources(TestAdminApplication.class)
4242
.web(WebApplicationType.SERVLET)
4343
.run("--server.port=0",
@@ -48,7 +48,7 @@ public void setUp() {
4848
}
4949

5050
@AfterEach
51-
public void shutdown() {
51+
void shutdown() {
5252
this.instance.close();
5353
}
5454

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/config/AdminServerUiAutoConfigurationTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,15 +52,15 @@
5252
import static org.mockito.Mockito.verify;
5353

5454
@ExtendWith(MockitoExtension.class)
55-
public class AdminServerUiAutoConfigurationTest implements WithAssertions {
55+
class AdminServerUiAutoConfigurationTest implements WithAssertions {
5656

5757
@Test
5858
void testNormalizeHomepageUrl() {
5959
assertThat(AdminServerUiAutoConfiguration.normalizeHomepageUrl("/test/")).isEqualTo("/test");
6060
}
6161

6262
@Nested
63-
public class ReactiveUiConfigurationTest {
63+
class ReactiveUiConfigurationTest {
6464

6565
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
6666
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.webflux.base-path=test")
@@ -74,7 +74,7 @@ public class ReactiveUiConfigurationTest {
7474
@ParameterizedTest
7575
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump",
7676
"/test/instances/1/actuator/logfile" })
77-
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
77+
void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
7878
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeExcludes)
7979
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE)
8080
.build();
@@ -95,7 +95,7 @@ public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
9595
@ParameterizedTest
9696
@CsvSource({ "/test/about", "/test/applications", "/test/instances", "/test/journal", "/test/wallboard",
9797
"/test/external" })
98-
public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
98+
void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
9999
MockServerHttpRequest serverHttpRequest = MockServerHttpRequest.get(routeIncludes)
100100
.header(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE)
101101
.build();
@@ -116,7 +116,7 @@ public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
116116
}
117117

118118
@Nested
119-
public class ServletUiConfiguration {
119+
class ServletUiConfiguration {
120120

121121
private final WebApplicationContextRunner contextRunner = new WebApplicationContextRunner()
122122
.withPropertyValues("--spring.boot.admin.ui.available-languages=de", "--spring.boot.admin.contextPath=test")
@@ -126,7 +126,7 @@ public class ServletUiConfiguration {
126126
@ParameterizedTest
127127
@CsvSource({ "/test/extensions/myextension", "/test/instances/1/actuator/heapdump",
128128
"/test/instances/1/actuator/logfile" })
129-
public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
129+
void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
130130
MockHttpServletRequest httpServletRequest = spy(new MockHttpServletRequest("GET", routeExcludes));
131131
httpServletRequest.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
132132

@@ -145,7 +145,7 @@ public void contextPathIsRespectedInExcludedRoutes(String routeExcludes) {
145145
@ParameterizedTest
146146
@CsvSource({ "/test/about", "/test/applications", "/test/instances", "/test/journal", "/test/wallboard",
147147
"/test/external" })
148-
public void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
148+
void contextPathIsRespectedInIncludedRoutes(String routeIncludes) {
149149
MockHttpServletRequest httpServletRequest = spy(new MockHttpServletRequest("GET", routeIncludes));
150150
httpServletRequest.addHeader(HttpHeaders.ACCEPT, MediaType.TEXT_HTML_VALUE);
151151

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/extensions/UiExtensionsScannerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,12 @@
2323

2424
import static org.assertj.core.api.Assertions.assertThat;
2525

26-
public class UiExtensionsScannerTest {
26+
class UiExtensionsScannerTest {
2727

2828
private final UiExtensionsScanner scanner = new UiExtensionsScanner(new PathMatchingResourcePatternResolver());
2929

3030
@Test
31-
public void should_find_extensions() throws IOException {
31+
void should_find_extensions() throws IOException {
3232
UiExtensions extensions = this.scanner.scan("classpath:/META-INF/test-extensions/");
3333
assertThat(extensions.getCssExtensions()).contains(new UiExtension("custom/custom.abcdef.css",
3434
"classpath:/META-INF/test-extensions/custom/custom.abcdef.css"));
@@ -38,7 +38,7 @@ public void should_find_extensions() throws IOException {
3838
}
3939

4040
@Test
41-
public void should_not_find_extensions() throws IOException {
41+
void should_not_find_extensions() throws IOException {
4242
UiExtensions extensions = this.scanner.scan("classpath:/META-INF/NO-test-extensions/");
4343
assertThat(extensions.getCssExtensions()).isEmpty();
4444
assertThat(extensions.getJsExtensions()).isEmpty();

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/extensions/UiRoutesScannerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@
2424

2525
import static org.assertj.core.api.Assertions.assertThat;
2626

27-
public class UiRoutesScannerTest {
27+
class UiRoutesScannerTest {
2828

2929
private final UiRoutesScanner scanner = new UiRoutesScanner(new PathMatchingResourcePatternResolver());
3030

3131
@Test
32-
public void should_find_route() throws IOException {
32+
void should_find_route() throws IOException {
3333
List<String> routes = this.scanner.scan("classpath:/META-INF/test-extensions/");
3434
assertThat(routes).containsExactlyInAnyOrder("/custom/**");
3535
}

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/HomepageForwardingMatcherTest.java

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -18,57 +18,48 @@
1818

1919
import java.util.List;
2020

21-
import lombok.Data;
2221
import org.junit.jupiter.api.Test;
2322
import org.springframework.http.MediaType;
2423

2524
import static java.util.Collections.singletonList;
2625
import static org.assertj.core.api.Assertions.assertThat;
2726

28-
public class HomepageForwardingMatcherTest {
27+
class HomepageForwardingMatcherTest {
2928

3029
private final HomepageForwardingMatcher<MockRequest> matcher = new HomepageForwardingMatcher<>(
31-
singletonList("/viewRoute/**"), singletonList("/viewRoute/*/exclude"), MockRequest::getMethod,
32-
MockRequest::getPath, MockRequest::getAccepts);
30+
singletonList("/viewRoute/**"), singletonList("/viewRoute/*/exclude"), MockRequest::method,
31+
MockRequest::path, MockRequest::accepts);
3332

3433
@Test
35-
public void should_return_false_when_method_is_not_get() {
34+
void should_return_false_when_method_is_not_get() {
3635
assertThat(this.matcher.test(new MockRequest("POST", "/viewRoute", singletonList(MediaType.TEXT_HTML))))
3736
.isFalse();
3837
}
3938

4039
@Test
41-
public void should_return_false_when_path_does_not_match() {
40+
void should_return_false_when_path_does_not_match() {
4241
assertThat(this.matcher.test(new MockRequest("GET", "/api", singletonList(MediaType.TEXT_HTML)))).isFalse();
4342
}
4443

4544
@Test
46-
public void should_return_false_when_accepts_does_not_match() {
45+
void should_return_false_when_accepts_does_not_match() {
4746
assertThat(this.matcher.test(new MockRequest("GET", "/viewRoute", singletonList(MediaType.APPLICATION_XML))))
4847
.isFalse();
4948
}
5049

5150
@Test
52-
public void should_return_false_when_path_is_excluded() {
51+
void should_return_false_when_path_is_excluded() {
5352
assertThat(this.matcher
5453
.test(new MockRequest("GET", "/viewRoute/12345/exclude", singletonList(MediaType.TEXT_HTML)))).isFalse();
5554
}
5655

5756
@Test
58-
public void should_return_true() {
57+
void should_return_true() {
5958
assertThat(this.matcher
6059
.test(new MockRequest("GET", "/viewRoute/detail?query", singletonList(MediaType.TEXT_HTML)))).isTrue();
6160
}
6261

63-
@Data
64-
private static final class MockRequest {
65-
66-
private final String method;
67-
68-
private final String path;
69-
70-
private final List<MediaType> accepts;
71-
62+
private record MockRequest(String method, String path, List<MediaType> accepts) {
7263
}
7364

7465
}

spring-boot-admin-server-ui/src/test/java/de/codecentric/boot/admin/server/ui/web/UiControllerTest.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@
3434
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
3535
import static org.springframework.util.CollectionUtils.isEmpty;
3636

37-
public class UiControllerTest {
37+
class UiControllerTest {
3838

3939
@Test
40-
public void should_use_default_url() throws Exception {
40+
void should_use_default_url() throws Exception {
4141
MockMvc mockMvc = setupController("", List.of());
4242

4343
mockMvc.perform(get("http://example/"))
@@ -47,7 +47,7 @@ public void should_use_default_url() throws Exception {
4747
}
4848

4949
@Test
50-
public void should_use_path_from_public_url() throws Exception {
50+
void should_use_path_from_public_url() throws Exception {
5151
MockMvc mockMvc = setupController("/public", List.of());
5252

5353
mockMvc.perform(get("http://example/"))
@@ -57,7 +57,7 @@ public void should_use_path_from_public_url() throws Exception {
5757
}
5858

5959
@Test
60-
public void should_use_host_and_path_from_public_url() throws Exception {
60+
void should_use_host_and_path_from_public_url() throws Exception {
6161
MockMvc mockMvc = setupController("http://public/public", List.of());
6262

6363
mockMvc.perform(get("http://example/"))
@@ -67,7 +67,7 @@ public void should_use_host_and_path_from_public_url() throws Exception {
6767
}
6868

6969
@Test
70-
public void should_use_scheme_host_and_path_from_public_url() throws Exception {
70+
void should_use_scheme_host_and_path_from_public_url() throws Exception {
7171
MockMvc mockMvc = setupController("https://public/public", List.of());
7272

7373
mockMvc.perform(get("http://example/"))
@@ -82,14 +82,14 @@ public void should_use_scheme_host_and_path_from_public_url() throws Exception {
8282
"link without children without url, null, false, true", //
8383
"link with children, null, true, false" }, //
8484
nullValues = { "null" })
85-
public void should_validate_external_views(String label, String url, boolean hasChildren, boolean shouldFail) {
85+
void should_validate_external_views(String label, String url, boolean hasChildren, boolean shouldFail) {
8686
try {
8787
UiController.ExternalView externalView = new UiController.ExternalView(label, url, 1, false,
8888
hasChildren
8989
? List.of(new UiController.ExternalView("child", "https://urli.com", 1, false, List.of()))
9090
: List.of());
9191

92-
setupController("http://mysba.com", List.of(externalView));
92+
setupController("https://mysba.com", List.of(externalView));
9393
}
9494
catch (Exception ex) {
9595
if (!shouldFail) {

0 commit comments

Comments
 (0)