-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
improved test infrastructure to mock aspects of IdeContext (#775)
- Loading branch information
Showing
9 changed files
with
185 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
cli/src/test/java/com/devonfw/tools/ide/commandlet/TestCommandletManager.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.devonfw.tools.ide.commandlet; | ||
|
||
import com.devonfw.tools.ide.context.IdeContext; | ||
|
||
/** | ||
* Extends {@link CommandletManagerImpl} to make {@link #add(Commandlet)} method visible for testing and mocking. | ||
*/ | ||
public class TestCommandletManager extends CommandletManagerImpl { | ||
|
||
/** | ||
* @param context the {@link IdeContext}. | ||
*/ | ||
public TestCommandletManager(IdeContext context) { | ||
|
||
super(context); | ||
} | ||
|
||
@Override | ||
public void add(Commandlet commandlet) { | ||
|
||
super.add(commandlet); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
89 changes: 89 additions & 0 deletions
89
cli/src/test/java/com/devonfw/tools/ide/tool/ide/IdeToolDummyCommandletTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.devonfw.tools.ide.tool.ide; | ||
|
||
import java.nio.file.Path; | ||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Set; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.io.TempDir; | ||
|
||
import com.devonfw.tools.ide.commandlet.Commandlet; | ||
import com.devonfw.tools.ide.common.Tag; | ||
import com.devonfw.tools.ide.context.AbstractIdeContextTest; | ||
import com.devonfw.tools.ide.context.AbstractIdeTestContext; | ||
import com.devonfw.tools.ide.context.IdeContext; | ||
import com.devonfw.tools.ide.context.IdeSlf4jContext; | ||
import com.devonfw.tools.ide.process.ProcessErrorHandling; | ||
import com.devonfw.tools.ide.process.ProcessMode; | ||
import com.devonfw.tools.ide.process.ProcessResult; | ||
import com.devonfw.tools.ide.process.ProcessResultImpl; | ||
import com.devonfw.tools.ide.step.Step; | ||
import com.devonfw.tools.ide.tool.plugin.ToolPluginDescriptor; | ||
import com.devonfw.tools.ide.version.GenericVersionRange; | ||
|
||
/** | ||
* Test of {@link IdeToolCommandlet} using {@link IdeToolDummyCommandlet}. | ||
*/ | ||
public class IdeToolDummyCommandletTest extends AbstractIdeContextTest { | ||
|
||
/** | ||
* Run the dummy commandlet and test that only active plugins are passed to installPlugin method. | ||
* | ||
* @param tempDir the {@link TempDir}. | ||
*/ | ||
@Test | ||
public void testDummyCommandlet(@TempDir Path tempDir) { | ||
|
||
AbstractIdeTestContext context = new IdeSlf4jContext(); | ||
context.setPluginsPath(tempDir); | ||
context.setSettingsPath(Path.of("src/test/resources/settings/dummy")); | ||
IdeToolDummyCommandlet dummyCommandlet = new IdeToolDummyCommandlet(context, "dummy", Set.of(Tag.IDE)); | ||
|
||
context.addCommandlet(dummyCommandlet); | ||
|
||
Commandlet dummy = context.getCommandletManager().getCommandlet("dummy"); | ||
assertThat(dummy).isSameAs(dummyCommandlet); | ||
dummy.run(); | ||
assertThat(dummyCommandlet.installedPlugins).hasSize(1); | ||
ToolPluginDescriptor plugin = dummyCommandlet.installedPlugins.get(0); | ||
assertThat(plugin.id()).isEqualTo("plugin1-id"); | ||
assertThat(plugin.url()).isEqualTo("https://dummy.com/plugins/plugin1-url"); | ||
} | ||
|
||
/** | ||
* Dummy commandlet extending {@link IdeToolCommandlet} for testing. | ||
*/ | ||
public static class IdeToolDummyCommandlet extends IdeToolCommandlet { | ||
|
||
final List<ToolPluginDescriptor> installedPlugins; | ||
|
||
IdeToolDummyCommandlet(IdeContext context, String tool, Set<Tag> tags) { | ||
|
||
super(context, tool, tags); | ||
this.installedPlugins = new ArrayList<>(); | ||
} | ||
|
||
@Override | ||
protected void configureWorkspace() { | ||
|
||
// disable workspace configuration since we have no IDE_HOME and therefore no settings | ||
} | ||
|
||
@Override | ||
public ProcessResult runTool(ProcessMode processMode, GenericVersionRange toolVersion, ProcessErrorHandling errorHandling, String... args) { | ||
|
||
// skip installation but trigger postInstall to test mocked plugin installation | ||
postInstall(true); | ||
return new ProcessResultImpl(0, List.of(), List.of()); | ||
} | ||
|
||
@Override | ||
public void installPlugin(ToolPluginDescriptor plugin, Step step) { | ||
|
||
this.installedPlugins.add(plugin); | ||
step.success("Dummy plugin " + plugin.name() + " installed."); | ||
} | ||
|
||
} | ||
} |
4 changes: 4 additions & 0 deletions
4
cli/src/test/resources/settings/dummy/dummy/plugins/plugin1.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
plugin_id=plugin1-id | ||
plugin_active=true | ||
plugin_url=https://dummy.com/plugins/plugin1-url | ||
tags=dummy |
4 changes: 4 additions & 0 deletions
4
cli/src/test/resources/settings/dummy/dummy/plugins/plugin2.properties
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
plugin_id=plugin2-id | ||
plugin_active=false | ||
plugin_url=https://dummy.com/plugins/plugin2-url | ||
tags=dummy2 |