mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-07 08:39:12 +00:00
[TASK] Adjusted exception handler unit test
This commit is contained in:
@@ -1,28 +1,39 @@
|
|||||||
package org.parabot;
|
package org.parabot;
|
||||||
|
|
||||||
import org.junit.Assert;
|
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.parabot.environment.handlers.exceptions.ExceptionHandler;
|
import org.parabot.environment.handlers.exceptions.ExceptionHandler;
|
||||||
import org.parabot.environment.handlers.exceptions.FileExceptionHandler;
|
import org.parabot.environment.handlers.exceptions.FileExceptionHandler;
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
public class FileExceptionHandlerTest {
|
public class FileExceptionHandlerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void test() {
|
public void manualTest() {
|
||||||
FileExceptionHandler serverHandler = new FileExceptionHandler(ExceptionHandler.ExceptionType.SERVER);
|
FileExceptionHandler handler = new FileExceptionHandler(ExceptionHandler.ExceptionType.CLIENT);
|
||||||
serverHandler.setIgnored(true);
|
handler.setIgnored(true);
|
||||||
|
|
||||||
File[] reports = serverHandler.getReportsDirectory().listFiles();
|
Exception exception = new NullPointerException("Manual test");
|
||||||
int reportCount = 0;
|
handler.handle(exception);
|
||||||
if (reports != null) {
|
}
|
||||||
reportCount = reports.length;
|
|
||||||
|
@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);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user