Skip to content

Commit 45b1ff2

Browse files
JayBazuziisidore4dsherwood
committed
- r remove comments
Co-Authored-By: Llewellyn Falco <[email protected]> Co-Authored-By: 4dsherwood <[email protected]>
1 parent 0b63609 commit 45b1ff2

File tree

2 files changed

+11
-57
lines changed

2 files changed

+11
-57
lines changed

approvaltests-tests/src/test/java/org/approvaltests/utils/ConsoleOutputTests.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,10 @@
55
import org.approvaltests.reporters.UseReporter;
66
import org.junit.jupiter.api.Test;
77

8-
import static org.junit.jupiter.api.Assertions.assertEquals;
9-
8+
@UseReporter(AutoApproveReporter.class)
109
public class ConsoleOutputTests
1110
{
1211
@Test
13-
@UseReporter(AutoApproveReporter.class)
1412
void testVerifyOutput()
1513
{
1614
var expected = """
@@ -26,7 +24,6 @@ void testVerifyOutput()
2624
}
2725
}
2826
@Test
29-
@UseReporter(AutoApproveReporter.class)
3027
void testVerifyError()
3128
{
3229
var expected = """
@@ -42,7 +39,6 @@ void testVerifyError()
4239
}
4340
}
4441
@Test
45-
@UseReporter(AutoApproveReporter.class)
4642
void testVerifyAll()
4743
{
4844
var expected = """

approvaltests/src/main/java/org/approvaltests/utils/ConsoleOutput.java

Lines changed: 10 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -6,109 +6,67 @@
66
import java.io.ByteArrayOutputStream;
77
import java.io.PrintStream;
88

9-
/**
10-
* A try-with-resources compatible utility for capturing console output.
11-
* Captures both System.out and System.err streams and provides methods
12-
* to retrieve the captured content as strings.
13-
*/
149
public class ConsoleOutput implements AutoCloseable
1510
{
1611
private final ByteArrayOutputStream outContent;
1712
private final ByteArrayOutputStream errContent;
1813
private final PrintStream originalOut;
1914
private final PrintStream originalErr;
20-
/**
21-
* Creates a new ConsoleOutput instance and begins capturing console output.
22-
* Both System.out and System.err are redirected to internal buffers.
23-
*/
15+
2416
public ConsoleOutput()
2517
{
26-
// Store original streams
2718
originalOut = System.out;
2819
originalErr = System.err;
29-
// Create capture streams
3020
outContent = new ByteArrayOutputStream();
3121
errContent = new ByteArrayOutputStream();
32-
// Redirect system streams
3322
System.setOut(new PrintStream(outContent));
3423
System.setErr(new PrintStream(errContent));
3524
}
36-
/**
37-
* Returns the captured standard output as a string.
38-
* @return The content written to System.out since this ConsoleOutput was created
39-
*/
25+
4026
public String getOutput()
4127
{
4228
return outContent.toString();
4329
}
44-
/**
45-
* Returns the captured standard error as a string.
46-
* @return The content written to System.err since this ConsoleOutput was created
47-
*/
30+
4831
public String getError()
4932
{
5033
return errContent.toString();
5134
}
52-
/**
53-
* Verifies the captured standard output using ApprovalTests.
54-
* This is a convenience method that calls Approvals.verify() on the captured output.
55-
*/
35+
5636
public void verifyOutput()
5737
{
5838
verifyOutput(new Options());
5939
}
60-
/**
61-
* Verifies the captured standard output using ApprovalTests with options.
62-
* This is a convenience method that calls Approvals.verify() on the captured output.
63-
* @param options The options to use for verification
64-
*/
40+
6541
public void verifyOutput(Options options)
6642
{
6743
Approvals.verify(getOutput(), options);
6844
}
69-
/**
70-
* Verifies the captured standard error using ApprovalTests.
71-
* This is a convenience method that calls Approvals.verify() on the captured error output.
72-
*/
45+
7346
public void verifyError()
7447
{
7548
Approvals.verify(getError());
7649
}
77-
/**
78-
* Verifies the captured standard error using ApprovalTests with options.
79-
* This is a convenience method that calls Approvals.verify() on the captured error output.
80-
* @param options The options to use for verification
81-
*/
50+
8251
public void verifyError(Options options)
8352
{
8453
Approvals.verify(getError(), options);
8554
}
86-
/**
87-
* Verifies both captured standard output and error using ApprovalTests.
88-
* This is a convenience method that calls Approvals.verify() on both the output and error combined.
89-
*/
55+
9056
public void verifyAll()
9157
{
9258
verifyAll(new Options());
9359
}
94-
/**
95-
* Verifies both captured standard output and error using ApprovalTests with options.
96-
* This is a convenience method that calls Approvals.verify() on both the output and error combined.
97-
* @param options The options to use for verification
98-
*/
60+
9961
public void verifyAll(Options options)
10062
{
10163
String combined = "Output:\n" + getOutput() + "\nError:\n" + getError();
10264
Approvals.verify(combined, options);
10365
}
104-
/**
105-
* Restores the original System.out and System.err streams.
106-
* This method is automatically called when used in a try-with-resources block.
107-
*/
66+
10867
@Override
10968
public void close()
11069
{
111-
// Restore original streams
11270
System.setOut(originalOut);
11371
System.setErr(originalErr);
11472
}

0 commit comments

Comments
 (0)