Skip to content

Commit

Permalink
feat: add example for a test base class
Browse files Browse the repository at this point in the history
  • Loading branch information
Silthus committed Nov 11, 2021
1 parent 0c0119a commit 436f690
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 21 deletions.
1 change: 0 additions & 1 deletion src/main/java/net/silthus/template/TemplatePlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ public TemplatePlugin(

@Override
public void onEnable() {

saveDefaultConfig();

getServer().getPluginManager().registerEvents(this, this);
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/config.yml
Original file line number Diff line number Diff line change
@@ -1 +1 @@
# add your default configuration properties here
# add your configuration properties here
20 changes: 1 addition & 19 deletions src/test/java/net/silthus/template/TemplatePluginTests.java
Original file line number Diff line number Diff line change
@@ -1,32 +1,14 @@
package net.silthus.template;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import org.bukkit.event.player.PlayerJoinEvent;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

public class TemplatePluginTests {

private ServerMock server;

@BeforeEach
public void setUp() {
server = MockBukkit.mock();
MockBukkit.load(TemplatePlugin.class);
}
public class TemplatePluginTests extends TestBase {

@Test
public void shouldFirePlayerJoinEvent() {

server.addPlayer();

server.getPluginManager().assertEventFired(PlayerJoinEvent.class);
}

@AfterEach
public void tearDown() {
MockBukkit.unmock();
}
}
23 changes: 23 additions & 0 deletions src/test/java/net/silthus/template/TestBase.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package net.silthus.template;

import be.seeseemelk.mockbukkit.MockBukkit;
import be.seeseemelk.mockbukkit.ServerMock;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;

public abstract class TestBase {

protected ServerMock server;
protected TemplatePlugin plugin;

@BeforeEach
public void setUp() {
server = MockBukkit.mock();
plugin = MockBukkit.load(TemplatePlugin.class);
}

@AfterEach
public void tearDown() {
MockBukkit.unmock();
}
}

0 comments on commit 436f690

Please sign in to comment.