OSDN Git Service

Merge pull request #50 from hizumiaoba/release/v4.0.0-Beta
[delesterandomselector/DelesteRandomSelector.git] / src / test / CrashReportTest.java
diff --git a/src/test/CrashReportTest.java b/src/test/CrashReportTest.java
new file mode 100644 (file)
index 0000000..ced1d50
--- /dev/null
@@ -0,0 +1,58 @@
+package test;
+
+import static org.junit.Assert.*;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.Paths;
+import java.util.Arrays;
+import java.util.List;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import com.ranfa.lib.handler.CrashHandler;
+
+public class CrashReportTest {
+       
+       private static final String INPUT_DIR = "Crash-Report";
+       
+       private static List<Path> before;
+       
+       @BeforeClass
+       public static void flushFolder() throws IOException {
+               if(Files.notExists(Paths.get(INPUT_DIR)))
+                       Files.createDirectory(Paths.get(INPUT_DIR));
+               before = Arrays.asList(Files.list(Paths.get(INPUT_DIR)).toArray(Path[]::new));
+       }
+       
+       @Test
+       public void generateSystemReportTest() {
+               CrashHandler handle = new CrashHandler();
+               assertNotNull(handle.outSystemInfo());
+       }
+       
+       @Test
+       public void generateCrashReportTest() {
+               CrashHandler handle = new CrashHandler(new RuntimeException());
+               assertEquals("Unexpected Error", handle.getDescription());
+               assertEquals(Integer.MIN_VALUE, handle.getEstimateExitCode());
+               assertEquals(handle.getThrowable().getClass(), RuntimeException.class);
+       }
+       
+       @AfterClass
+       public static void deleteReport() throws IOException {
+               List<Path> after = Arrays.asList(Files.list(Paths.get(INPUT_DIR)).toArray(Path[]::new));
+               after.removeAll(before);
+               after.stream().forEach(t -> {
+                       try {
+                               Files.delete(t);
+                       } catch (IOException e) {
+                               e.printStackTrace();
+                       }
+               });
+       }
+
+}