Skip to content

Commit 15d64b1

Browse files
committed
Added a 3rd test to include the full scenario
1 parent 6139ada commit 15d64b1

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

javav2/example_code/inspector/src/test/java/InspectorTests.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
22
// SPDX-License-Identifier: Apache-2.0
33

4+
import com.java.inspector.InspectorScenario;
45
import org.slf4j.Logger;
56
import org.slf4j.LoggerFactory;
67
import com.java.inspector.HelloInspector;
@@ -15,6 +16,12 @@
1516
import software.amazon.awssdk.regions.Region;
1617
import software.amazon.awssdk.services.inspector2.Inspector2Client;
1718

19+
import java.io.ByteArrayInputStream;
20+
import java.io.ByteArrayOutputStream;
21+
import java.io.InputStream;
22+
import java.io.PrintStream;
23+
import java.util.Collections;
24+
1825
import static org.junit.jupiter.api.Assertions.*;
1926

2027
@TestInstance(TestInstance.Lifecycle.PER_METHOD)
@@ -101,4 +108,40 @@ public void testInspectorActionsIntegration() {
101108

102109
logger.info("Test 2 passed");
103110
}
111+
112+
113+
@Test
114+
@Tag("IntegrationTest")
115+
@Order(3)
116+
public void testInspectorScenarioEndToEnd() {
117+
assertDoesNotThrow(() -> {
118+
119+
// The scenario calls scanner.nextLine() repeatedly.
120+
// We simulate user input by providing many "c" lines.
121+
String simulatedInput = String.join("\n",
122+
Collections.nCopies(20, "c")) + "\n";
123+
124+
InputStream originalIn = System.in;
125+
PrintStream originalOut = System.out;
126+
127+
try {
128+
// Redirect System.in to simulated input
129+
ByteArrayInputStream testIn = new ByteArrayInputStream(simulatedInput.getBytes());
130+
System.setIn(testIn);
131+
132+
// Capture System.out so logs don’t spam the console
133+
System.setOut(new PrintStream(new ByteArrayOutputStream()));
134+
135+
// Run the scenario
136+
InspectorScenario.main(new String[]{});
137+
138+
} finally {
139+
// Restore original I/O streams
140+
System.setIn(originalIn);
141+
System.setOut(originalOut);
142+
}
143+
});
144+
145+
logger.info("Test 3 (Scenario end-to-end) passed");
146+
}
104147
}

0 commit comments

Comments
 (0)