-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add basic tests for the launcher package
- Loading branch information
1 parent
3837d17
commit c19c812
Showing
8 changed files
with
262 additions
and
1 deletion.
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
41 changes: 41 additions & 0 deletions
41
src/test/java/org/apache/commons/exec/launcher/AbstractCommandLauncherTest.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,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)); | ||
} | ||
|
||
} |
34 changes: 34 additions & 0 deletions
34
src/test/java/org/apache/commons/exec/launcher/CommandLauncherFactoryTest.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,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()); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
src/test/java/org/apache/commons/exec/launcher/CommandLauncherImplTest.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,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(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/org/apache/commons/exec/launcher/Java13CommandLauncherTest.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,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(); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/org/apache/commons/exec/launcher/OS2CommandLauncherTest.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,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()); | ||
} | ||
|
||
} |
63 changes: 63 additions & 0 deletions
63
src/test/java/org/apache/commons/exec/launcher/VmsCommandLauncherTest.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,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)); | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
src/test/java/org/apache/commons/exec/launcher/WinNTCommandLauncherTest.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,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()); | ||
} | ||
|
||
} |