[TASK] Added Unit test

This commit is contained in:
Jeroen Ketelaar
2019-05-21 23:12:22 -05:00
parent 32ce5c0cda
commit 19bb75f09b
2 changed files with 30 additions and 2 deletions
@@ -46,8 +46,8 @@ public class FileExceptionHandler extends ExceptionHandler {
StringBuilder reportContent = new StringBuilder();
reportContent.append(e.getMessage() + "\n\n");
for (StackTraceElement stackTraceElement : e.getStackTrace()) {
reportContent.append(stackTraceElement);
for (int i = 0; i < e.getStackTrace().length; i++) {
reportContent.append((i > 0 ? " " : "") + e.getStackTrace()[i] + "\n");
}
FileUtil.writeFileContents(report, reportContent.toString());
@@ -0,0 +1,28 @@
package org.parabot;
import org.junit.Assert;
import org.junit.Test;
import org.parabot.environment.handlers.exceptions.ExceptionHandler;
import org.parabot.environment.handlers.exceptions.FileExceptionHandler;
import java.io.File;
public class FileExceptionHandlerTest {
@Test
public void test() {
FileExceptionHandler serverHandler = new FileExceptionHandler(ExceptionHandler.ExceptionType.SERVER);
serverHandler.setIgnored(true);
File[] reports = serverHandler.getReportsDirectory().listFiles();
int reportCount = 0;
if (reports != null) {
reportCount = reports.length;
}
Exception exception = new Exception("Test");
serverHandler.handle(exception);
Assert.assertTrue(serverHandler.getReportsDirectory().listFiles().length > reportCount);
}
}