|
17 | 17 |
|
18 | 18 | import org.junit.jupiter.api.Test; |
19 | 19 | import org.openrewrite.DocumentExample; |
| 20 | +import org.openrewrite.java.JavaParser; |
20 | 21 | import org.openrewrite.test.RecipeSpec; |
21 | 22 | import org.openrewrite.test.RewriteTest; |
22 | 23 |
|
@@ -288,4 +289,88 @@ void main() { |
288 | 289 | ) |
289 | 290 | ); |
290 | 291 | } |
| 292 | + |
| 293 | + @Test |
| 294 | + void doNotMigrateMainUsedAsMethodReference() { |
| 295 | + //language=java |
| 296 | + rewriteRun( |
| 297 | + java( |
| 298 | + """ |
| 299 | + interface MainMethod { |
| 300 | + void run(String[] args); |
| 301 | + } |
| 302 | + """ |
| 303 | + ), |
| 304 | + java( |
| 305 | + """ |
| 306 | + class Application { |
| 307 | + public static void main(String[] args) { |
| 308 | + System.out.println("Hello from main"); |
| 309 | + } |
| 310 | + } |
| 311 | +
|
| 312 | + class Runner { |
| 313 | + void executeMain() { |
| 314 | + MainMethod foo = Application::main; |
| 315 | + foo.run(null); |
| 316 | + } |
| 317 | + } |
| 318 | + """ |
| 319 | + ) |
| 320 | + ); |
| 321 | + } |
| 322 | + |
| 323 | + @Test |
| 324 | + void doNotMigrateMainWithNonDefaultConstructor() { |
| 325 | + //language=java |
| 326 | + rewriteRun( |
| 327 | + java( |
| 328 | + """ |
| 329 | + class Application { |
| 330 | + public static void main(String[] args) { |
| 331 | + System.out.println("Hello!"); |
| 332 | + } |
| 333 | +
|
| 334 | + public Application(String config) { |
| 335 | + // Non-default constructor |
| 336 | + } |
| 337 | + } |
| 338 | + """ |
| 339 | + ) |
| 340 | + ); |
| 341 | + } |
| 342 | + |
| 343 | + @Test |
| 344 | + void doNotMigrateMainInSpringBootApplication() { |
| 345 | + //language=java |
| 346 | + rewriteRun( |
| 347 | + spec -> spec.parser(JavaParser.fromJavaVersion().dependsOn( |
| 348 | + """ |
| 349 | + package org.springframework.boot.autoconfigure; |
| 350 | + public @interface SpringBootApplication {} |
| 351 | + """, |
| 352 | + """ |
| 353 | + package org.springframework.boot; |
| 354 | + public class SpringApplication { |
| 355 | + public static void run(Class<?> primarySource, String... args) {} |
| 356 | + } |
| 357 | + """ |
| 358 | + )), |
| 359 | + java( |
| 360 | + """ |
| 361 | + package com.example.demo; |
| 362 | +
|
| 363 | + import org.springframework.boot.SpringApplication; |
| 364 | + import org.springframework.boot.autoconfigure.SpringBootApplication; |
| 365 | +
|
| 366 | + @SpringBootApplication |
| 367 | + class DemoApplication { |
| 368 | + public static void main(String[] args) { |
| 369 | + SpringApplication.run(DemoApplication.class, args); |
| 370 | + } |
| 371 | + } |
| 372 | + """ |
| 373 | + ) |
| 374 | + ); |
| 375 | + } |
291 | 376 | } |
0 commit comments