Skip to content

Commit a5f7202

Browse files
authored
devonfw#127: Increase commandlet test coverage for EnvironmentCommandlet and ContextCommandlet (devonfw#144)
1 parent d2d4920 commit a5f7202

File tree

3 files changed

+93
-1
lines changed

3 files changed

+93
-1
lines changed
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
package com.devonfw.tools.ide.commandlet;
2+
3+
import java.util.Locale;
4+
5+
import org.junit.jupiter.api.Test;
6+
7+
import com.devonfw.tools.ide.context.AbstractIdeContext;
8+
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
9+
import com.devonfw.tools.ide.context.IdeContextConsole;
10+
11+
public class ContextCommandletTest extends AbstractIdeContextTest {
12+
13+
/**
14+
* Test of {@link ContextCommandlet} has name context.
15+
*/
16+
@Test
17+
public void testNameIsContext(){
18+
//arrange
19+
ContextCommandlet cxt = new ContextCommandlet();
20+
//act & assert
21+
assertThat(cxt.getName()).isEqualTo("context");
22+
}
23+
24+
/**
25+
* Test of {@link ContextCommandlet} does not require home.
26+
*/
27+
@Test
28+
public void testThatHomeIsNotReqired() {
29+
30+
// arrange
31+
ContextCommandlet cxt = new ContextCommandlet();
32+
//act & assert
33+
assertThat(cxt.isIdeHomeRequired()).isFalse();
34+
}
35+
36+
/**
37+
* Test of {@link ContextCommandlet} run.
38+
*/
39+
@Test
40+
public void testRun() {
41+
42+
// arrange
43+
ContextCommandlet cxt = new ContextCommandlet();
44+
// act
45+
cxt.run();
46+
// assert
47+
assertThat(cxt.getIdeContext()).isInstanceOf(IdeContextConsole.class);
48+
assertThat(cxt.getIdeContext().isForceMode()).isFalse();
49+
assertThat(cxt.getIdeContext().isBatchMode()).isFalse();
50+
assertThat(cxt.getIdeContext().isQuietMode()).isFalse();
51+
assertThat(cxt.getIdeContext().isOfflineMode()).isFalse();
52+
assertThat(cxt.getIdeContext().getLocale()).isEqualTo(Locale.getDefault());
53+
54+
}
55+
}

cli/src/test/java/com/devonfw/tools/ide/commandlet/EnvironmentCommandletTest.java

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,13 @@
11
package com.devonfw.tools.ide.commandlet;
22

3+
import com.devonfw.tools.ide.context.IdeContext;
34
import org.junit.jupiter.api.Test;
45

56
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
7+
import com.devonfw.tools.ide.context.IdeTestContext;
68
import com.devonfw.tools.ide.context.IdeTestContextMock;
79
import com.devonfw.tools.ide.environment.VariableLine;
10+
import com.devonfw.tools.ide.log.IdeLogLevel;
811

912
/**
1013
* Test of {@link EnvironmentCommandlet}.
@@ -64,4 +67,38 @@ public void testNormalizeWindowsLine() {
6467
assertThat(normalized.getName()).isEqualTo("MAGIC_PATH");
6568
}
6669

70+
/**
71+
* Test of {@link EnvironmentCommandlet} run.
72+
*/
73+
@Test
74+
public void testRun() {
75+
76+
// arrange
77+
String path = "workspaces/foo-test/my-git-repo";
78+
IdeTestContext context = newContext("basic", path, false);
79+
EnvironmentCommandlet env = context.getCommandletManager().getCommandlet(EnvironmentCommandlet.class);
80+
// act
81+
env.run();
82+
// assert
83+
assertLogMessage(context, IdeLogLevel.INFO, "MVN_VERSION=3.9.*");
84+
assertLogMessage(context, IdeLogLevel.INFO, "SOME=some-${UNDEFINED}");
85+
assertLogMessage(context, IdeLogLevel.INFO, "BAR=bar-some-${UNDEFINED}");
86+
assertLogMessage(context, IdeLogLevel.INFO, "IDE_TOOLS=mvn,eclipse");
87+
assertLogMessage(context, IdeLogLevel.INFO, "ECLIPSE_VERSION=2023-03");
88+
assertLogMessage(context, IdeLogLevel.INFO, "FOO=foo-bar-some-${UNDEFINED}");
89+
assertLogMessage(context, IdeLogLevel.INFO, "JAVA_VERSION=17*");
90+
assertLogMessage(context, IdeLogLevel.INFO, "INTELLIJ_EDITION=ultimate");
91+
assertLogMessage(context, IdeLogLevel.INFO, "DOCKER_EDITION=docker");
92+
}
93+
/**
94+
* Test of {@link EnvironmentCommandlet} does not require home.
95+
*/
96+
@Test
97+
public void testThatHomeIsNotReqired() {
98+
99+
// arrange
100+
EnvironmentCommandlet env = new EnvironmentCommandlet(IdeTestContextMock.get());
101+
// act & assert
102+
assertThat(env.isIdeHomeRequired()).isFalse();
103+
}
67104
}

cli/src/test/java/com/devonfw/tools/ide/commandlet/HelpCommandletTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public void testThatHomeIsNotReqired() {
2424
// act
2525
HelpCommandlet help = new HelpCommandlet(context);
2626
// assert
27-
assertThat(help.isIdeHomeRequired()).isEqualTo(false);
27+
assertThat(help.isIdeHomeRequired()).isFalse();
2828
}
2929

3030
/**

0 commit comments

Comments
 (0)