Skip to content

Commit

Permalink
devonfw#127: Increase commandlet test coverage for EnvironmentCommand…
Browse files Browse the repository at this point in the history
…let and ContextCommandlet (devonfw#144)
  • Loading branch information
moritzLanger authored Dec 12, 2023
1 parent d2d4920 commit a5f7202
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package com.devonfw.tools.ide.commandlet;

import java.util.Locale;

import org.junit.jupiter.api.Test;

import com.devonfw.tools.ide.context.AbstractIdeContext;
import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeContextConsole;

public class ContextCommandletTest extends AbstractIdeContextTest {

/**
* Test of {@link ContextCommandlet} has name context.
*/
@Test
public void testNameIsContext(){
//arrange
ContextCommandlet cxt = new ContextCommandlet();
//act & assert
assertThat(cxt.getName()).isEqualTo("context");
}

/**
* Test of {@link ContextCommandlet} does not require home.
*/
@Test
public void testThatHomeIsNotReqired() {

// arrange
ContextCommandlet cxt = new ContextCommandlet();
//act & assert
assertThat(cxt.isIdeHomeRequired()).isFalse();
}

/**
* Test of {@link ContextCommandlet} run.
*/
@Test
public void testRun() {

// arrange
ContextCommandlet cxt = new ContextCommandlet();
// act
cxt.run();
// assert
assertThat(cxt.getIdeContext()).isInstanceOf(IdeContextConsole.class);
assertThat(cxt.getIdeContext().isForceMode()).isFalse();
assertThat(cxt.getIdeContext().isBatchMode()).isFalse();
assertThat(cxt.getIdeContext().isQuietMode()).isFalse();
assertThat(cxt.getIdeContext().isOfflineMode()).isFalse();
assertThat(cxt.getIdeContext().getLocale()).isEqualTo(Locale.getDefault());

}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
package com.devonfw.tools.ide.commandlet;

import com.devonfw.tools.ide.context.IdeContext;
import org.junit.jupiter.api.Test;

import com.devonfw.tools.ide.context.AbstractIdeContextTest;
import com.devonfw.tools.ide.context.IdeTestContext;
import com.devonfw.tools.ide.context.IdeTestContextMock;
import com.devonfw.tools.ide.environment.VariableLine;
import com.devonfw.tools.ide.log.IdeLogLevel;

/**
* Test of {@link EnvironmentCommandlet}.
Expand Down Expand Up @@ -64,4 +67,38 @@ public void testNormalizeWindowsLine() {
assertThat(normalized.getName()).isEqualTo("MAGIC_PATH");
}

/**
* Test of {@link EnvironmentCommandlet} run.
*/
@Test
public void testRun() {

// arrange
String path = "workspaces/foo-test/my-git-repo";
IdeTestContext context = newContext("basic", path, false);
EnvironmentCommandlet env = context.getCommandletManager().getCommandlet(EnvironmentCommandlet.class);
// act
env.run();
// assert
assertLogMessage(context, IdeLogLevel.INFO, "MVN_VERSION=3.9.*");
assertLogMessage(context, IdeLogLevel.INFO, "SOME=some-${UNDEFINED}");
assertLogMessage(context, IdeLogLevel.INFO, "BAR=bar-some-${UNDEFINED}");
assertLogMessage(context, IdeLogLevel.INFO, "IDE_TOOLS=mvn,eclipse");
assertLogMessage(context, IdeLogLevel.INFO, "ECLIPSE_VERSION=2023-03");
assertLogMessage(context, IdeLogLevel.INFO, "FOO=foo-bar-some-${UNDEFINED}");
assertLogMessage(context, IdeLogLevel.INFO, "JAVA_VERSION=17*");
assertLogMessage(context, IdeLogLevel.INFO, "INTELLIJ_EDITION=ultimate");
assertLogMessage(context, IdeLogLevel.INFO, "DOCKER_EDITION=docker");
}
/**
* Test of {@link EnvironmentCommandlet} does not require home.
*/
@Test
public void testThatHomeIsNotReqired() {

// arrange
EnvironmentCommandlet env = new EnvironmentCommandlet(IdeTestContextMock.get());
// act & assert
assertThat(env.isIdeHomeRequired()).isFalse();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public void testThatHomeIsNotReqired() {
// act
HelpCommandlet help = new HelpCommandlet(context);
// assert
assertThat(help.isIdeHomeRequired()).isEqualTo(false);
assertThat(help.isIdeHomeRequired()).isFalse();
}

/**
Expand Down

0 comments on commit a5f7202

Please sign in to comment.