|
20 | 20 | import java.nio.file.Path; |
21 | 21 | import java.util.List; |
22 | 22 | import java.util.NoSuchElementException; |
| 23 | +import java.util.concurrent.ExecutionException; |
| 24 | +import java.util.concurrent.TimeUnit; |
| 25 | +import java.util.concurrent.TimeoutException; |
23 | 26 | import java.util.logging.Logger; |
24 | 27 | import java.util.stream.Collectors; |
25 | 28 |
|
@@ -120,18 +123,23 @@ private void runVersionTest(String cliExecutable) throws IOException { |
120 | 123 | } |
121 | 124 |
|
122 | 125 | private void runCreateProjectTest(String cliExecutable) throws IOException { |
123 | | - Path dir = Files.createTempDirectory("project"); |
124 | | - Process process = new ProcessBuilder() |
125 | | - .directory(dir.toFile()) |
126 | | - .command(cliExecutable, "init", "--reset", "--batch") |
127 | | - .start(); |
128 | | - String result = String.join("\n", InputStreams.toLines(process.getInputStream())); |
129 | | - LOGGER.info("errors : " + String.join("\n", InputStreams.toLines(process.getErrorStream()))); |
130 | | - LOGGER.info("result output : " + result); |
131 | | - process.destroy(); |
132 | | - |
133 | | - LOGGER.info("exitValue - " + process.exitValue()); |
134 | | - assertThat(result, containsString("Switch directory to")); |
135 | | - assertThat(list(dir).size(), is(not(0))); |
| 126 | + try { |
| 127 | + Path dir = Files.createTempDirectory("project"); |
| 128 | + Process process = new ProcessBuilder() |
| 129 | + .directory(dir.toFile()) |
| 130 | + .command(cliExecutable, "init", "--reset", "--batch") |
| 131 | + .start() |
| 132 | + .onExit() |
| 133 | + .get(5, TimeUnit.MINUTES); |
| 134 | + String result = String.join("", InputStreams.toLines(process.getInputStream())); |
| 135 | + LOGGER.info("errors - " + InputStreams.toLines(process.getErrorStream())); |
| 136 | + process.destroy(); |
| 137 | + LOGGER.info("exitValue - " + process.exitValue()); |
| 138 | + LOGGER.info(result); |
| 139 | + assertThat(result, containsString("Switch directory to")); |
| 140 | + assertThat(list(dir).size(), is(not(0))); |
| 141 | + } catch (InterruptedException | ExecutionException | TimeoutException e) { |
| 142 | + throw new RuntimeException(e); |
| 143 | + } |
136 | 144 | } |
137 | 145 | } |
0 commit comments