-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainTest.java
More file actions
42 lines (34 loc) · 1.45 KB
/
MainTest.java
File metadata and controls
42 lines (34 loc) · 1.45 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
package dev.delivercraft.paint;
import static org.assertj.core.api.Assertions.assertThat;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintStream;
import java.nio.charset.StandardCharsets;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.ResourceLock;
import org.junit.jupiter.api.parallel.Resources;
class MainTest {
@Test
@ResourceLock("SYSTEM_IN")
@ResourceLock(Resources.SYSTEM_OUT)
@SuppressWarnings("PMD.CloseResource")
void main_GivenValidInput_ShouldPrintPaintEstimate() throws IOException {
InputStream originalInput = System.in;
PrintStream originalOutput = System.out;
String inputText = "1%n18%n20%n".formatted();
ByteArrayInputStream input = new ByteArrayInputStream(inputText.getBytes(StandardCharsets.UTF_8));
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (input; output; PrintStream printStream = new PrintStream(output, true, StandardCharsets.UTF_8)) {
System.setIn(input);
System.setOut(printStream);
new Main().main();
assertThat(output.toString(StandardCharsets.UTF_8)).contains(
"You will need to purchase 2 gallons of paint to cover 360 square feet.");
} finally {
System.setIn(originalInput);
System.setOut(originalOutput);
}
}
}