summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorKeuin <[email protected]>2020-12-24 20:32:08 +0800
committerKeuin <[email protected]>2020-12-24 20:32:08 +0800
commit76284748a605cf1d237fcf4e5196b15254e0c8af (patch)
treedc2e48325862018453ad363c6e481a6a55541925 /src/main/java
parent87d1c3b5ed3cc8b51685e9c979b05b43c053c69f (diff)
add unit test
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/com/keuin/blame/test/TestDatabase.java79
1 files changed, 79 insertions, 0 deletions
diff --git a/src/main/java/com/keuin/blame/test/TestDatabase.java b/src/main/java/com/keuin/blame/test/TestDatabase.java
new file mode 100644
index 0000000..7d817de
--- /dev/null
+++ b/src/main/java/com/keuin/blame/test/TestDatabase.java
@@ -0,0 +1,79 @@
+package com.keuin.blame.test;
+
+import com.keuin.blame.Blame;
+import com.keuin.blame.SubmitWorker;
+import com.keuin.blame.data.LogEntry;
+import com.keuin.blame.data.WorldPos;
+import com.keuin.blame.data.enums.ActionType;
+import com.keuin.blame.data.enums.ObjectType;
+import com.keuin.blame.lookup.LookupCallback;
+import com.keuin.blame.lookup.LookupManager;
+import com.keuin.blame.lookup.TestableFilter;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Objects;
+import java.util.UUID;
+
+import static org.junit.Assert.*;
+
+public class TestDatabase {
+
+ @Before
+ public void init() {
+ Blame.loadConfig();
+ }
+
+ @Test
+ public void testCreateEmptyEntry() {
+ try {
+ SubmitWorker.INSTANCE.submit(LogEntry.EMPTY_ENTRY);
+ Thread.sleep(2000);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testCreateNonEmptyEntry() {
+ try {
+ long timeMillis = 10102020;
+ SubmitWorker.INSTANCE.submit(new LogEntry(
+ timeMillis,
+ "subject-id",
+ UUID.randomUUID(),
+ new WorldPos("world", 1, 2, 3),
+ ActionType.BLOCK_USE,
+ ObjectType.BLOCK,
+ "object-id",
+ new WorldPos("world", 4, 5, 6)
+ ));
+ Thread.sleep(2000);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+
+ @Test
+ public void testLookupAfterInserted() {
+ try {
+ final boolean[] success = {false};
+ SubmitWorker.INSTANCE.submit(LogEntry.EMPTY_ENTRY);
+ Thread.sleep(2000);
+ LookupManager.INSTANCE.lookup(new TestableFilter(), new LookupCallback() {
+ @Override
+ public void onLookupFinishes(Iterable<LogEntry> logEntries) {
+ for (LogEntry entry : logEntries) {
+ System.out.println(entry);
+ assertEquals(entry, LogEntry.EMPTY_ENTRY);
+ success[0] = Objects.equals(entry, LogEntry.EMPTY_ENTRY);
+ }
+ }
+ });
+ Thread.sleep(2000);
+ assertTrue(success[0]);
+ } catch (Exception e) {
+ fail();
+ }
+ }
+} \ No newline at end of file