@@ -335,10 +335,64 @@ class OpenApiGradlePluginTest {
335
335
}
336
336
}
337
337
338
+ @Test
339
+ fun `running the same build keeps the OpenAPI task up to date` () {
340
+ buildFile.writeText(
341
+ """
342
+ $baseBuildGradle
343
+ openApi {}
344
+ """ .trimMargin()
345
+ )
346
+
347
+ // Run the first build to generate the OpenAPI file
348
+ assertEquals(TaskOutcome .SUCCESS , openApiDocsTask(runTheBuild()).outcome)
349
+ assertOpenApiJsonFile(1 )
350
+
351
+ // Rerunning the build does not regenerate the OpenAPI file
352
+ assertEquals(TaskOutcome .UP_TO_DATE , openApiDocsTask(runTheBuild()).outcome)
353
+ assertOpenApiJsonFile(1 )
354
+ }
355
+
356
+ @Test
357
+ fun `changing the source code regenerates the OpenAPI` () {
358
+ buildFile.writeText(
359
+ """
360
+ $baseBuildGradle
361
+ openApi {}
362
+ """ .trimMargin()
363
+ )
364
+
365
+ // Run the first build to generate the OpenAPI file
366
+ assertEquals(TaskOutcome .SUCCESS , openApiDocsTask(runTheBuild()).outcome)
367
+ assertOpenApiJsonFile(1 )
368
+
369
+ val addedFile = projectTestDir.resolve(" src/main/java/com/example/demo/endpoints/AddedController.java" )
370
+ addedFile.createNewFile()
371
+ addedFile.writeText("""
372
+ package com.example.demo.endpoints;
373
+
374
+ import org.springframework.web.bind.annotation.GetMapping;
375
+ import org.springframework.web.bind.annotation.RestController;
376
+
377
+ @RestController
378
+ public class AddedController {
379
+
380
+ @GetMapping("/added")
381
+ public String added() {
382
+ return "Added file";
383
+ }
384
+ }
385
+ """ .trimIndent())
386
+
387
+ // Run the same build with added source file
388
+ assertEquals(TaskOutcome .SUCCESS , openApiDocsTask(runTheBuild()).outcome)
389
+ assertOpenApiJsonFile(2 )
390
+ }
391
+
338
392
private fun runTheBuild (vararg additionalArguments : String = emptyArray()) =
339
393
GradleRunner .create()
340
394
.withProjectDir(projectTestDir)
341
- .withArguments(" clean " , " generateOpenApiDocs" , * additionalArguments)
395
+ .withArguments(" generateOpenApiDocs" , * additionalArguments)
342
396
.withPluginClasspath()
343
397
.build()
344
398
0 commit comments