11package tech .jhipster .lite .cli .command .infrastructure .primary ;
22
33import static org .assertj .core .api .Assertions .assertThat ;
4- import static tech .jhipster .lite .TestProjects .newTestFolder ;
4+ import static tech .jhipster .lite .cli .command .infrastructure .primary .CliFixture .commandLine ;
5+ import static tech .jhipster .lite .cli .command .infrastructure .primary .CliFixture .setupProjectTestFolder ;
56
67import java .io .IOException ;
7- import java .nio .file .Files ;
88import java .nio .file .Path ;
9- import java .util .List ;
109import org .junit .jupiter .api .DisplayName ;
1110import org .junit .jupiter .api .Nested ;
1211import org .junit .jupiter .api .Test ;
1312import org .junit .jupiter .api .extension .ExtendWith ;
1413import org .springframework .beans .factory .annotation .Autowired ;
1514import org .springframework .boot .test .system .CapturedOutput ;
1615import org .springframework .boot .test .system .OutputCaptureExtension ;
17- import picocli .CommandLine ;
1816import tech .jhipster .lite .cli .IntegrationTest ;
1917import tech .jhipster .lite .module .application .JHipsterModulesApplicationService ;
2018import tech .jhipster .lite .module .infrastructure .secondary .git .GitTestUtil ;
@@ -42,18 +40,18 @@ class JHLiteCommandsFactoryTest {
4240 void shouldShowHelpMessageWhenNoCommand (CapturedOutput output ) {
4341 String [] args = {};
4442
45- int exitCode = commandLine ().execute (args );
43+ int exitCode = commandLine (modules , projects ).execute (args );
4644
4745 assertThat (exitCode ).isEqualTo (2 );
4846 assertThat (output ).contains (
49- """
50- JHipster Lite CLI
51- -h, --help Show this help message and exit.
52- -V, --version Print version information and exit.
53-
54- Commands:
55- """
56- );
47+ """
48+ JHipster Lite CLI
49+ -h, --help Show this help message and exit.
50+ -V, --version Print version information and exit.
51+
52+ Commands:
53+ """
54+ );
5755 }
5856
5957 @ Nested
@@ -64,7 +62,7 @@ class ListModules {
6462 void shouldListModules (CapturedOutput output ) {
6563 String [] args = { "list" };
6664
67- int exitCode = commandLine ().execute (args );
65+ int exitCode = commandLine (modules , projects ).execute (args );
6866
6967 assertThat (exitCode ).isZero ();
7068 assertThat (output )
@@ -84,7 +82,7 @@ class ApplyModule {
8482 void shouldNotApplyWithoutModuleSlugSubcommand (CapturedOutput output ) {
8583 String [] args = { "apply" };
8684
87- int exitCode = commandLine ().execute (args );
85+ int exitCode = commandLine (modules , projects ).execute (args );
8886
8987 assertThat (exitCode ).isEqualTo (2 );
9088 assertThat (output ).contains ("Missing required subcommand" ).contains ("init" ).contains ("prettier" );
@@ -94,7 +92,7 @@ void shouldNotApplyWithoutModuleSlugSubcommand(CapturedOutput output) {
9492 void shouldEscapeCommandDescriptionInHelpCommand (CapturedOutput output ) {
9593 String [] args = { "apply" , "--help" };
9694
97- int exitCode = commandLine ().execute (args );
95+ int exitCode = commandLine (modules , projects ).execute (args );
9896
9997 assertThat (exitCode ).isZero ();
10098 assertThat (output ).doesNotContain (
@@ -106,7 +104,7 @@ void shouldEscapeCommandDescriptionInHelpCommand(CapturedOutput output) {
106104 void shouldDisplayModuleSlugsInHelpCommand (CapturedOutput output ) {
107105 String [] args = { "apply" , "--help" };
108106
109- int exitCode = commandLine ().execute (args );
107+ int exitCode = commandLine (modules , projects ).execute (args );
110108
111109 assertThat (exitCode ).isZero ();
112110 assertThat (output )
@@ -128,7 +126,7 @@ void shouldDisplayModuleSlugsInHelpCommand(CapturedOutput output) {
128126 void shouldDisplayModuleSlugsInAlphabeticalOrderInApplyHelpCommand (CapturedOutput output ) {
129127 String [] args = { "apply" , "--help" };
130128
131- int exitCode = commandLine ().execute (args );
129+ int exitCode = commandLine (modules , projects ).execute (args );
132130
133131 assertThat (exitCode ).isZero ();
134132 assertThat (output .toString ().indexOf ("angular-core" ))
@@ -152,7 +150,7 @@ void shouldApplyInitModuleWithRequiredOptions() throws IOException {
152150 "npm" ,
153151 };
154152
155- int exitCode = commandLine ().execute (args );
153+ int exitCode = commandLine (modules , projects ).execute (args );
156154
157155 assertThat (exitCode ).isZero ();
158156 assertThat (GitTestUtil .getCommits (projectPath )).contains ("Apply module: init" );
@@ -165,7 +163,7 @@ void shouldNotApplyInitModuleMissingRequiredOptions(CapturedOutput output) throw
165163 Path projectPath = setupProjectTestFolder ();
166164 String [] args = { "apply" , "init" , "--project-path" , projectPath .toString () };
167165
168- int exitCode = commandLine ().execute (args );
166+ int exitCode = commandLine (modules , projects ).execute (args );
169167
170168 assertThat (exitCode ).isEqualTo (2 );
171169 assertThat (GitTestUtil .getCommits (projectPath )).isEmpty ();
@@ -193,7 +191,7 @@ void shouldApplyInitModuleWithCommitDefaultValue() throws IOException {
193191 "npm" ,
194192 };
195193
196- int exitCode = commandLine ().execute (args );
194+ int exitCode = commandLine (modules , projects ).execute (args );
197195
198196 assertThat (exitCode ).isZero ();
199197 assertThat (GitTestUtil .getCommits (projectPath )).contains ("Apply module: init" );
@@ -221,7 +219,7 @@ void shouldApplyInitModuleWithCommit() throws IOException {
221219 "--commit" ,
222220 };
223221
224- int exitCode = commandLine ().execute (args );
222+ int exitCode = commandLine (modules , projects ).execute (args );
225223
226224 assertThat (exitCode ).isZero ();
227225 assertThat (GitTestUtil .getCommits (projectPath )).contains ("Apply module: init" );
@@ -244,7 +242,7 @@ void shouldApplyInitModuleWithoutCommit() throws IOException {
244242 "--no-commit" ,
245243 };
246244
247- int exitCode = commandLine ().execute (args );
245+ int exitCode = commandLine (modules , projects ).execute (args );
248246
249247 assertThat (exitCode ).isZero ();
250248 assertThat (GitTestUtil .getCommits (projectPath )).isEmpty ();
@@ -266,7 +264,7 @@ void shouldNotApplyModuleWithInvalidBaseName() throws IOException {
266264 "npm" ,
267265 };
268266
269- int exitCode = commandLine ().execute (args );
267+ int exitCode = commandLine (modules , projects ).execute (args );
270268
271269 assertThat (exitCode ).isEqualTo (1 );
272270 }
@@ -289,7 +287,7 @@ void shouldApplyInitModuleWithIndentation() throws IOException {
289287 "4" ,
290288 };
291289
292- int exitCode = commandLine ().execute (args );
290+ int exitCode = commandLine (modules , projects ).execute (args );
293291
294292 assertThat (exitCode ).isZero ();
295293 assertThat (projectPropertyValue (projectPath , INDENT_SIZE )).isEqualTo (4 );
@@ -313,7 +311,7 @@ void shouldApplyInitModuleWithEndOfLine() throws IOException {
313311 "lf" ,
314312 };
315313
316- int exitCode = commandLine ().execute (args );
314+ int exitCode = commandLine (modules , projects ).execute (args );
317315
318316 assertThat (exitCode ).isZero ();
319317 assertThat (projectPropertyValue (projectPath , END_OF_LINE )).isEqualTo ("lf" );
@@ -334,7 +332,7 @@ void shouldReuseParametersFromPreviousModuleApplications() throws IOException {
334332 "--node-package-manager" ,
335333 "npm" ,
336334 };
337- int initModuleExitCode = commandLine ().execute (initModuleArgs );
335+ int initModuleExitCode = commandLine (modules , projects ).execute (initModuleArgs );
338336 assertThat (initModuleExitCode ).isZero ();
339337 String [] mavenJavaModuleArgs = {
340338 "apply" ,
@@ -345,7 +343,7 @@ void shouldReuseParametersFromPreviousModuleApplications() throws IOException {
345343 "com.my.company" ,
346344 };
347345
348- int mavenJavaModuleExitCode = commandLine ().execute (mavenJavaModuleArgs );
346+ int mavenJavaModuleExitCode = commandLine (modules , projects ).execute (mavenJavaModuleArgs );
349347
350348 assertThat (mavenJavaModuleExitCode ).isZero ();
351349 assertThat (projectPropertyValue (projectPath , PROJECT_NAME )).isEqualTo ("JHipster Sample Application" );
@@ -357,36 +355,10 @@ void shouldReuseParametersFromPreviousModuleApplications() throws IOException {
357355 void shouldShowVersion (CapturedOutput output ) {
358356 String [] args = { "--version" };
359357
360- int exitCode = commandLine ().execute (args );
358+ int exitCode = commandLine (modules , projects ).execute (args );
361359
362360 assertThat (exitCode ).isZero ();
363361 assertThat (output ).contains ("JHipster Lite CLI v1" ).contains ("JHipster Lite version: 2" );
364362 }
365-
366- private static Path setupProjectTestFolder () throws IOException {
367- String projectFolder = newTestFolder ();
368- Path projectPath = Path .of (projectFolder );
369- Files .createDirectories (projectPath );
370- loadGitConfig (projectPath );
371-
372- return projectPath ;
373- }
374-
375- private static void loadGitConfig (Path project ) {
376- GitTestUtil .execute (project , "init" );
377- GitTestUtil .execute (project , "config" , "init.defaultBranch" , "main" );
378- GitTestUtil .
execute (
project ,
"config" ,
"user.email" ,
"\" [email protected] \" " );
379- GitTestUtil .execute (project , "config" , "user.name" , "\" Test\" " );
380- }
381- }
382-
383- private CommandLine commandLine () {
384- ListModulesCommand listModulesCommand = new ListModulesCommand (modules );
385- ApplyModuleSubCommandsFactory subCommandsFactory = new ApplyModuleSubCommandsFactory (modules , projects );
386- ApplyModuleCommand applyModuleCommand = new ApplyModuleCommand (modules , subCommandsFactory );
387-
388- JHLiteCommandsFactory jhliteCommandsFactory = new JHLiteCommandsFactory (List .of (listModulesCommand , applyModuleCommand ), "1" , "2" );
389-
390- return new CommandLine (jhliteCommandsFactory .buildCommandSpec ());
391363 }
392364}
0 commit comments