|
19 | 19 | import java.io.ByteArrayOutputStream;
|
20 | 20 | import java.io.IOException;
|
21 | 21 | import java.nio.charset.StandardCharsets;
|
| 22 | +import java.time.Duration; |
22 | 23 | import java.util.concurrent.CountDownLatch;
|
23 | 24 | import java.util.concurrent.ExecutorService;
|
24 | 25 | import java.util.concurrent.Executors;
|
|
35 | 36 | import org.springframework.shell.component.context.ComponentContext;
|
36 | 37 |
|
37 | 38 | import static org.assertj.core.api.Assertions.assertThat;
|
| 39 | +import static org.awaitility.Awaitility.await; |
38 | 40 |
|
39 | 41 | public class ConfirmationInputTests extends AbstractShellTests {
|
40 | 42 |
|
@@ -158,6 +160,36 @@ public void testResultUserInputNo() throws InterruptedException, IOException {
|
158 | 160 | assertThat(run1Context.getResultValue()).isFalse();
|
159 | 161 | }
|
160 | 162 |
|
| 163 | + @Test |
| 164 | + public void testUserInputShown() throws InterruptedException, IOException { |
| 165 | + ComponentContext<?> empty = ComponentContext.empty(); |
| 166 | + ConfirmationInput component1 = new ConfirmationInput(getTerminal(), "component1"); |
| 167 | + component1.setResourceLoader(new DefaultResourceLoader()); |
| 168 | + component1.setTemplateExecutor(getTemplateExecutor()); |
| 169 | + |
| 170 | + service.execute(() -> { |
| 171 | + ConfirmationInputContext run1Context = component1.run(empty); |
| 172 | + result1.set(run1Context); |
| 173 | + latch1.countDown(); |
| 174 | + }); |
| 175 | + |
| 176 | + TestBuffer testBuffer = new TestBuffer().append("N"); |
| 177 | + write(testBuffer.getBytes()); |
| 178 | + |
| 179 | + await().atMost(Duration.ofSeconds(4)) |
| 180 | + .untilAsserted(() -> assertThat(consoleOut()).contains("N")); |
| 181 | + |
| 182 | + testBuffer = new TestBuffer().cr(); |
| 183 | + write(testBuffer.getBytes()); |
| 184 | + |
| 185 | + latch1.await(2, TimeUnit.SECONDS); |
| 186 | + ConfirmationInputContext run1Context = result1.get(); |
| 187 | + |
| 188 | + assertThat(run1Context).isNotNull(); |
| 189 | + assertThat(run1Context.getResultValue()).isNotNull(); |
| 190 | + assertThat(run1Context.getResultValue()).isFalse(); |
| 191 | + } |
| 192 | + |
161 | 193 | @Test
|
162 | 194 | public void testResultUserInputYes() throws InterruptedException, IOException {
|
163 | 195 | ComponentContext<?> empty = ComponentContext.empty();
|
|
0 commit comments