Skip to content

Commit 7de2a26

Browse files
committed
Adding ioException test
1 parent 62a4845 commit 7de2a26

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

src/test/java/com/adobe/campaign/tests/logparser/utils/ParseGuardRailsTest.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -242,4 +242,24 @@ public void testExportAnomalyReport_WhenFileExists() throws IOException {
242242
assertThat("Should not have old content",
243243
report.containsKey("test"), is(false));
244244
}
245+
246+
@Test
247+
public void testExportAnomalyReport_WhenIOExceptionOccurs() throws IOException {
248+
// Create some anomalies
249+
ParseGuardRails.HEAP_LIMIT = 1;
250+
ParseGuardRails.HEAP_SIZE_AT_START = -20;
251+
ParseGuardRails.checkMemoryLimits();
252+
253+
// Create a file that will cause an IOException when trying to write
254+
File reportFile = new File(ANOMALY_REPORT_PATH);
255+
reportFile.createNewFile();
256+
reportFile.setReadOnly();
257+
258+
// This should log an error but not throw an exception
259+
ParseGuardRails.exportAnomalyReport();
260+
261+
// Clean up
262+
reportFile.setWritable(true);
263+
reportFile.delete();
264+
}
245265
}

0 commit comments

Comments
 (0)