[TASK] Adjusted exception handler unit test

This commit is contained in:
Jeroen Ketelaar
2019-05-21 23:28:51 -05:00
parent 223171f03f
commit 6d0643cd3b
@@ -1,28 +1,39 @@
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);
public void manualTest() {
FileExceptionHandler handler = new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT);
handler.setIgnored(true);
File[] reports = serverHandler.getReportsDirectory().listFiles();
int reportCount = 0;
if (reports != null) {
reportCount = reports.length;
Exception exception = new NullPointerException("Manual test");
handler.handle(exception);
}
@Test
public void threadHandlerTest() {
FileExceptionHandler handler = new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT);
handler.setIgnored(true);
Thread thread = new Thread() {
@Override
public void run() throws NullPointerException {
throw new NullPointerException("Thread test");
}
};
thread.setUncaughtExceptionHandler(handler);
thread.start();
try {
Thread.sleep(1500);
} catch (InterruptedException e) {
e.printStackTrace();
}
Exception exception = new Exception("Test");
serverHandler.handle(exception);
Assert.assertTrue(serverHandler.getReportsDirectory().listFiles().length > reportCount);
}
}