From 767b0bb8fe1a06cd95768ff9957fc64fd27d3e45 Mon Sep 17 00:00:00 2001 From: sameagen Date: Tue, 11 Jun 2024 15:57:05 -0400 Subject: [PATCH 1/2] Fix MatlabCommandRunner --- .../mathworks/ci/utilities/MatlabCommandRunner.java | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java index 1f6f233a..921274fd 100644 --- a/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java +++ b/src/main/java/com/mathworks/ci/utilities/MatlabCommandRunner.java @@ -5,7 +5,6 @@ * */ -import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; @@ -36,16 +35,15 @@ public MatlabCommandRunner(MatlabActionParameters params) throws IOException, In this.params = params; this.additionalEnvVars = new HashMap(); + FilePath workspace = params.getWorkspace(); + // Handle case where workspace doesn't exist - if (!params.getWorkspace().exists()) { - params.getWorkspace().mkdirs(); + if (!workspace.exists()) { + workspace.mkdirs(); } // Create MATLAB folder - FilePath matlabFolder = new FilePath( - params.getLauncher().getChannel(), params.getWorkspace().getRemote() - + File.separator - + ".matlab"); + FilePath matlabFolder = new FilePath(workspace, ".matlab"); matlabFolder.mkdirs(); // Create temp folder From 8e6040d1512989872634255323a9e497ab56e2b5 Mon Sep 17 00:00:00 2001 From: sameagen Date: Tue, 11 Jun 2024 16:31:07 -0400 Subject: [PATCH 2/2] Update unit tests --- .../ci/utilities/MatlabCommandRunnerTest.java | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java index 742afc81..7dcc695b 100644 --- a/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java +++ b/src/test/java/unit/com/mathworks/ci/utilities/MatlabCommandRunnerTest.java @@ -40,7 +40,6 @@ @RunWith(MockitoJUnitRunner.class) public class MatlabCommandRunnerTest { - @Mock private FilePath workspace; @Mock private Launcher launcher; @Mock private ProcStarter procStarter; private EnvVars env; @@ -57,14 +56,12 @@ public class MatlabCommandRunnerTest { public void initialize() throws IOException, InterruptedException { env = new EnvVars(); - when(params.getWorkspace()).thenReturn(workspace); + doReturn(new FilePath(tempDir.getRoot())).when(params).getWorkspace(); when(params.getLauncher()).thenReturn(launcher); when(params.getEnvVars()).thenReturn(env); when(params.getTaskListener()).thenReturn(listener); when(params.getStartupOptions()).thenReturn(""); - when(launcher.getChannel()).thenReturn(null); - when(workspace.getRemote()).thenReturn(tempDir.getRoot().getAbsolutePath()); when(listener.getLogger()).thenReturn(logger); doReturn(false).when(launcher).isUnix(); @@ -87,8 +84,7 @@ public void validConstructorDoesNotThrow() throws IOException, InterruptedExcept @Test public void constructorUsesParamsForTempFolder() throws IOException, InterruptedException { MatlabCommandRunner runner = new MatlabCommandRunner(params); - verify(params, times(1)).getLauncher(); - verify(params, times(3)).getWorkspace(); + verify(params, times(1)).getWorkspace(); } @Test @@ -214,7 +210,7 @@ public void runUsesWorkspaceLocationAsWD() throws IOException, InterruptedExcept runner.runMatlabCommand("COMMAND"); - verify(procStarter).pwd(workspace); + verify(procStarter).pwd(new FilePath(tempDir.getRoot())); } @Test