diff --git a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java index fafa8041ff9..3058bca6c01 100644 --- a/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java +++ b/codan/org.eclipse.cdt.codan.core.test/src/org/eclipse/cdt/codan/internal/core/externaltool/ExternalToolInvokerTest.java @@ -16,14 +16,16 @@ import java.io.File; import java.util.ArrayList; import java.util.List; +import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser; import org.eclipse.cdt.codan.core.externaltool.ConfigurationSettings; import org.eclipse.cdt.codan.core.externaltool.IArgsSeparator; import org.eclipse.cdt.codan.core.externaltool.ICommandLauncher; -import org.eclipse.cdt.codan.core.externaltool.AbstractOutputParser; import org.eclipse.cdt.codan.core.externaltool.InvocationFailure; import org.eclipse.cdt.codan.core.externaltool.InvocationParameters; +import org.eclipse.cdt.codan.core.externaltool.SingleConfigurationSetting; import org.eclipse.cdt.codan.core.externaltool.SpaceDelimitedArgsSeparator; import org.eclipse.cdt.codan.core.param.BasicProblemPreference; +import org.eclipse.cdt.codan.core.param.IProblemPreference; import org.eclipse.cdt.codan.core.param.MapProblemPreference; import org.eclipse.cdt.codan.core.test.CodanTestCase; import org.eclipse.core.resources.IProject; @@ -67,16 +69,19 @@ public class ExternalToolInvokerTest extends CodanTestCase { private MapProblemPreference createPreferences(File path, String args, boolean shouldDisplayOutput) { MapProblemPreference preferences = new MapProblemPreference(); - preferences.addChildDescriptor(new BasicProblemPreference("externalToolPath", "Path")); - preferences.addChildDescriptor(new BasicProblemPreference("externalToolArgs", "Args")); - preferences.addChildDescriptor(new BasicProblemPreference("externalToolShouldDisplayOutput", - "Should Display Output")); - preferences.setChildValue("externalToolPath", path); - preferences.setChildValue("externalToolArgs", args); - preferences.setChildValue("externalToolShouldDisplayOutput", shouldDisplayOutput); + preferences.addChildDescriptor(createPreference(PathSetting.KEY, path)); + preferences.addChildDescriptor(createPreference(ArgsSetting.KEY, args)); + preferences.addChildDescriptor(createPreference(ShouldDisplayOutputSetting.KEY, + shouldDisplayOutput)); return preferences; } + private IProblemPreference createPreference(String key, Object value) { + BasicProblemPreference preference = new BasicProblemPreference(key, ""); + preference.setValue(value); + return preference; + } + @Override public boolean isCpp() { return true; @@ -89,26 +94,24 @@ public class ExternalToolInvokerTest extends CodanTestCase { InvocationParameters parameters = new InvocationParameters(currentIFile, currentIFile, currentIFile.getLocation().toOSString(), cproject.getProject().getLocation()); externalToolInvoker.invoke(parameters, configurationSettings, argsSeparator, parsers); - assertSame(cproject.getProject(), commandLauncher.project); - assertEquals(EXTERNAL_TOOL_NAME, commandLauncher.externalToolName); - String expectedExecutablePath = configurationSettings.getPath().getValue().toString(); - assertEquals(expectedExecutablePath, commandLauncher.executablePath.toOSString()); - String[] expectedArgs = { parameters.getActualFilePath(), "--debug=true", "--include=all" }; - assertArrayEquals(expectedArgs, commandLauncher.args); - assertEquals(parameters.getWorkingDirectory(), commandLauncher.workingDirectory); - assertEquals(configurationSettings.getShouldDisplayOutput().getValue().booleanValue(), - commandLauncher.shouldDisplayOutput); - assertSame(parsers, commandLauncher.parsers); + commandLauncher.assertThatReceivedProject(cproject.getProject()); + commandLauncher.assertThatReceivedExternalToolName(EXTERNAL_TOOL_NAME); + commandLauncher.assertThatReceivedExecutablePath(configurationSettings.getPath()); + commandLauncher.assertThatReceivedArgs(configurationSettings.getArgs()); + commandLauncher.assertThatReceivedWorkingDirectory(parameters.getWorkingDirectory()); + commandLauncher.assertThatReceivedShouldDisplayOutput( + configurationSettings.getShouldDisplayOutput()); + commandLauncher.assetThatReceivedOutputParsers(parsers); } private static class CommandLauncherStub implements ICommandLauncher { - IProject project; - String externalToolName; - IPath executablePath; - String[] args; - IPath workingDirectory; - boolean shouldDisplayOutput; - List parsers; + private IProject project; + private String externalToolName; + private IPath executablePath; + private String[] args; + private IPath workingDirectory; + private boolean shouldDisplayOutput; + private List parsers; @Override public void buildAndLaunchCommand(IProject project, String externalToolName, @@ -123,5 +126,35 @@ public class ExternalToolInvokerTest extends CodanTestCase { this.shouldDisplayOutput = shouldDisplayOutput; this.parsers = parsers; } + + void assertThatReceivedProject(IProject expected) { + assertEquals(expected, project); + } + + void assertThatReceivedExternalToolName(String expected) { + assertEquals(expected, externalToolName); + } + + void assertThatReceivedExecutablePath(SingleConfigurationSetting expected) { + String expectedPath = expected.getValue().toString(); + assertEquals(expectedPath, executablePath.toOSString()); + } + + void assertThatReceivedArgs(SingleConfigurationSetting expected) { + String[] expectedArgs = expected.getValue().split("\\s+"); + assertArrayEquals(expectedArgs, args); + } + + void assertThatReceivedWorkingDirectory(IPath expected) { + assertSame(expected, workingDirectory); + } + + void assertThatReceivedShouldDisplayOutput(SingleConfigurationSetting expected) { + assertEquals(expected.getValue().booleanValue(), shouldDisplayOutput); + } + + void assetThatReceivedOutputParsers(List expected) { + assertSame(expected, parsers); + } } } diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ArgsSetting.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ArgsSetting.java index 37d8a748d5e..61f0f9a4e47 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ArgsSetting.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ArgsSetting.java @@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor; * @since 2.1 */ public class ArgsSetting extends SingleConfigurationSetting { - private static final String KEY = "externalToolArgs"; //$NON-NLS-1$ + static final String KEY = "externalToolArgs"; //$NON-NLS-1$ /** * Constructor. diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/PathSetting.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/PathSetting.java index 378fab61be6..91864b1d147 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/PathSetting.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/PathSetting.java @@ -27,7 +27,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor; * @since 2.1 */ public class PathSetting extends SingleConfigurationSetting { - private static final String KEY = "externalToolPath"; //$NON-NLS-1$ + static final String KEY = "externalToolPath"; //$NON-NLS-1$ /** * Constructor. diff --git a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ShouldDisplayOutputSetting.java b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ShouldDisplayOutputSetting.java index e3aaf704219..77c3ce5a95d 100644 --- a/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ShouldDisplayOutputSetting.java +++ b/codan/org.eclipse.cdt.codan.core/src/org/eclipse/cdt/codan/internal/core/externaltool/ShouldDisplayOutputSetting.java @@ -26,7 +26,7 @@ import org.eclipse.cdt.codan.core.param.IProblemPreferenceDescriptor; * @since 2.1 */ public class ShouldDisplayOutputSetting extends SingleConfigurationSetting { - private static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$ + static final String KEY = "externalToolShouldDisplayOutput"; //$NON-NLS-1$ /** * Constructor.