Skip to content

Commit 9ab77c7

Browse files
committed
Polish contribution
See gh-47987
1 parent bf0152e commit 9ab77c7

File tree

1 file changed

+43
-10
lines changed
  • spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart

1 file changed

+43
-10
lines changed

spring-boot-project/spring-boot-devtools/src/test/java/org/springframework/boot/devtools/restart/MainMethodTests.java

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -68,24 +68,41 @@ void viaJarLauncher() throws Exception {
6868
}
6969

7070
@Test
71-
void missingArgsMainMethod() throws Exception {
72-
Method actualMain = MissingArgs.class.getMethod("main");
73-
MainMethod method = new TestThread(MissingArgs::main).test();
71+
void detectPublicMainMethod() throws Exception {
72+
Method actualMain = PublicMainMethod.class.getMethod("main", String[].class);
73+
MainMethod method = new TestThread(PublicMainMethod::main).test();
7474
assertThat(method.getMethod()).isEqualTo(actualMain);
7575
assertThat(method.getDeclaringClassName()).isEqualTo(actualMain.getDeclaringClass().getName());
7676
}
7777

7878
@Test
79-
void missingArgsPackagePrivateMainMethod() throws Exception {
80-
Method actualMain = MissingArgsPackagePrivate.class.getDeclaredMethod("main");
81-
MainMethod method = new TestThread(MissingArgsPackagePrivate::main).test();
79+
void detectPublicParameterlessMainMethod() throws Exception {
80+
Method actualMain = PublicParameterlessMainMethod.class.getMethod("main");
81+
MainMethod method = new TestThread(PublicParameterlessMainMethod::main).test();
82+
assertThat(method.getMethod()).isEqualTo(actualMain);
83+
assertThat(method.getDeclaringClassName()).isEqualTo(actualMain.getDeclaringClass().getName());
84+
}
85+
86+
@Test
87+
void detectPackagePrivateMainMethod() throws Exception {
88+
Method actualMain = PackagePrivateMainMethod.class.getDeclaredMethod("main", String[].class);
89+
MainMethod method = new TestThread(PackagePrivateMainMethod::main).test();
90+
assertThat(method.getMethod()).isEqualTo(actualMain);
91+
assertThat(method.getDeclaringClassName()).isEqualTo(actualMain.getDeclaringClass().getName());
92+
}
93+
94+
@Test
95+
void detectPackagePrivateParameterlessMainMethod() throws Exception {
96+
Method actualMain = PackagePrivateParameterlessMainMethod.class.getDeclaredMethod("main");
97+
MainMethod method = new TestThread(PackagePrivateParameterlessMainMethod::main).test();
8298
assertThat(method.getMethod()).isEqualTo(actualMain);
8399
assertThat(method.getDeclaringClassName()).isEqualTo(actualMain.getDeclaringClass().getName());
84100
}
85101

86102
@Test
87103
void nonStatic() {
88-
assertThatIllegalStateException().isThrownBy(() -> new TestThread(() -> new NonStaticMain().main()).test())
104+
assertThatIllegalStateException()
105+
.isThrownBy(() -> new TestThread(() -> new NonStaticMainMethod().main()).test())
89106
.withMessageContaining("Unable to find main method");
90107
}
91108

@@ -144,23 +161,39 @@ public static void main(String... args) {
144161

145162
}
146163

147-
public static class MissingArgs {
164+
public static class PublicMainMethod {
165+
166+
public static void main(String... args) {
167+
mainMethod.set(new MainMethod());
168+
}
169+
170+
}
171+
172+
public static class PublicParameterlessMainMethod {
148173

149174
public static void main() {
150175
mainMethod.set(new MainMethod());
151176
}
152177

153178
}
154179

155-
public static class MissingArgsPackagePrivate {
180+
public static class PackagePrivateMainMethod {
181+
182+
static void main(String... args) {
183+
mainMethod.set(new MainMethod());
184+
}
185+
186+
}
187+
188+
public static class PackagePrivateParameterlessMainMethod {
156189

157190
static void main() {
158191
mainMethod.set(new MainMethod());
159192
}
160193

161194
}
162195

163-
public static class NonStaticMain {
196+
public static class NonStaticMainMethod {
164197

165198
void main(String... args) {
166199
mainMethod.set(new MainMethod());

0 commit comments

Comments
 (0)