From 76284748a605cf1d237fcf4e5196b15254e0c8af Mon Sep 17 00:00:00 2001 From: Keuin Date: Thu, 24 Dec 2020 20:32:08 +0800 Subject: add unit test --- .../java/com/keuin/blame/test/TestDatabase.java | 79 ++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 src/main/java/com/keuin/blame/test/TestDatabase.java (limited to 'src/main') 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 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 -- cgit v1.2.3