-
Notifications
You must be signed in to change notification settings - Fork 1
[Tests] Add unit tests for database events, ManagerKey, and improve Pair/Parser coverage #52
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
120 changes: 120 additions & 0 deletions
120
src/test/java/com/diamonddagger590/mccore/event/database/DatabaseTableEventsTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| package com.diamonddagger590.mccore.event.database; | ||
|
|
||
| import org.bukkit.event.HandlerList; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
| import static org.junit.jupiter.api.Assertions.assertNotSame; | ||
| import static org.junit.jupiter.api.Assertions.assertSame; | ||
|
|
||
| class DatabaseTableEventsTest { | ||
|
|
||
| @Test | ||
| @DisplayName("Given PreTablesCreateEvent, when constructed, then getHandlers returns non-null HandlerList") | ||
| void preTablesCreateEvent_getHandlers_returnsNonNull() { | ||
| PreTablesCreateEvent event = new PreTablesCreateEvent(); | ||
| assertNotNull(event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given PreTablesCreateEvent, when getHandlerList called, then returns same instance as getHandlers") | ||
| void preTablesCreateEvent_getHandlerList_returnsSameInstanceAsGetHandlers() { | ||
| PreTablesCreateEvent event = new PreTablesCreateEvent(); | ||
| assertSame(PreTablesCreateEvent.getHandlerList(), event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given two PreTablesCreateEvents, when getHandlers called, then they share the same HandlerList") | ||
| void preTablesCreateEvent_handlerList_isSharedAcrossInstances() { | ||
| PreTablesCreateEvent event1 = new PreTablesCreateEvent(); | ||
| PreTablesCreateEvent event2 = new PreTablesCreateEvent(); | ||
| assertSame(event1.getHandlers(), event2.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given TablesCreatedEvent, when constructed, then getHandlers returns non-null HandlerList") | ||
| void tablesCreatedEvent_getHandlers_returnsNonNull() { | ||
| TablesCreatedEvent event = new TablesCreatedEvent(); | ||
| assertNotNull(event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given TablesCreatedEvent, when getHandlerList called, then returns same instance as getHandlers") | ||
| void tablesCreatedEvent_getHandlerList_returnsSameInstanceAsGetHandlers() { | ||
| TablesCreatedEvent event = new TablesCreatedEvent(); | ||
| assertSame(TablesCreatedEvent.getHandlerList(), event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given two TablesCreatedEvents, when getHandlers called, then they share the same HandlerList") | ||
| void tablesCreatedEvent_handlerList_isSharedAcrossInstances() { | ||
| TablesCreatedEvent event1 = new TablesCreatedEvent(); | ||
| TablesCreatedEvent event2 = new TablesCreatedEvent(); | ||
| assertSame(event1.getHandlers(), event2.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given PreTablesUpdateEvent, when constructed, then getHandlers returns non-null HandlerList") | ||
| void preTablesUpdateEvent_getHandlers_returnsNonNull() { | ||
| PreTablesUpdateEvent event = new PreTablesUpdateEvent(); | ||
| assertNotNull(event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given PreTablesUpdateEvent, when getHandlerList called, then returns same instance as getHandlers") | ||
| void preTablesUpdateEvent_getHandlerList_returnsSameInstanceAsGetHandlers() { | ||
| PreTablesUpdateEvent event = new PreTablesUpdateEvent(); | ||
| assertSame(PreTablesUpdateEvent.getHandlerList(), event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given two PreTablesUpdateEvents, when getHandlers called, then they share the same HandlerList") | ||
| void preTablesUpdateEvent_handlerList_isSharedAcrossInstances() { | ||
| PreTablesUpdateEvent event1 = new PreTablesUpdateEvent(); | ||
| PreTablesUpdateEvent event2 = new PreTablesUpdateEvent(); | ||
| assertSame(event1.getHandlers(), event2.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given TablesUpdatedEvent, when constructed, then getHandlers returns non-null HandlerList") | ||
| void tablesUpdatedEvent_getHandlers_returnsNonNull() { | ||
| TablesUpdatedEvent event = new TablesUpdatedEvent(); | ||
| assertNotNull(event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given TablesUpdatedEvent, when getHandlerList called, then returns same instance as getHandlers") | ||
| void tablesUpdatedEvent_getHandlerList_returnsSameInstanceAsGetHandlers() { | ||
| TablesUpdatedEvent event = new TablesUpdatedEvent(); | ||
| assertSame(TablesUpdatedEvent.getHandlerList(), event.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given two TablesUpdatedEvents, when getHandlers called, then they share the same HandlerList") | ||
| void tablesUpdatedEvent_handlerList_isSharedAcrossInstances() { | ||
| TablesUpdatedEvent event1 = new TablesUpdatedEvent(); | ||
| TablesUpdatedEvent event2 = new TablesUpdatedEvent(); | ||
| assertSame(event1.getHandlers(), event2.getHandlers()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given all four event types, when getHandlerList called, then each type has its own distinct HandlerList") | ||
| void allDatabaseEvents_handlerLists_areDistinctPerType() { | ||
| HandlerList preCreate = PreTablesCreateEvent.getHandlerList(); | ||
| HandlerList created = TablesCreatedEvent.getHandlerList(); | ||
| HandlerList preUpdate = PreTablesUpdateEvent.getHandlerList(); | ||
| HandlerList updated = TablesUpdatedEvent.getHandlerList(); | ||
|
|
||
| assertNotNull(preCreate); | ||
| assertNotNull(created); | ||
| assertNotNull(preUpdate); | ||
| assertNotNull(updated); | ||
| assertNotSame(preCreate, created); | ||
| assertNotSame(preCreate, preUpdate); | ||
| assertNotSame(preCreate, updated); | ||
| assertNotSame(created, preUpdate); | ||
| assertNotSame(created, updated); | ||
| assertNotSame(preUpdate, updated); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
src/test/java/com/diamonddagger590/mccore/registry/manager/ManagerKeyTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package com.diamonddagger590.mccore.registry.manager; | ||
|
|
||
| import com.diamonddagger590.mccore.chat.ChatResponseManager; | ||
| import com.diamonddagger590.mccore.command.CoreCommandManager; | ||
| import com.diamonddagger590.mccore.configuration.ReloadableContentManager; | ||
| import org.junit.jupiter.api.DisplayName; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
|
||
| class ManagerKeyTest { | ||
|
|
||
| @Test | ||
| @DisplayName("Given the COMMAND key constant, when managerClass called, then returns CoreCommandManager class") | ||
| void managerClass_returnsCoreCommandManagerClass_whenKeyIsCommand() { | ||
| assertNotNull(ManagerKey.COMMAND); | ||
| assertEquals(CoreCommandManager.class, ManagerKey.COMMAND.managerClass()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given the RELOADABLE_CONTENT key constant, when managerClass called, then returns ReloadableContentManager class") | ||
| void managerClass_returnsReloadableContentManagerClass_whenKeyIsReloadableContent() { | ||
| assertNotNull(ManagerKey.RELOADABLE_CONTENT); | ||
| assertEquals(ReloadableContentManager.class, ManagerKey.RELOADABLE_CONTENT.managerClass()); | ||
| } | ||
|
|
||
| @Test | ||
| @DisplayName("Given the CHAT_RESPONSE key constant, when managerClass called, then returns ChatResponseManager class") | ||
| void managerClass_returnsChatResponseManagerClass_whenKeyIsChatResponse() { | ||
| assertNotNull(ManagerKey.CHAT_RESPONSE); | ||
| assertEquals(ChatResponseManager.class, ManagerKey.CHAT_RESPONSE.managerClass()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.