Testing™ with MockBukkit
Dieser Commit ist enthalten in:
Ursprung
ac499b32b8
Commit
53673c42e5
27
build.gradle
27
build.gradle
@ -48,18 +48,6 @@ targetCompatibility = JavaVersion.VERSION_17
|
|||||||
|
|
||||||
mainClassName = ''
|
mainClassName = ''
|
||||||
|
|
||||||
sourceSets {
|
|
||||||
main {
|
|
||||||
java {
|
|
||||||
srcDirs = ['src/']
|
|
||||||
}
|
|
||||||
resources {
|
|
||||||
srcDirs = ['src/']
|
|
||||||
exclude '**/*.java', '**/*.kt'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
repositories {
|
repositories {
|
||||||
mavenCentral()
|
mavenCentral()
|
||||||
|
|
||||||
@ -70,6 +58,9 @@ repositories {
|
|||||||
maven {
|
maven {
|
||||||
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
|
||||||
}
|
}
|
||||||
|
maven {
|
||||||
|
url = uri('https://repo.papermc.io/repository/maven-public/')
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
@ -86,4 +77,16 @@ dependencies {
|
|||||||
compileOnly swdep("Spigot-1.19")
|
compileOnly swdep("Spigot-1.19")
|
||||||
compileOnly swdep("WorldEdit-1.15")
|
compileOnly swdep("WorldEdit-1.15")
|
||||||
compileOnly swdep("SpigotCore")
|
compileOnly swdep("SpigotCore")
|
||||||
|
|
||||||
|
testImplementation swdep("SpigotCore")
|
||||||
|
testImplementation(platform('org.junit:junit-bom:5.10.0'))
|
||||||
|
testImplementation('org.junit.jupiter:junit-jupiter')
|
||||||
|
testImplementation 'com.github.seeseemelk:MockBukkit-v1.20:3.9.0'
|
||||||
|
}
|
||||||
|
|
||||||
|
test {
|
||||||
|
useJUnitPlatform()
|
||||||
|
testLogging {
|
||||||
|
events "passed", "skipped", "failed"
|
||||||
|
}
|
||||||
}
|
}
|
@ -27,12 +27,16 @@ import de.steamwar.towerrun.listener.IngameListener;
|
|||||||
import de.steamwar.towerrun.listener.LobbyListener;
|
import de.steamwar.towerrun.listener.LobbyListener;
|
||||||
import de.steamwar.towerrun.listener.NotLobbyListener;
|
import de.steamwar.towerrun.listener.NotLobbyListener;
|
||||||
import lombok.Getter;
|
import lombok.Getter;
|
||||||
|
import org.bukkit.plugin.PluginDescriptionFile;
|
||||||
import org.bukkit.plugin.java.JavaPlugin;
|
import org.bukkit.plugin.java.JavaPlugin;
|
||||||
|
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||||
import org.bukkit.plugin.java.annotation.dependency.Dependency;
|
import org.bukkit.plugin.java.annotation.dependency.Dependency;
|
||||||
import org.bukkit.plugin.java.annotation.plugin.Description;
|
import org.bukkit.plugin.java.annotation.plugin.Description;
|
||||||
import org.bukkit.plugin.java.annotation.plugin.Plugin;
|
import org.bukkit.plugin.java.annotation.plugin.Plugin;
|
||||||
import org.bukkit.plugin.java.annotation.plugin.author.Author;
|
import org.bukkit.plugin.java.annotation.plugin.author.Author;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
@Plugin(name = "TowerRun", version = "0.0.1")
|
@Plugin(name = "TowerRun", version = "0.0.1")
|
||||||
@Dependency(value = "SpigotCore")
|
@Dependency(value = "SpigotCore")
|
||||||
@Dependency(value = "WorldEdit")
|
@Dependency(value = "WorldEdit")
|
||||||
@ -45,18 +49,20 @@ public class TowerRun extends JavaPlugin {
|
|||||||
private static TowerRun instance;
|
private static TowerRun instance;
|
||||||
@Getter
|
@Getter
|
||||||
private static Message message;
|
private static Message message;
|
||||||
|
@Getter
|
||||||
|
private static LobbyCountdown lobbyCountdown;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnable() {
|
public void onEnable() {
|
||||||
instance = this;
|
instance = this;
|
||||||
message = new Message("TowerRun", getClassLoader());
|
message = new Message("TowerRun", getClassLoader());
|
||||||
|
saveDefaultConfig();
|
||||||
new LobbyListener();
|
new LobbyListener();
|
||||||
new IngameListener();
|
new IngameListener();
|
||||||
new GlobalListener();
|
new GlobalListener();
|
||||||
new LobbyListener();
|
new LobbyListener();
|
||||||
new NotLobbyListener();
|
new NotLobbyListener();
|
||||||
new LobbyCountdown();
|
lobbyCountdown = new LobbyCountdown();
|
||||||
new EndCountdown();
|
new EndCountdown();
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -24,6 +24,7 @@ import de.steamwar.towerrun.config.Config;
|
|||||||
import de.steamwar.towerrun.game.TowerRunGame;
|
import de.steamwar.towerrun.game.TowerRunGame;
|
||||||
import de.steamwar.towerrun.state.GameStateToggleListener;
|
import de.steamwar.towerrun.state.GameStateToggleListener;
|
||||||
import de.steamwar.towerrun.state.GameStates;
|
import de.steamwar.towerrun.state.GameStates;
|
||||||
|
import lombok.Getter;
|
||||||
import net.md_5.bungee.api.ChatMessageType;
|
import net.md_5.bungee.api.ChatMessageType;
|
||||||
import net.md_5.bungee.api.chat.TextComponent;
|
import net.md_5.bungee.api.chat.TextComponent;
|
||||||
import org.bukkit.Bukkit;
|
import org.bukkit.Bukkit;
|
||||||
@ -31,6 +32,7 @@ import org.bukkit.scheduler.BukkitTask;
|
|||||||
|
|
||||||
import java.util.EnumSet;
|
import java.util.EnumSet;
|
||||||
|
|
||||||
|
@Getter
|
||||||
public class LobbyCountdown extends GameStateToggleListener {
|
public class LobbyCountdown extends GameStateToggleListener {
|
||||||
|
|
||||||
private BukkitTask task;
|
private BukkitTask task;
|
@ -20,7 +20,6 @@
|
|||||||
package de.steamwar.towerrun.game;
|
package de.steamwar.towerrun.game;
|
||||||
|
|
||||||
import de.steamwar.towerrun.config.WorldConfig;
|
import de.steamwar.towerrun.config.WorldConfig;
|
||||||
import lombok.ToString;
|
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.util.Vector;
|
import org.bukkit.util.Vector;
|
||||||
|
|
||||||
@ -47,11 +46,4 @@ public record TowerRunPlayer(Player player) {
|
|||||||
player.teleport(WorldConfig.SPAWN);
|
player.teleport(WorldConfig.SPAWN);
|
||||||
player.setVelocity(new Vector(0, 0, 0));
|
player.setVelocity(new Vector(0, 0, 0));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "TowerRunPlayer{" +
|
|
||||||
"player=" + player.getName() +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
}
|
}
|
6
src/main/resources/config.yml
Normale Datei
6
src/main/resources/config.yml
Normale Datei
@ -0,0 +1,6 @@
|
|||||||
|
minPlayers: 2
|
||||||
|
lobbyTimer: 30
|
||||||
|
|
||||||
|
destroyable:
|
||||||
|
- WHITE_WOOL
|
||||||
|
- FIRE
|
33
src/main/resources/world.yml
Normale Datei
33
src/main/resources/world.yml
Normale Datei
@ -0,0 +1,33 @@
|
|||||||
|
tower:
|
||||||
|
regions:
|
||||||
|
1:
|
||||||
|
minX: 61
|
||||||
|
maxX: 128
|
||||||
|
minZ: 308
|
||||||
|
maxZ: 340
|
||||||
|
2:
|
||||||
|
minX: 97
|
||||||
|
maxX: 128
|
||||||
|
minZ: 273
|
||||||
|
maxZ: 340
|
||||||
|
escapeHeight: 12
|
||||||
|
spawn:
|
||||||
|
x: 116
|
||||||
|
y: 167
|
||||||
|
z: 297
|
||||||
|
yaw: 0.0
|
||||||
|
pitch: 0.0
|
||||||
|
doors:
|
||||||
|
1:
|
||||||
|
x: 117
|
||||||
|
y: 167
|
||||||
|
z: 309
|
||||||
|
2:
|
||||||
|
x: 116
|
||||||
|
y: 167
|
||||||
|
z: 309
|
||||||
|
lavaY: 220
|
||||||
|
|
||||||
|
winconditions:
|
||||||
|
- LAST_REMAINING
|
||||||
|
- LAST_OUTSIDE
|
77
src/test/java/de/steamwar/towerrun/TowerRunTests.java
Normale Datei
77
src/test/java/de/steamwar/towerrun/TowerRunTests.java
Normale Datei
@ -0,0 +1,77 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.towerrun;
|
||||||
|
import be.seeseemelk.mockbukkit.MockBukkit;
|
||||||
|
import be.seeseemelk.mockbukkit.ServerMock;
|
||||||
|
import be.seeseemelk.mockbukkit.WorldMock;
|
||||||
|
import be.seeseemelk.mockbukkit.entity.PlayerMock;
|
||||||
|
import de.steamwar.towerrun.mocks.WorldMockWithFolder;
|
||||||
|
import org.bukkit.GameMode;
|
||||||
|
import org.bukkit.Location;
|
||||||
|
import org.junit.jupiter.api.AfterEach;
|
||||||
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
|
class TowerRunTests {
|
||||||
|
|
||||||
|
private ServerMock server;
|
||||||
|
private WorldMock world;
|
||||||
|
private TowerRun plugin;
|
||||||
|
|
||||||
|
@BeforeEach
|
||||||
|
public void setup() {
|
||||||
|
server = MockBukkit.mock();
|
||||||
|
world = new WorldMockWithFolder();
|
||||||
|
server.addWorld(world);
|
||||||
|
plugin = MockBukkit.load(TowerRun.class);
|
||||||
|
}
|
||||||
|
|
||||||
|
@AfterEach
|
||||||
|
public void teardown() {
|
||||||
|
MockBukkit.unmock();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void playerJoin() {
|
||||||
|
PlayerMock playerMock = server.addPlayer();
|
||||||
|
playerMock.assertGameMode(GameMode.SURVIVAL);
|
||||||
|
playerMock.assertTeleported(new Location(playerMock.getWorld(), 116, 167, 297), 2);
|
||||||
|
playerMock.disconnect();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void lobbyCountdown() {
|
||||||
|
server.getScheduler().performOneTick();
|
||||||
|
PlayerMock playerOne = server.addPlayer();
|
||||||
|
server.getScheduler().performTicks(20);
|
||||||
|
assertEquals(30, TowerRun.getLobbyCountdown().getTimer());
|
||||||
|
PlayerMock playerTwo = server.addPlayer();
|
||||||
|
server.getScheduler().performTicks(20);
|
||||||
|
assertEquals(29, TowerRun.getLobbyCountdown().getTimer());
|
||||||
|
server.getScheduler().performTicks(19 * 20);
|
||||||
|
assertEquals(10, TowerRun.getLobbyCountdown().getTimer());
|
||||||
|
playerTwo.disconnect();
|
||||||
|
server.getScheduler().performTicks(20);
|
||||||
|
assertEquals(30, TowerRun.getLobbyCountdown().getTimer());
|
||||||
|
playerOne.disconnect();
|
||||||
|
}
|
||||||
|
}
|
32
src/test/java/de/steamwar/towerrun/mocks/WorldMockWithFolder.java
Normale Datei
32
src/test/java/de/steamwar/towerrun/mocks/WorldMockWithFolder.java
Normale Datei
@ -0,0 +1,32 @@
|
|||||||
|
/*
|
||||||
|
* This file is a part of the SteamWar software.
|
||||||
|
*
|
||||||
|
* Copyright (C) 2023 SteamWar.de-Serverteam
|
||||||
|
*
|
||||||
|
* This program is free software: you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU Affero General Public License as published by
|
||||||
|
* the Free Software Foundation, either version 3 of the License, or
|
||||||
|
* (at your option) any later version.
|
||||||
|
*
|
||||||
|
* This program is distributed in the hope that it will be useful,
|
||||||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||||
|
* GNU Affero General Public License for more details.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU Affero General Public License
|
||||||
|
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package de.steamwar.towerrun.mocks;
|
||||||
|
|
||||||
|
import be.seeseemelk.mockbukkit.WorldMock;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class WorldMockWithFolder extends WorldMock {
|
||||||
|
@Override
|
||||||
|
public @NotNull File getWorldFolder() {
|
||||||
|
return new File("src/test/resources/world");
|
||||||
|
}
|
||||||
|
}
|
33
src/test/resources/world/config.yml
Normale Datei
33
src/test/resources/world/config.yml
Normale Datei
@ -0,0 +1,33 @@
|
|||||||
|
tower:
|
||||||
|
regions:
|
||||||
|
1:
|
||||||
|
minX: 61
|
||||||
|
maxX: 128
|
||||||
|
minZ: 308
|
||||||
|
maxZ: 340
|
||||||
|
2:
|
||||||
|
minX: 97
|
||||||
|
maxX: 128
|
||||||
|
minZ: 273
|
||||||
|
maxZ: 340
|
||||||
|
escapeHeight: 12
|
||||||
|
spawn:
|
||||||
|
x: 116
|
||||||
|
y: 167
|
||||||
|
z: 297
|
||||||
|
yaw: 0.0
|
||||||
|
pitch: 0.0
|
||||||
|
doors:
|
||||||
|
1:
|
||||||
|
x: 117
|
||||||
|
y: 167
|
||||||
|
z: 309
|
||||||
|
2:
|
||||||
|
x: 116
|
||||||
|
y: 167
|
||||||
|
z: 309
|
||||||
|
lavaY: 220
|
||||||
|
|
||||||
|
winconditions:
|
||||||
|
- LAST_REMAINING
|
||||||
|
- LAST_OUTSIDE
|
In neuem Issue referenzieren
Einen Benutzer sperren