mirror of
https://github.com/2006-Scape/Parabot.git
synced 2026-07-03 00:37:55 +00:00
[TASK] Adjusted exception handler unit test
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user