WIP: Tests? #4

Geschlossen
Chaoscaot möchte 1 Commits von tests nach master mergen
27 geänderte Dateien mit 206 neuen und 22 gelöschten Zeilen

Datei anzeigen

@ -48,18 +48,6 @@ targetCompatibility = JavaVersion.VERSION_17
mainClassName = ''
sourceSets {
main {
java {
srcDirs = ['src/']
}
resources {
srcDirs = ['src/']
exclude '**/*.java', '**/*.kt'
}
}
}
repositories {
mavenCentral()
@ -70,6 +58,9 @@ repositories {
maven {
url = uri('https://hub.spigotmc.org/nexus/content/repositories/snapshots/')
}
maven {
url = uri('https://repo.papermc.io/repository/maven-public/')
}
}
dependencies {
@ -86,4 +77,16 @@ dependencies {
compileOnly swdep("Spigot-1.19")
compileOnly swdep("WorldEdit-1.15")
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"
}
}

Datei anzeigen

@ -27,12 +27,16 @@ import de.steamwar.towerrun.listener.IngameListener;
import de.steamwar.towerrun.listener.LobbyListener;
import de.steamwar.towerrun.listener.NotLobbyListener;
import lombok.Getter;
import org.bukkit.plugin.PluginDescriptionFile;
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.plugin.Description;
import org.bukkit.plugin.java.annotation.plugin.Plugin;
import org.bukkit.plugin.java.annotation.plugin.author.Author;
import java.io.File;
@Plugin(name = "TowerRun", version = "0.0.1")
@Dependency(value = "SpigotCore")
@Dependency(value = "WorldEdit")
@ -45,18 +49,20 @@ public class TowerRun extends JavaPlugin {
private static TowerRun instance;
@Getter
private static Message message;
@Getter
private static LobbyCountdown lobbyCountdown;
@Override
public void onEnable() {
instance = this;
message = new Message("TowerRun", getClassLoader());
saveDefaultConfig();
new LobbyListener();
new IngameListener();
new GlobalListener();
new LobbyListener();
new NotLobbyListener();
new LobbyCountdown();
lobbyCountdown = new LobbyCountdown();
new EndCountdown();
}
}

Datei anzeigen

@ -24,6 +24,7 @@ import de.steamwar.towerrun.config.Config;
import de.steamwar.towerrun.game.TowerRunGame;
import de.steamwar.towerrun.state.GameStateToggleListener;
import de.steamwar.towerrun.state.GameStates;
import lombok.Getter;
import net.md_5.bungee.api.ChatMessageType;
import net.md_5.bungee.api.chat.TextComponent;
import org.bukkit.Bukkit;
@ -31,6 +32,7 @@ import org.bukkit.scheduler.BukkitTask;
import java.util.EnumSet;
@Getter
public class LobbyCountdown extends GameStateToggleListener {
private BukkitTask task;

Datei anzeigen

@ -20,7 +20,6 @@
package de.steamwar.towerrun.game;
import de.steamwar.towerrun.config.WorldConfig;
import lombok.ToString;
import org.bukkit.entity.Player;
import org.bukkit.util.Vector;
@ -47,11 +46,4 @@ public record TowerRunPlayer(Player player) {
player.teleport(WorldConfig.SPAWN);
player.setVelocity(new Vector(0, 0, 0));
}
@Override
public String toString() {
return "TowerRunPlayer{" +
"player=" + player.getName() +
'}';
}
}

Datei anzeigen

@ -0,0 +1,6 @@
minPlayers: 2
lobbyTimer: 30
destroyable:
- WHITE_WOOL
- FIRE

33
src/main/resources/world.yml Normale Datei
Datei anzeigen

@ -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

Datei anzeigen

@ -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();
}
}

Datei anzeigen

@ -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");
}
}

Datei anzeigen

@ -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