Skip to content

Commit

Permalink
devonfw#898: fixed exception
Browse files Browse the repository at this point in the history
adjusted tests
  • Loading branch information
jan-vcapgemini committed Jan 16, 2025
1 parent 14c0dc2 commit e517a38
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ public void run() {
Object installedValue = getInstalledValue(commandlet);
boolean getInstalledValue = this.installed.isTrue();
boolean getConfiguredValue = this.configured.isTrue();
if (installedValue == null && getInstalledValue && !getConfiguredValue) {
throw new CliException("Tool " + commandlet + " is not installed.", 1);
}
if (getInstalledValue == getConfiguredValue) {
if (getInstalledValue) { // both --configured and --installed
logToolInfo(logger, commandlet, configuredValue, installedValue);
Expand All @@ -91,7 +94,6 @@ public void run() {
} else {
if (getInstalledValue) {
if (installedValue == null) {

logToolInfo(logger, commandlet, configuredValue, null);
} else {
logger.log(installedValue.toString());
Expand All @@ -107,15 +109,11 @@ private void logToolInfo(IdeSubLogger logger, ToolCommandlet commandlet, Object
String property = getPropertyToGet();
String toolName = commandlet.getName();
if (installedValue == null) {
throw new CliException("No installation of tool " + toolName + " was found.", 1);
} else {
logger.log("The installed {} for tool {} is {}.", property, toolName, installedValue);
}
if (configuredValue == null) {
logger.log("There is no configured {} for tool {}.", property, toolName);
logger.log("No installation of tool {} was found.", toolName);
} else {
logger.log("The configured {} for tool {} is {}.", property, toolName, configuredValue);
logger.log("The installed {} for tool {} is {}", property, toolName, installedValue);
}
logger.log("The configured {} for tool {} is {}", property, toolName, configuredValue);
if (!Objects.equals(configuredValue, installedValue)) {
logger.log("To install that {} call the following command:", property);
logger.log("ide install {}", toolName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ public void testEditionGetCommandletRunWithoutFlagsAndNotInstalled() {
// assert
assertThat(context).log().hasEntries(
IdeLogEntry.ofWarning("Undefined edition " + tool + " of tool " + tool),
IdeLogEntry.ofProcessable("The installed edition for tool " + tool + " is " + tool + "."),
IdeLogEntry.ofProcessable("The configured edition for tool " + tool + " is " + tool + "."));
IdeLogEntry.ofProcessable("The installed edition for tool " + tool + " is " + tool),
IdeLogEntry.ofProcessable("The configured edition for tool " + tool + " is " + tool));
}

/** Test of {@link VersionGetCommandlet} run with --configured flag and installed tool */
Expand All @@ -67,6 +67,21 @@ public void testEditionGetCommandletConfiguredEditionAndInstalled() {
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("java");
}

/** Test of {@link VersionGetCommandlet} run with --configured flag and not installed tool */
@Test
public void testEditionGetCommandletNotInstalledConfiguredEdition() {

// arrange
IdeTestContext context = newContext(PROJECT);
EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class);
editionGet.tool.setValueAsString("tomcat", context);
editionGet.configured.setValue(true);
// act
editionGet.run();
// assert
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("basic");
}

/** Test of {@link VersionGetCommandlet} run with --configured flag but tool was not installed */
@Test
public void testEditionGetCommandletConfiguredEditionButNotInstalled() {
Expand All @@ -82,7 +97,7 @@ public void testEditionGetCommandletConfiguredEditionButNotInstalled() {
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("az");
}

/** Test of {@link EditionGetCommandlet} run, when tool is not installed but --installed flag was used. */
/** Test of {@link EditionGetCommandlet} run, when tool is not installed but --installed flag was used and --configured was not used. */
@Test
public void testEditionGetCommandletToolNotInstalledButInstalledFlagInUseThrowsException() {

Expand All @@ -95,35 +110,39 @@ public void testEditionGetCommandletToolNotInstalledButInstalledFlagInUseThrowsE
assertThrows(CliException.class, () -> editionGet.run());
}

/** Test of {@link EditionGetCommandlet} run, with --installed flag, when Installed Version is null. */
/** Test of {@link EditionGetCommandlet} run, with --installed flag, when tool is installed. */
@Test
public void testEditionGetCommandletInstalledEditionToolNotInstalled() {
public void testEditionGetCommandletInstalledEditionToolInstalled() {

// arrange
IdeTestContext context = newContext(PROJECT);
EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class);
editionGet.tool.setValueAsString("java", context);
editionGet.tool.setValueAsString("mvn", context);
editionGet.installed.setValue(true);
// act
editionGet.run();
// assert
assertThat(context).log().hasEntries(IdeLogEntry.ofProcessable("java"));
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("mvn");
}


/** Test of {@link EditionGetCommandlet} run, with --installed flag, when tool is installed. */
/** Test of {@link EditionGetCommandlet} run, with --installed and --configured flag, when tool is not installed. */
@Test
public void testEditionGetCommandletInstalledEditionToolInstalled() {
public void testEditionGetCommandletInstalledConfiguredEditionToolNotInstalled() {

// arrange
String tool = "tomcat";
IdeTestContext context = newContext(PROJECT);
mockInstallTool(context, "mvn");
EditionGetCommandlet editionGet = context.getCommandletManager().getCommandlet(EditionGetCommandlet.class);
editionGet.tool.setValueAsString("mvn", context);
editionGet.tool.setValueAsString(tool, context);
editionGet.configured.setValue(true);
editionGet.installed.setValue(true);
// act
editionGet.run();
// assert
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("mvn");
assertThat(context).log().hasEntries(
IdeLogEntry.ofProcessable("No installation of tool " + tool + " was found."),
IdeLogEntry.ofProcessable("The configured edition for tool " + tool + " is basic"),
IdeLogEntry.ofProcessable("ide install " + tool)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,75 @@ public class VersionGetCommandletTest extends AbstractIdeContextTest {
private static final String PROJECT = "edition-version-get-uninstall";

/**
* Test of {@link VersionGetCommandlet} run, when Installed Version is null.
* Test of {@link VersionGetCommandlet} run, when Installed Version is null but configured version is set.
*/
@Test
public void testVersionGetCommandletNotInstalledRunThrowsException() {
public void testVersionGetCommandletNotInstalledRun() {

// arrange
IdeTestContext context = newContext(PROJECT);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
versionGet.tool.setValueAsString("java", context);
versionGet.tool.setValueAsString("az", context);
// act
versionGet.run();
// assert
assertThat(context).log().hasEntries(
IdeLogEntry.ofProcessable("No installation of tool az was found."),
IdeLogEntry.ofProcessable("The configured version for tool az is 1.0.1"),
IdeLogEntry.ofProcessable("ide install az"));
}

/**
* Test of {@link VersionGetCommandlet} run, when --installed flag is set, --configured is not set and installed version is null.
*/
@Test
public void testVersionGetCommandletNotInstalledWithInstalledFlagRunThrowsException() {

// arrange
IdeTestContext context = newContext(PROJECT);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
versionGet.tool.setValueAsString("tomcat", context);
versionGet.installed.setValue(true);
// act/assert
assertThrows(CliException.class, () -> versionGet.run());
}

/**
* Test of {@link VersionGetCommandlet} run.
* Test of {@link VersionGetCommandlet} run, when --configured flag is set, configured version is not set and installed version is null.
*/
@Test
public void testVersionGetCommandletNotInstalledConfiguredWithConfiguredFlagRun() {

// arrange
IdeTestContext context = newContext(PROJECT_SETTINGS);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
versionGet.tool.setValueAsString("az", context);
versionGet.configured.setValue(true);
// act
versionGet.run();
// assert
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("*");
}

/**
* Test of {@link VersionGetCommandlet} run, when --configured flag is set and Installed Version is null.
*/
@Test
public void testVersionGetCommandletNotInstalledWithConfigured() {

// arrange
IdeTestContext context = newContext(PROJECT);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
versionGet.tool.setValueAsString("az", context);
versionGet.configured.setValue(true);
// act
versionGet.run();
// assert
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("1.0.1");
}

/**
* Test of {@link VersionGetCommandlet} run, where "configured" flag is set and the configured version is 3.9.1.
*/
@Test
public void testVersionGetCommandletConfiguredRun() {
Expand All @@ -50,13 +104,13 @@ public void testVersionGetCommandletConfiguredRun() {
}

/**
* Test of {@link VersionGetCommandlet} run with the installed flag, where the installed version is 3.9.4.
* Test of {@link VersionGetCommandlet} run with the "installed" flag, where the installed version is 3.9.4.
*/
@Test
public void testVersionGetCommandletInstalledRun() {

// arrange
IdeTestContext context = newContext(PROJECT_SETTINGS);
IdeTestContext context = newContext(PROJECT);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
// act
versionGet.tool.setValueAsString("mvn", context);
Expand All @@ -83,6 +137,48 @@ public void testVersionGetCommandletConfiguredStarRun() {
assertThat(context).log(IdeLogLevel.PROCESSABLE).hasMessage("*");
}

/**
* Test of {@link VersionGetCommandlet} run with the "configured" and the "installed" flag, where the configured version is "any" (*).
*/
@Test
public void testVersionGetCommandletConfiguredInstalledRun() {

// arrange
IdeTestContext context = newContext(PROJECT_SETTINGS);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
// act
versionGet.tool.setValueAsString("mvn", context);
versionGet.configured.setValue(true);
versionGet.installed.setValue(true);
versionGet.run();
// assert
assertThat(context).log().hasEntries(
IdeLogEntry.ofProcessable("The installed version for tool mvn is 3.9.4"),
IdeLogEntry.ofProcessable("The configured version for tool mvn is *"),
IdeLogEntry.ofProcessable("ide install mvn"));
}

/**
* Test of {@link VersionGetCommandlet} run with the "configured" and the "installed" flag, where the configured version is 3.9.1.
*/
@Test
public void testVersionGetCommandletConfiguredInstalledSpecificRun() {

// arrange
IdeTestContext context = newContext(PROJECT);
VersionGetCommandlet versionGet = context.getCommandletManager().getCommandlet(VersionGetCommandlet.class);
// act
versionGet.tool.setValueAsString("mvn", context);
versionGet.configured.setValue(true);
versionGet.installed.setValue(true);
versionGet.run();
// assert
assertThat(context).log().hasEntries(
IdeLogEntry.ofProcessable("The installed version for tool mvn is 3.9.4"),
IdeLogEntry.ofProcessable("The configured version for tool mvn is 3.9.1"),
IdeLogEntry.ofProcessable("ide install mvn"));
}

/**
* Test of {@link VersionGetCommandlet} run, where a specific version is installed (mvn 3.9.4) but no specific version is configured (configured version *).
*/
Expand All @@ -97,8 +193,8 @@ public void testVersionGetCommandletMatchInstalledToConfiguredStarRun() {
versionGet.run();
// assert
assertThat(context).log().hasEntries(
IdeLogEntry.ofProcessable("The installed version for tool mvn is 3.9.4."),
IdeLogEntry.ofProcessable("The configured version for tool mvn is *."),
IdeLogEntry.ofProcessable("The installed version for tool mvn is 3.9.4"),
IdeLogEntry.ofProcessable("The configured version for tool mvn is *"),
IdeLogEntry.ofProcessable("ide install mvn")
);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
MVN_VERSION=3.9.1
AZ_VERSION=1.0.1
TOMCAT_EDITION=basic
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
3.9.4

0 comments on commit e517a38

Please sign in to comment.