44import org .junit .jupiter .api .BeforeEach ;
55import org .junit .jupiter .api .Test ;
66import org .junit .jupiter .api .DisplayName ;
7- import picocli .CommandLine ;
87
98import java .io .ByteArrayOutputStream ;
109import java .io .PrintStream ;
@@ -17,13 +16,11 @@ class ContextMapperCLITest {
1716 private final ByteArrayOutputStream errContent = new ByteArrayOutputStream ();
1817 private final PrintStream originalOut = System .out ;
1918 private final PrintStream originalErr = System .err ;
20- private CommandLine cmd ;
2119
2220 @ BeforeEach
2321 void setUp () {
2422 System .setOut (new PrintStream (outContent ));
2523 System .setErr (new PrintStream (errContent ));
26- cmd = new CommandLine (new ContextMapperCLI ());
2724 }
2825
2926 @ AfterEach
@@ -39,7 +36,7 @@ void main_WhenCalledWithoutCommand_ThenPrintsTopLevelHelp() {
3936 // No arguments for this test case
4037
4138 // When
42- cmd . execute ( );
39+ ContextMapperCLI . runCLI ( new String [ 0 ] );
4340
4441 // Then
4542 assertThat (outContent .toString ()).contains ("Context Mapper CLI. Use 'cm --help' for usage information." );
@@ -52,7 +49,7 @@ void main_WhenCalledWithHelpOption_ThenPrintsTopLevelHelp() {
5249 String [] args = { "--help" };
5350
5451 // When
55- int exitCode = cmd . execute (args );
52+ int exitCode = ContextMapperCLI . runCLI (args );
5653
5754 // Then
5855 assertThat (exitCode ).isEqualTo (0 );
@@ -70,11 +67,25 @@ void main_WhenCalledWithVersionOption_ThenPrintsVersion() {
7067 String [] args = { "--version" };
7168
7269 // When
73- int exitCode = cmd . execute (args );
70+ int exitCode = ContextMapperCLI . runCLI (args );
7471
7572 // Then
7673 assertThat (exitCode ).isEqualTo (0 );
77- assertThat (outContent .toString ()).contains ("Context Mapper CLI" );
74+ assertThat (outContent .toString ().trim ()).isEqualTo ("Context Mapper CLI DEVELOPMENT VERSION" );
75+ }
76+
77+ @ Test
78+ @ DisplayName ("main() should print version when called with -V option" )
79+ void main_WhenCalledWithShortVersionOption_ThenPrintsVersion () {
80+ // Given
81+ String [] args = { "-V" };
82+
83+ // When
84+ int exitCode = ContextMapperCLI .runCLI (args );
85+
86+ // Then
87+ assertThat (exitCode ).isEqualTo (0 );
88+ assertThat (outContent .toString ().trim ()).isEqualTo ("Context Mapper CLI DEVELOPMENT VERSION" );
7889 }
7990
8091 @ Test
@@ -84,7 +95,7 @@ void main_WhenCalledWithInvalidOption_ThenPrintsErrorAndUsage() {
8495 String [] args = { "--invalid-option" };
8596
8697 // When
87- int exitCode = cmd . execute (args );
98+ int exitCode = ContextMapperCLI . runCLI (args );
8899
89100 // Then
90101 assertThat (exitCode ).isNotEqualTo (0 );
@@ -100,7 +111,7 @@ void main_WhenCalledWithInvalidSubcommand_ThenPrintsErrorAndUsage() {
100111 String [] args = { "invalid-command" };
101112
102113 // When
103- int exitCode = cmd . execute (args );
114+ int exitCode = ContextMapperCLI . runCLI (args );
104115
105116 // Then
106117 assertThat (exitCode ).isNotEqualTo (0 );
0 commit comments