-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBasicExampleTest.java
More file actions
86 lines (73 loc) · 2.18 KB
/
BasicExampleTest.java
File metadata and controls
86 lines (73 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
package example;
import app.zoftwhere.bolt.Runner;
import java.io.PrintStream;
import java.util.Scanner;
import org.junit.jupiter.api.Test;
/**
* A couple of basic examples of how the Bolt Assertion runner can be used in tests.
*
* @author Osmund
* @version 11.4.0
* @since 1.0.0
*/
class BasicExampleTest {
// An immutable runner that can be reused.
private final Runner runner = new Runner();
private static void basic(Scanner scanner, PrintStream out) {
out.print("Hello World?");
}
private static void run(String[] argumentArray, Scanner scanner, PrintStream out) {
out.print("Program arguments:");
for (final String line : argumentArray) {
out.println();
out.print(line);
}
}
private static String runProcess() {
// Run the process and get the exit code.
try {
Thread.sleep(100);
return "Success!";
} catch (InterruptedException e) {
return "Interrupted";
}
}
@Test
void testCase() {
// Start with defining a application (must accept scanner and print stream).
runner.run(BasicExampleTest::basic).input().expected("Hello World?").assertSuccess();
// Start with defining the application input (application must still accept scanner and print
// stream).
runner.input().run(BasicExampleTest::basic).expected("Hello World?").assertSuccess();
// Run a simple lambda.
runner
.run((scanner, out) -> out.print("Hello World!"))
.input()
.expected("Hello World!")
.assertSuccess();
// Run a program with arguments.
runner
.run(BasicExampleTest::run)
.argument("a=1", "b=2")
.input()
.expected("Program arguments:", "a=1", "b=2")
.assertSuccess();
// Run with arguments with input.
runner
.input()
.argument("a=1", "b=2")
.run(BasicExampleTest::run)
.expected("Program arguments:", "a=1", "b=2")
.assertSuccess();
// Run with a difference method.
runner
.input()
.run(
(scanner, out) -> {
String result = runProcess();
out.print(result);
})
.expected("Success!")
.assertSuccess();
}
}