1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.maven.plugin.surefire.booterclient.lazytestprovider;
20
21 import org.apache.maven.surefire.shared.utils.cli.CommandLineException;
22 import org.assertj.core.api.Condition;
23 import org.junit.Test;
24
25 import static org.apache.maven.surefire.shared.lang3.SystemUtils.IS_OS_WINDOWS;
26 import static org.assertj.core.api.Assertions.assertThat;
27
28
29
30
31 public class CommandlineTest {
32 @Test
33 public void shouldGetEnvironmentVariables() {
34 Commandline cli = new Commandline();
35 String[] env = cli.getEnvironmentVariables();
36
37 assertThat(env).doesNotHaveDuplicates().satisfies(new ContainsAnyStartsWith("JAVA_HOME="));
38
39 String[] excluded = {"JAVA_HOME"};
40 cli = new Commandline(excluded);
41 env = cli.getEnvironmentVariables();
42
43 assertThat(env).doesNotHaveDuplicates().satisfies(new NotContainsAnyStartsWith("JAVA_HOME="));
44 }
45
46 @Test
47 public void shouldExecute() throws CommandLineException {
48 Commandline cli = new Commandline();
49 cli.getShell().setWorkingDirectory(System.getProperty("user.dir"));
50 cli.getShell().setExecutable(IS_OS_WINDOWS ? "dir" : "ls");
51 cli.execute();
52 }
53
54 private static final class ContainsAnyStartsWith extends Condition<Object[]> {
55 private final String expected;
56
57 ContainsAnyStartsWith(String expected) {
58 this.expected = expected;
59 }
60
61 @Override
62 public boolean matches(Object[] values) {
63 boolean matches = false;
64 for (Object value : values) {
65 assertThat(value).isInstanceOf(String.class);
66 matches |= ((String) value).startsWith(expected);
67 }
68 return matches;
69 }
70 }
71
72 private static final class NotContainsAnyStartsWith extends Condition<Object[]> {
73 private final String expected;
74
75 NotContainsAnyStartsWith(String expected) {
76 this.expected = expected;
77 }
78
79 @Override
80 public boolean matches(Object[] values) {
81 boolean matches = false;
82 for (Object value : values) {
83 assertThat(value).isInstanceOf(String.class);
84 matches |= ((String) value).startsWith(expected);
85 }
86 return !matches;
87 }
88 }
89 }