Add basic tests for the launcher package
diff --git a/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java b/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
index 32106c3..7aa5322 100644
--- a/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
+++ b/src/main/java/org/apache/commons/exec/launcher/VmsCommandLauncher.java
@@ -39,7 +39,7 @@
/**
* Writes the command into a temporary DCL script and returns the corresponding File object. The script will be deleted on exit.
*/
- private File createCommandFile(final CommandLine cmd, final Map<String, String> env) throws IOException {
+ File createCommandFile(final CommandLine cmd, final Map<String, String> env) throws IOException {
final Path path = Files.createTempFile("EXEC", ".TMP");
final File script = path.toFile();
script.deleteOnExit();
diff --git a/src/test/java/org/apache/commons/exec/launcher/AbstractCommandLauncherTest.java b/src/test/java/org/apache/commons/exec/launcher/AbstractCommandLauncherTest.java
new file mode 100644
index 0000000..b5929a4
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/AbstractCommandLauncherTest.java
@@ -0,0 +1,41 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.junit.jupiter.api.Test;
+
+abstract class AbstractCommandLauncherTest<T extends CommandLauncher> {
+
+ abstract T createCommandLauncher();
+
+ @Test
+ public void testIsFailure() throws Exception {
+ final T commandLauncher = createCommandLauncher();
+ assertTrue(commandLauncher.isFailure(2));
+ assertTrue(commandLauncher.isFailure(1));
+ }
+
+ @Test
+ public void testIsFailureZero() throws Exception {
+ assertFalse(createCommandLauncher().isFailure(0));
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/CommandLauncherFactoryTest.java b/src/test/java/org/apache/commons/exec/launcher/CommandLauncherFactoryTest.java
new file mode 100644
index 0000000..14dad58
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/CommandLauncherFactoryTest.java
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
+import org.junit.jupiter.api.Test;
+
+/**
+ * Tests {@link CommandLauncherFactory}.
+ */
+public class CommandLauncherFactoryTest {
+
+ @Test
+ public void testCreateVMLauncher() throws Exception {
+ assertNotNull(CommandLauncherFactory.createVMLauncher());
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/CommandLauncherImplTest.java b/src/test/java/org/apache/commons/exec/launcher/CommandLauncherImplTest.java
new file mode 100644
index 0000000..eb013e0
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/CommandLauncherImplTest.java
@@ -0,0 +1,42 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Map;
+
+import org.apache.commons.exec.CommandLine;
+
+public class CommandLauncherImplTest extends AbstractCommandLauncherTest<CommandLauncherImpl> {
+
+ static class CommandLauncherImplFixture extends CommandLauncherImpl {
+
+ @Override
+ public Process exec(final CommandLine cmd, final Map<String, String> env, final File workingDir) throws IOException {
+ return null;
+ }
+
+ }
+
+ @Override
+ CommandLauncherImpl createCommandLauncher() {
+ return new CommandLauncherImplFixture();
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/Java13CommandLauncherTest.java b/src/test/java/org/apache/commons/exec/launcher/Java13CommandLauncherTest.java
new file mode 100644
index 0000000..1e64aad
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/Java13CommandLauncherTest.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+public class Java13CommandLauncherTest extends AbstractCommandLauncherTest<Java13CommandLauncher> {
+
+ @Override
+ Java13CommandLauncher createCommandLauncher() {
+ return new Java13CommandLauncher();
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/OS2CommandLauncherTest.java b/src/test/java/org/apache/commons/exec/launcher/OS2CommandLauncherTest.java
new file mode 100644
index 0000000..c903564
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/OS2CommandLauncherTest.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+public class OS2CommandLauncherTest extends AbstractCommandLauncherTest<OS2CommandLauncher> {
+
+ @Override
+ OS2CommandLauncher createCommandLauncher() {
+ return new OS2CommandLauncher(CommandLauncherFactory.createVMLauncher());
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/VmsCommandLauncherTest.java b/src/test/java/org/apache/commons/exec/launcher/VmsCommandLauncherTest.java
new file mode 100644
index 0000000..8821be1
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/VmsCommandLauncherTest.java
@@ -0,0 +1,63 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import java.io.IOException;
+import java.util.HashMap;
+
+import org.apache.commons.exec.CommandLine;
+import org.junit.jupiter.api.Test;
+
+public class VmsCommandLauncherTest extends AbstractCommandLauncherTest<VmsCommandLauncher> {
+
+ @Override
+ VmsCommandLauncher createCommandLauncher() {
+ return new VmsCommandLauncher();
+ }
+
+ @Test
+ public void testCreateCommandFile() throws IOException {
+ final VmsCommandLauncher commandLauncher = createCommandLauncher();
+ final CommandLine cl = CommandLine.parse("a b \"c d\"");
+ assertNotNull(commandLauncher.createCommandFile(cl, null));
+ final HashMap<String, String> env = new HashMap<>();
+ assertNotNull(commandLauncher.createCommandFile(cl, env));
+ env.put("EnvKey", "EnvValue");
+ assertNotNull(commandLauncher.createCommandFile(cl, env));
+
+ }
+
+ @Override
+ @Test
+ public void testIsFailure() throws Exception {
+ final CommandLauncher commandLauncher = createCommandLauncher();
+ assertTrue(commandLauncher.isFailure(2));
+ assertFalse(commandLauncher.isFailure(1));
+ }
+
+ @Override
+ @Test
+ public void testIsFailureZero() throws Exception {
+ assertTrue(createCommandLauncher().isFailure(0));
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/exec/launcher/WinNTCommandLauncherTest.java b/src/test/java/org/apache/commons/exec/launcher/WinNTCommandLauncherTest.java
new file mode 100644
index 0000000..1ec9a2a
--- /dev/null
+++ b/src/test/java/org/apache/commons/exec/launcher/WinNTCommandLauncherTest.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.exec.launcher;
+
+public class WinNTCommandLauncherTest extends AbstractCommandLauncherTest<WinNTCommandLauncher> {
+
+ @Override
+ WinNTCommandLauncher createCommandLauncher() {
+ return new WinNTCommandLauncher(CommandLauncherFactory.createVMLauncher());
+ }
+
+}