mirror of
https://github.com/mcMMO-Dev/mcMMO.git
synced 2024-11-22 13:16:45 +01:00
Added a Unit Test for mc version detection (#4560)
* Added a Unit Test for mc version detection * Merge upstream and update server software string
This commit is contained in:
parent
b79d452a6d
commit
2c849d9cb4
@ -1,13 +1,25 @@
|
|||||||
package com.gmail.nossr50.util.platform;
|
package com.gmail.nossr50.util.platform;
|
||||||
|
|
||||||
|
import java.util.logging.Logger;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
|
import org.bukkit.Bukkit;
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
|
import org.junit.jupiter.params.ParameterizedTest;
|
||||||
|
import org.junit.jupiter.params.provider.Arguments;
|
||||||
|
import org.junit.jupiter.params.provider.MethodSource;
|
||||||
|
import org.mockito.MockedStatic;
|
||||||
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
|
import com.gmail.nossr50.mcMMO;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.*;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
|
|
||||||
class MinecraftGameVersionTest {
|
class MinecraftGameVersionTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testAtLeast() {
|
void testAtLeast() {
|
||||||
// TODO: Remove redundant tests
|
// TODO: Remove redundant tests
|
||||||
MinecraftGameVersion oneEightEight = new MinecraftGameVersion(1, 8, 8);
|
MinecraftGameVersion oneEightEight = new MinecraftGameVersion(1, 8, 8);
|
||||||
MinecraftGameVersion oneSixteenFive = new MinecraftGameVersion(1, 16, 5);
|
MinecraftGameVersion oneSixteenFive = new MinecraftGameVersion(1, 16, 5);
|
||||||
@ -34,7 +46,6 @@ class MinecraftGameVersionTest {
|
|||||||
assertTrue(majorVersionTest.isAtLeast(2, 0, 0));
|
assertTrue(majorVersionTest.isAtLeast(2, 0, 0));
|
||||||
assertTrue(majorVersionTest.isAtLeast(1, 0, 0));
|
assertTrue(majorVersionTest.isAtLeast(1, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
// Test minor version number
|
// Test minor version number
|
||||||
MinecraftGameVersion minorVersionTest = new MinecraftGameVersion(0, 3, 0);
|
MinecraftGameVersion minorVersionTest = new MinecraftGameVersion(0, 3, 0);
|
||||||
|
|
||||||
@ -62,4 +73,59 @@ class MinecraftGameVersionTest {
|
|||||||
assertTrue(patchVersionTest.isAtLeast(0, 0, 4));
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 4));
|
||||||
assertTrue(patchVersionTest.isAtLeast(0, 0, 5));
|
assertTrue(patchVersionTest.isAtLeast(0, 0, 5));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@MethodSource("getGameVersions")
|
||||||
|
@ParameterizedTest(name = "Verify that \"{0}\" is recognized as {1}.{2}.{3}")
|
||||||
|
void testVersionDetection(String gameVersion, int major, int minor, int patch) {
|
||||||
|
/*
|
||||||
|
* The platform manager checks for the type of server software,
|
||||||
|
* we will just simulate some "Spigot" version here, so that the test can
|
||||||
|
* continue successfully.
|
||||||
|
*/
|
||||||
|
String serverSoftwareVersion = "git-Spigot-12345-abcdef (MC: " + major + '.' + minor + '.' + patch + ')';
|
||||||
|
|
||||||
|
// Set up a mock plugin for logging.
|
||||||
|
mcMMO plugin = Mockito.mock(mcMMO.class);
|
||||||
|
Mockito.when(plugin.getName()).thenReturn("mcMMO");
|
||||||
|
Mockito.when(plugin.getLogger()).thenReturn(Logger.getLogger("mcMMO"));
|
||||||
|
mcMMO.p = plugin;
|
||||||
|
|
||||||
|
try (MockedStatic<Bukkit> bukkit = Mockito.mockStatic(Bukkit.class)) {
|
||||||
|
// Inject our own Bukkit versions
|
||||||
|
bukkit.when(() -> Bukkit.getVersion()).thenReturn(serverSoftwareVersion);
|
||||||
|
bukkit.when(() -> Bukkit.getBukkitVersion()).thenReturn(gameVersion);
|
||||||
|
|
||||||
|
PlatformManager manager = new PlatformManager();
|
||||||
|
Platform platform = manager.getPlatform();
|
||||||
|
MinecraftGameVersion minecraftVersion = platform.getGameVersion();
|
||||||
|
|
||||||
|
assertEquals(major, minecraftVersion.getMajorVersion().asInt());
|
||||||
|
assertEquals(minor, minecraftVersion.getMinorVersion().asInt());
|
||||||
|
assertEquals(patch, minecraftVersion.getPatchVersion().asInt());
|
||||||
|
} finally {
|
||||||
|
mcMMO.p = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static @NotNull Stream<Arguments> getGameVersions() {
|
||||||
|
/*
|
||||||
|
* These samples were taken directly from the historical
|
||||||
|
* data of CraftBukkit's pom.xml file:
|
||||||
|
* https://hub.spigotmc.org/stash/projects/SPIGOT/repos/craftbukkit/browse/pom.xml
|
||||||
|
*
|
||||||
|
* We should be safe to assume that forks follow these conventions and do not mess
|
||||||
|
* with this version number (Spigot, Paper and Tuinity do at least).
|
||||||
|
*/
|
||||||
|
return Stream.of(
|
||||||
|
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||||
|
Arguments.of("1.13-R0.2-SNAPSHOT", 1, 13, 0),
|
||||||
|
Arguments.of("1.13.2-R0.1-SNAPSHOT", 1, 13, 2),
|
||||||
|
Arguments.of("1.13-pre7-R0.1-SNAPSHOT", 1, 13, 0),
|
||||||
|
Arguments.of("1.14-pre5-SNAPSHOT", 1, 14, 0),
|
||||||
|
Arguments.of("1.15-R0.1-SNAPSHOT", 1, 15, 0),
|
||||||
|
Arguments.of("1.16.5-R0.1-SNAPSHOT", 1, 16, 5),
|
||||||
|
Arguments.of("1.17-R0.1-SNAPSHOT", 1, 17, 0)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user