Skip to content

Commit 5c1f0b5

Browse files
Create Robot.java
iluwatar#606 Robot pattern issue
1 parent 3a1a714 commit 5c1f0b5

File tree

1 file changed

+32
-0
lines changed
  • templateview/src/main/java/com/iluwatar/templateview

1 file changed

+32
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
package com.iluwatar.templateview;
2+
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.PrintStream;
5+
import static org.junit.jupiter.api.Assertions.assertTrue;
6+
7+
public class TemplateViewRobot {
8+
9+
private final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
10+
private final PrintStream originalOut = System.out;
11+
public TemplateViewRobot render(TemplateView view) {
12+
try {
13+
System.setOut(new PrintStream(outputStream));
14+
view.render();
15+
} finally {
16+
System.setOut(originalOut);
17+
}
18+
return this;
19+
}
20+
21+
public TemplateViewRobot verifyContent(String expectedContent) {
22+
String renderedOutput = outputStream.toString();
23+
assertTrue(renderedOutput.contains(expectedContent),
24+
String.format("Expected content '%s' not found in output:\n%s", expectedContent, renderedOutput));
25+
return this;
26+
}
27+
28+
public TemplateViewRobot reset() {
29+
outputStream.reset();
30+
return this;
31+
}
32+
}

0 commit comments

Comments
 (0)