Skip to content

Commit eda7d34

Browse files
Dependencies updating
1 parent 4b32afb commit eda7d34

File tree

4 files changed

+91
-84
lines changed

4 files changed

+91
-84
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ All features of [zt-exec](https://github.com/zeroturnaround/zt-exec) are support
3030
<dependency>
3131
<groupId>org.cactoos</groupId>
3232
<artifactId>cactoos</artifactId>
33-
<version>0.11.10</version>
33+
<version>0.29</version>
3434
</dependency>
3535
````
3636
### Examples

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@
7070
<dependency>
7171
<groupId>org.cactoos</groupId>
7272
<artifactId>cactoos</artifactId>
73-
<version>0.11.10</version>
73+
<version>0.29</version>
7474
</dependency>
7575
</dependencies>
7676
</project>

src/main/java/com/enot/cmd/core/Cmd.java

Lines changed: 20 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package com.enot.cmd.core;
22

33
import org.apache.commons.io.FileUtils;
4-
import org.cactoos.list.ArrayAsIterable;
5-
import org.cactoos.list.ConcatIterable;
6-
import org.cactoos.list.MappedIterable;
4+
import org.cactoos.iterable.IterableOf;
5+
import org.cactoos.iterable.Joined;
6+
import org.cactoos.iterable.Mapped;
77
import org.zeroturnaround.exec.ProcessExecutor;
88

99
import java.io.File;
@@ -28,8 +28,9 @@ public final class Cmd implements ICmd {
2828
public Cmd() {
2929
this(false,
3030
"",
31-
new Listening(null, new ArrayAsIterable<>()),
32-
e -> {},
31+
new Listening(null, new IterableOf<>()),
32+
e -> {
33+
},
3334
"");
3435
}
3536

@@ -83,9 +84,9 @@ private ProcessExecutor processExecutor(String... command) {
8384
executor.addListener(listener);
8485
}
8586

86-
Iterable<String> commands = new ArrayAsIterable<>(command);
87+
Iterable<String> commands = new IterableOf<>(command);
8788
if (interpreter != null && !interpreter.trim().isEmpty()) {
88-
commands = new ConcatIterable<>(new ArrayAsIterable<>(interpreter), commands);
89+
commands = new Joined<>(new IterableOf<>(interpreter), commands);
8990
}
9091

9192
LambdaListenerAdapter beforeStart = new LambdaListenerAdapter((LambdaListenerAdapter.BeforeStart) processExecutor -> {
@@ -151,44 +152,40 @@ public Listening(Cmd owner, Iterable<LambdaListenerAdapter> listeners) {
151152
public CmdListening beforeStart(LambdaListenerAdapter.BeforeStart... lambdas) {
152153
return new Listening(
153154
owner,
154-
new ConcatIterable<>(
155+
new Joined<>(
155156
this.listeners,
156-
new MappedIterable<>(
157-
new ArrayAsIterable<>(lambdas),
158-
LambdaListenerAdapter::new)));
157+
new Mapped<>(LambdaListenerAdapter::new,
158+
new IterableOf<>(lambdas))));
159159
}
160160

161161
@Override
162162
public CmdListening afterStart(LambdaListenerAdapter.AfterStart... lambdas) {
163163
return new Listening(
164164
owner,
165-
new ConcatIterable<>(
165+
new Joined<>(
166166
this.listeners,
167-
new MappedIterable<>(
168-
new ArrayAsIterable<>(lambdas),
169-
LambdaListenerAdapter::new)));
167+
new Mapped<>(LambdaListenerAdapter::new,
168+
new IterableOf<>(lambdas))));
170169
}
171170

172171
@Override
173172
public CmdListening afterFinish(LambdaListenerAdapter.AfterFinish... lambdas) {
174173
return new Listening(
175174
owner,
176-
new ConcatIterable<>(
175+
new Joined<>(
177176
this.listeners,
178-
new MappedIterable<>(
179-
new ArrayAsIterable<>(lambdas),
180-
LambdaListenerAdapter::new)));
177+
new Mapped<>(LambdaListenerAdapter::new,
178+
new IterableOf<>(lambdas))));
181179
}
182180

183181
@Override
184182
public CmdListening afterStop(LambdaListenerAdapter.AfterStop... lambdas) {
185183
return new Listening(
186184
owner,
187-
new ConcatIterable<>(
185+
new Joined<>(
188186
this.listeners,
189-
new MappedIterable<>(
190-
new ArrayAsIterable<>(lambdas),
191-
LambdaListenerAdapter::new)));
187+
new Mapped<>(LambdaListenerAdapter::new,
188+
new IterableOf<>(lambdas))));
192189
}
193190

194191
@Override

src/test/java/com/enot/cmd/CmdTest.java

Lines changed: 69 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package com.enot.cmd;
22

33
import com.enot.cmd.core.Cmd;
4-
import org.hamcrest.core.IsEqual;
5-
import org.hamcrest.core.IsSame;
6-
import org.junit.Assert;
74
import org.junit.Test;
85
import org.zeroturnaround.exec.stream.LogOutputStream;
96

@@ -16,121 +13,134 @@
1613
import java.util.UUID;
1714
import java.util.concurrent.TimeoutException;
1815

19-
import static org.junit.Assert.*;
16+
import static org.hamcrest.core.AllOf.allOf;
17+
import static org.hamcrest.core.Is.is;
18+
import static org.hamcrest.core.IsNot.not;
19+
import static org.junit.Assert.assertThat;
2020

2121
public class CmdTest {
2222
@Test
2323
public void interpreterCommandLine() {
24-
Assert.assertThat(
24+
assertThat(
2525
new Cmd()
2626
.interpreter("sh")
2727
.command("-c", "echo Hello;")
2828
.commandLine(),
29-
new IsEqual<>(Arrays.asList("sh", "-c", "echo Hello;")));
29+
is(Arrays.asList("sh", "-c", "echo Hello;")));
3030
}
3131

3232
@Test
3333
public void execute() throws Exception {
34-
Assert.assertEquals("Hello\n",
34+
assertThat(
3535
new Cmd()
3636
.configuring(e -> e.readOutput(true))
3737
.command("echo", "Hello")
3838
.execute()
39-
.outputUTF8());
39+
.outputUTF8(),
40+
is("Hello\n"));
4041
}
4142

4243
@Test
4344
public void executeNoTimeout() throws Exception {
44-
Assert.assertEquals("Hello\n",
45+
assertThat(
4546
new Cmd()
4647
.configuring(e -> e.readOutput(true))
4748
.command("echo", "Hello")
4849
.executeNoTimeout()
49-
.outputUTF8());
50+
.outputUTF8(),
51+
is("Hello\n"));
5052
}
5153

5254
@Test
5355
public void start() throws Exception {
54-
Assert.assertEquals("Hello\n",
56+
assertThat(
5557
new Cmd()
5658
.configuring(e -> e.readOutput(true))
5759
.command("echo", "Hello")
5860
.start()
5961
.getFuture()
6062
.get()
61-
.outputUTF8());
63+
.outputUTF8(),
64+
is("Hello\n"));
6265
}
6366

6467
@Test
6568
public void executeScript() throws Exception {
66-
Assert.assertEquals("Hello\n",
69+
assertThat(
6770
new Cmd()
6871
.configuring(e -> e.readOutput(true))
6972
.interpreter("sh")
7073
.command("-c", "s='Hello'; echo $s;")
7174
.execute()
72-
.outputUTF8());
75+
.outputUTF8(),
76+
is("Hello\n"));
7377
}
7478

7579
@Test
7680
public void createWorkDir() throws Exception {
77-
File workDir = generateRandomPath().toFile();
78-
79-
assertFalse(workDir.exists());
80-
81-
new Cmd()
82-
.configuring(e -> e.directory(workDir))
83-
.command("echo", "hello world")
84-
.execute();
85-
86-
assertTrue(workDir.exists());
81+
final File workDir = generateRandomPath().toFile();
82+
assertThat(true, allOf(
83+
is(not(workDir.exists())),
84+
is(0 == new Cmd()
85+
.configuring(e -> e.directory(workDir))
86+
.command("echo", "hello world")
87+
.execute()
88+
.getExitValue()),
89+
is(workDir.exists())
90+
));
8791
}
8892

8993
@Test
9094
public void cleanUp() throws Exception {
91-
File workDir = generateRandomPath().toFile();
92-
93-
assertFalse(workDir.exists());
94-
95-
new Cmd()
96-
.configuring(e -> e.directory(workDir))
97-
.cleanUp(true)
98-
.command("echo", "hello world")
99-
.execute();
100-
101-
assertFalse("Directory should be deleted", workDir.exists());
95+
final File workDir = generateRandomPath().toFile();
96+
assertThat(true, allOf(
97+
is(not(workDir.exists())),
98+
is(0 == new Cmd()
99+
.configuring(e -> e.directory(workDir))
100+
.cleanUp(true)
101+
.command("echo", "hello world")
102+
.execute()
103+
.getExitValue()),
104+
is(not(workDir.exists()))
105+
));
102106
}
103107

104108
@Test
105109
public void outputFile() throws Exception {
106-
Path execDir = generateRandomPath();
107-
String outputFileName = "test.output";
108-
new Cmd()
109-
.configuring(e -> e.directory(execDir.toFile()))
110-
.outputFileName(outputFileName)
111-
.command("echo", "hello world")
112-
.execute();
113-
assertTrue("Output file should be exists", Paths.get(execDir.toString(), outputFileName).toFile().exists());
110+
final String outputFileName = "test.output";
111+
final File workDir = generateRandomPath().toFile();
112+
assertThat(true, allOf(
113+
is(not(workDir.exists())),
114+
is(0 == new Cmd()
115+
.configuring(e -> e.directory(workDir))
116+
.outputFileName(outputFileName)
117+
.command("echo", "hello world")
118+
.execute()
119+
.getExitValue()),
120+
is(new File(workDir, outputFileName).exists())
121+
));
114122
}
115123

116124
@Test
117125
public void beforeStartListener() throws IOException, InterruptedException, TimeoutException {
118-
ArrayList<String> lines = new ArrayList<>();
119-
final String arg = "line1";
120-
new Cmd()
121-
.listening()
122-
.beforeStart(e -> e.redirectOutputAlsoTo(new LogOutputStream() {
123-
@Override
124-
protected void processLine(String line) {
125-
lines.add(line);
126-
}
127-
}))
128-
.back()
129-
.command("echo", arg)
130-
.execute();
131-
132-
assertEquals(1, lines.size());
133-
assertEquals(arg, lines.get(0));
126+
final ArrayList<String> lines = new ArrayList<>();
127+
final String message = "line1";
128+
assertThat(true, allOf(
129+
is(0 == new Cmd()
130+
.listening()
131+
.beforeStart(e -> e.redirectOutputAlsoTo(new LogOutputStream() {
132+
@Override
133+
protected void processLine(String line) {
134+
lines.add(line);
135+
}
136+
}))
137+
.back()
138+
.command("echo", message)
139+
.execute()
140+
.getExitValue()),
141+
is(1 == lines.size()),
142+
is(message.equals(lines.get(0)))
143+
));
134144
}
135145

136146
private Path generateRandomPath() {

0 commit comments

Comments
 (0)