Skip to content

Commit bc2de76

Browse files
JayBazuziisidore4dsherwood
committed
- r clean up
Co-Authored-By: Llewellyn Falco <[email protected]> Co-Authored-By: 4dsherwood <[email protected]>
1 parent 45b1ff2 commit bc2de76

File tree

3 files changed

+72
-69
lines changed

3 files changed

+72
-69
lines changed

.windsurf/CodeStyle.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
Remove all comments from the code.
66
If the comment is explaining a block of code, extract the block as a reusable method and give it a name
77
If the comment is explaining a variable, extract one with a name or give an existing variable a better name
8+
Keep comments related to .md snippets (these comments will start with // begin-snippet and end with // end-snippet)
89

910
## Testing Console output
1011

approvaltests-tests/src/test/java/org/approvaltests/scrubbers/DateScrubberTest.java

Lines changed: 71 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
import static org.junit.jupiter.api.Assertions.assertThrows;
1919
import org.approvaltests.reporters.UseReporter;
2020
import org.approvaltests.reporters.AutoApproveReporter;
21-
import org.approvaltests.reporters.BeyondCompareReporter;
2221

2322
public class DateScrubberTest
2423
{
@@ -109,30 +108,27 @@ void testUtilDate()
109108
@Test
110109
void testAddScrubberWithValidRegexAndExample()
111110
{
112-
// Clear any existing custom scrubbers
113-
DateScrubber.clearCustomScrubbers();
114-
// Add a custom scrubber with valid regex and example
115-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}");
116-
// Test that the custom scrubber works
117-
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
118-
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
111+
try
112+
{
113+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}");
114+
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
115+
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
116+
}
117+
finally
118+
{
119+
DateScrubber.clearCustomScrubbers();
120+
}
119121
}
120122
@Test
121123
void testAddScrubberWithInvalidRegex()
122124
{
123-
// Clear any existing custom scrubbers
124-
DateScrubber.clearCustomScrubbers();
125-
// Test that invalid regex throws an exception
126125
assertThrows(IllegalArgumentException.class, () -> {
127126
DateScrubber.addScrubber("2023-Dec-25", "[invalid regex");
128127
});
129128
}
130129
@Test
131130
void testAddScrubberWithRegexThatDoesntMatchExample()
132131
{
133-
// Clear any existing custom scrubbers
134-
DateScrubber.clearCustomScrubbers();
135-
// Test that regex that doesn't match example throws an exception
136132
assertThrows(IllegalArgumentException.class, () -> {
137133
DateScrubber.addScrubber("2023-Dec-25", "\\d{2}-\\d{2}-\\d{4}");
138134
});
@@ -150,70 +146,86 @@ void testAddScrubberDisplaysMessage()
150146
To suppress this message, use:
151147
DateScrubber.addScrubber("<date format>", "<regex>", false)
152148
""";
153-
// Clear any existing custom scrubbers
154-
DateScrubber.clearCustomScrubbers();
155-
// Capture system output to verify message is displayed
156-
try (ConsoleOutput console = new ConsoleOutput())
149+
try
157150
{
158-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}");
159-
console.verifyOutput(new Options().inline(expected));
151+
try (ConsoleOutput console = new ConsoleOutput())
152+
{
153+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}");
154+
console.verifyOutput(new Options().inline(expected));
155+
}
156+
}
157+
finally
158+
{
159+
DateScrubber.clearCustomScrubbers();
160160
}
161161
}
162162
@Test
163163
void testAddScrubberSuppressMessage()
164164
{
165-
// Clear any existing custom scrubbers
166-
DateScrubber.clearCustomScrubbers();
167-
// Capture system output to verify message is NOT displayed
168-
try (ConsoleOutput console = new ConsoleOutput())
165+
try
169166
{
170-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
171-
String output = console.getOutput();
172-
assertEquals("", output);
167+
try (ConsoleOutput console = new ConsoleOutput())
168+
{
169+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
170+
String output = console.getOutput();
171+
assertEquals("", output);
172+
}
173+
}
174+
finally
175+
{
176+
DateScrubber.clearCustomScrubbers();
173177
}
174178
}
175179
@Test
176180
void testCustomScrubberIntegrationWithGetScrubberFor()
177181
{
178-
// Clear any existing custom scrubbers
179-
DateScrubber.clearCustomScrubbers();
180-
// Add a custom scrubber - use a unique pattern that doesn't conflict with built-ins
181-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
182-
// Test that getScrubberFor finds the custom scrubber
183-
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
184-
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
185-
// Test that it works with different examples matching the pattern
186-
assertEquals("[Date1]", scrubber.scrub("2025-Mar-30"));
187-
assertEquals("Meeting on [Date1] at noon", scrubber.scrub("Meeting on 2024-Jan-15 at noon"));
188-
assertEquals("Due date: [Date1]", scrubber.scrub("Due date: 2025-Mar-30"));
182+
try
183+
{
184+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
185+
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
186+
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
187+
assertEquals("[Date1]", scrubber.scrub("2025-Mar-30"));
188+
assertEquals("Meeting on [Date1] at noon", scrubber.scrub("Meeting on 2024-Jan-15 at noon"));
189+
assertEquals("Due date: [Date1]", scrubber.scrub("Due date: 2025-Mar-30"));
190+
}
191+
finally
192+
{
193+
DateScrubber.clearCustomScrubbers();
194+
}
189195
}
190196
@Test
191197
void testClearCustomScrubbers()
192198
{
193-
// Add a custom scrubber
194-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
195-
// Verify it works
196-
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
197-
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
198-
// Clear custom scrubbers
199-
DateScrubber.clearCustomScrubbers();
200-
// Verify the custom scrubber no longer works
201-
assertThrows(Exception.class, () -> {
202-
DateScrubber.getScrubberFor("2024-Jan-15");
203-
});
199+
try
200+
{
201+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
202+
DateScrubber scrubber = DateScrubber.getScrubberFor("2024-Jan-15");
203+
assertEquals("[Date1]", scrubber.scrub("2024-Jan-15"));
204+
DateScrubber.clearCustomScrubbers();
205+
assertThrows(Exception.class, () -> {
206+
DateScrubber.getScrubberFor("2024-Jan-15");
207+
});
208+
}
209+
finally
210+
{
211+
DateScrubber.clearCustomScrubbers();
212+
}
204213
}
205214
@Test
206215
void testMultipleCustomScrubbers()
207216
{
208-
// Clear any existing custom scrubbers
209-
DateScrubber.clearCustomScrubbers();
210-
// Add multiple custom scrubbers
211-
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
212-
DateScrubber.addScrubber("25/Dec/2023", "\\d{2}/[A-Za-z]{3}/\\d{4}", false);
213-
// Test both custom scrubbers work
214-
DateScrubber scrubber1 = DateScrubber.getScrubberFor("2024-Jan-15");
215-
assertEquals("[Date1]", scrubber1.scrub("2024-Jan-15"));
216-
DateScrubber scrubber2 = DateScrubber.getScrubberFor("15/Jan/2024");
217-
assertEquals("[Date1]", scrubber2.scrub("15/Jan/2024"));
217+
try
218+
{
219+
DateScrubber.addScrubber("2023-Dec-25", "\\d{4}-[A-Za-z]{3}-\\d{2}", false);
220+
DateScrubber.addScrubber("25/Dec/2023", "\\d{2}/[A-Za-z]{3}/\\d{4}", false);
221+
DateScrubber scrubber1 = DateScrubber.getScrubberFor("2024-Jan-15");
222+
assertEquals("[Date1]", scrubber1.scrub("2024-Jan-15"));
223+
DateScrubber scrubber2 = DateScrubber.getScrubberFor("15/Jan/2024");
224+
assertEquals("[Date1]", scrubber2.scrub("15/Jan/2024"));
225+
}
226+
finally
227+
{
228+
DateScrubber.clearCustomScrubbers();
229+
}
218230
}
219231
}

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

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ public class ConsoleOutput implements AutoCloseable
1212
private final ByteArrayOutputStream errContent;
1313
private final PrintStream originalOut;
1414
private final PrintStream originalErr;
15-
1615
public ConsoleOutput()
1716
{
1817
originalOut = System.out;
@@ -22,48 +21,39 @@ public ConsoleOutput()
2221
System.setOut(new PrintStream(outContent));
2322
System.setErr(new PrintStream(errContent));
2423
}
25-
2624
public String getOutput()
2725
{
2826
return outContent.toString();
2927
}
30-
3128
public String getError()
3229
{
3330
return errContent.toString();
3431
}
35-
3632
public void verifyOutput()
3733
{
3834
verifyOutput(new Options());
3935
}
40-
4136
public void verifyOutput(Options options)
4237
{
4338
Approvals.verify(getOutput(), options);
4439
}
45-
4640
public void verifyError()
4741
{
4842
Approvals.verify(getError());
4943
}
50-
5144
public void verifyError(Options options)
5245
{
5346
Approvals.verify(getError(), options);
5447
}
55-
5648
public void verifyAll()
5749
{
5850
verifyAll(new Options());
5951
}
60-
6152
public void verifyAll(Options options)
6253
{
6354
String combined = "Output:\n" + getOutput() + "\nError:\n" + getError();
6455
Approvals.verify(combined, options);
6556
}
66-
6757
@Override
6858
public void close()
6959
{

0 commit comments

Comments
 (0)