Skip to content

Commit

Permalink
fix quality violations
Browse files Browse the repository at this point in the history
  • Loading branch information
uchitsa committed Dec 16, 2024
1 parent b7d0f2d commit 4bb88a7
Showing 1 changed file with 45 additions and 38 deletions.
83 changes: 45 additions & 38 deletions src/test/java/com/jcabi/log/VerboseProcessTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -102,29 +102,31 @@ void echosUnicodeCorrectly() {
@Test
void runsACommandLineScriptWithException() {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS, "");
final VerboseProcess process = new VerboseProcess(
new ProcessBuilder("cat", "/non-existing-file.txt")
.redirectErrorStream(true)
);
try {
process.stdout();
Assertions.fail("exception expected");
} catch (final IllegalArgumentException ex) {
MatcherAssert.assertThat(
"should be no such file exception",
ex.getMessage(),
Matchers.containsString("No such file or directory")
);
try (VerboseProcess process = new VerboseProcess(
new ProcessBuilder("cat", "/non-existing-file.txt").redirectErrorStream(true)
)) {
try {
process.stdout();
Assertions.fail("exception expected");
} catch (final IllegalArgumentException ex) {
MatcherAssert.assertThat(
"should be no such file exception",
ex.getMessage(),
Matchers.containsString("No such file or directory")
);
}
}
}

@Test
void runsACommandLineScriptWithExceptionNoRedir() throws Exception {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS, "");
final VerboseProcess process = new VerboseProcess(
final VerboseProcess.Result result;
try (VerboseProcess process = new VerboseProcess(
new ProcessBuilder("cat", "/non-existing-file.txt")
);
final VerboseProcess.Result result = process.waitFor();
)) {
result = process.waitFor();
}
MatcherAssert.assertThat(
"should be 1",
result.code(),
Expand All @@ -140,14 +142,15 @@ void runsACommandLineScriptWithExceptionNoRedir() throws Exception {
@Test
void handlesLongRunningCommand() {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS, "");
final VerboseProcess process = new VerboseProcess(
try (VerboseProcess process = new VerboseProcess(
new ProcessBuilder("/bin/bash", "-c", "sleep 2; echo 'done'")
);
MatcherAssert.assertThat(
"should be done",
process.stdout(),
Matchers.startsWith("done")
);
)) {
MatcherAssert.assertThat(
"should be done",
process.stdout(),
Matchers.startsWith("done")
);
}
}

@Test
Expand Down Expand Up @@ -208,18 +211,21 @@ void rejectsStderrWithLevelAll() {
void quietlyTerminatesLongRunningProcess() throws Exception {
Assumptions.assumeFalse(SystemUtils.IS_OS_WINDOWS, "");
final Process proc = new ProcessBuilder("sleep", "10000").start();
final VerboseProcess process = new VerboseProcess(proc);
final CountDownLatch start = new CountDownLatch(1);
final CountDownLatch done = new CountDownLatch(1);
new Thread(
final CountDownLatch start;
final CountDownLatch done;
try (VerboseProcess process = new VerboseProcess(proc)) {
start = new CountDownLatch(1);
done = new CountDownLatch(1);
new Thread(
new VerboseRunnable(
() -> {
start.countDown();
process.stdoutQuietly();
done.countDown();
}
)
).start();
() -> {
start.countDown();
process.stdoutQuietly();
done.countDown();
}
)
).start();
}
start.await();
TimeUnit.SECONDS.sleep(1L);
proc.destroy();
Expand All @@ -245,10 +251,11 @@ void stdoutQuietlyLogsErrors() {
"cat", String.format("/non-existing-file-%s ", message)
);
}
final VerboseProcess process = new VerboseProcess(
builder, Level.OFF, Level.WARNING
);
process.stdoutQuietly();
try (VerboseProcess process = new VerboseProcess(
builder, Level.OFF, Level.WARNING
)) {
process.stdoutQuietly();
}
MatcherAssert.assertThat(
"should be contains 'hello dear friend' message",
writer.toString(),
Expand Down

0 comments on commit 4bb88a7

Please sign in to comment.