From f414311e71a89eabc22d841116976311f9bce63b Mon Sep 17 00:00:00 2001 From: "gru-agent[bot]" <185149714+gru-agent[bot]@users.noreply.github.com> Date: Wed, 12 Feb 2025 07:04:18 +0000 Subject: [PATCH] Add tests for the main method in DemoApplication to handle various argument scenarios. --- .../example/demo/DemoApplicationTests.java | 33 +++++++++++++++++-- 1 file changed, 30 insertions(+), 3 deletions(-) diff --git a/src/test/java/com/example/demo/DemoApplicationTests.java b/src/test/java/com/example/demo/DemoApplicationTests.java index 2778a6a..931a2cf 100644 --- a/src/test/java/com/example/demo/DemoApplicationTests.java +++ b/src/test/java/com/example/demo/DemoApplicationTests.java @@ -2,12 +2,39 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.boot.SpringApplication; +import org.springframework.boot.test.system.OutputCaptureExtension; +import org.junit.jupiter.api.extension.ExtendWith; +import static org.junit.jupiter.api.Assertions.assertThrows; + +@ExtendWith(OutputCaptureExtension.class) @SpringBootTest class DemoApplicationTests { - @Test - void contextLoads() { - } + @Test + void contextLoads() { + } + + @Test + void testMainMethod() { + String[] args = new String[]{"arg1", "arg2"}; + DemoApplication.main(args); + } + + @Test + void testMainMethodWithEmptyArgs() { + // To avoid port conflicts, set a random port for this test + System.setProperty("server.port", "0"); + String[] args = new String[]{}; + DemoApplication.main(args); + } + @Test + void testMainMethodWithNullArgs() { + // Ensure that passing null arguments throws the expected exception + assertThrows(IllegalArgumentException.class, () -> { + DemoApplication.main(null); + }); + } }