Skip to content

Commit 0208805

Browse files
committed
Add input into ConfirmationInput
- Now displaying what user actually inputs - Backport #740 - Fixes #745
1 parent 33eb30e commit 0208805

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

spring-shell-core/src/main/resources/org/springframework/shell/component/confirmation-input-default.stg

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ result(model) ::= <<
3030

3131
// component is running
3232
running(model) ::= <<
33-
<question_name(model)> <info(model)>
33+
<question_name(model)> <info(model)> <model.input>
3434
<message(model)>
3535
>>
3636

spring-shell-core/src/test/java/org/springframework/shell/component/ConfirmationInputTests.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.ByteArrayOutputStream;
2020
import java.io.IOException;
2121
import java.nio.charset.StandardCharsets;
22+
import java.time.Duration;
2223
import java.util.concurrent.CountDownLatch;
2324
import java.util.concurrent.ExecutorService;
2425
import java.util.concurrent.Executors;
@@ -35,6 +36,7 @@
3536
import org.springframework.shell.component.context.ComponentContext;
3637

3738
import static org.assertj.core.api.Assertions.assertThat;
39+
import static org.awaitility.Awaitility.await;
3840

3941
public class ConfirmationInputTests extends AbstractShellTests {
4042

@@ -158,6 +160,36 @@ public void testResultUserInputNo() throws InterruptedException, IOException {
158160
assertThat(run1Context.getResultValue()).isFalse();
159161
}
160162

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+
161193
@Test
162194
public void testResultUserInputYes() throws InterruptedException, IOException {
163195
ComponentContext<?> empty = ComponentContext.empty();

0 commit comments

Comments
 (0)