From 830916f91ca3ae4c193513e9abb2a70ed9c3eb9e Mon Sep 17 00:00:00 2001 From: Adrian Date: Sat, 11 Mar 2023 10:26:15 -0500 Subject: [PATCH] test: implement tests resolves #49 --- common/build.gradle.kts | 14 +++++ .../common/ConfigurationTest.java | 63 +++++++++++++++++++ gradle/libs.versions.toml | 5 ++ velocity/build.gradle.kts | 11 +++- .../velocity/AuthMeUtilsTest.java | 37 +++++++++++ .../authmevelocity/velocity/PairTest.java | 34 ++++++++++ 6 files changed, 163 insertions(+), 1 deletion(-) create mode 100644 common/src/test/java/io/github/_4drian3d/authmevelocity/common/ConfigurationTest.java create mode 100644 velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeUtilsTest.java create mode 100644 velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/PairTest.java diff --git a/common/build.gradle.kts b/common/build.gradle.kts index 8039d8a..5429573 100644 --- a/common/build.gradle.kts +++ b/common/build.gradle.kts @@ -11,6 +11,11 @@ repositories { dependencies { compileOnly(libs.configurate.hocon) compileOnly(libs.libby.core) + + testImplementation(libs.configurate.hocon) + testImplementation(platform("org.junit:junit-bom:5.9.2")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation(libs.assertj) } blossom { @@ -20,3 +25,12 @@ blossom { replaceToken("{configurate}", libs.versions.configurate.get()) replaceToken("{geantyref}", libs.versions.geantyref.get()) } + +tasks { + test { + useJUnitPlatform() + testLogging { + events("passed", "failed") + } + } +} diff --git a/common/src/test/java/io/github/_4drian3d/authmevelocity/common/ConfigurationTest.java b/common/src/test/java/io/github/_4drian3d/authmevelocity/common/ConfigurationTest.java new file mode 100644 index 0000000..c00a244 --- /dev/null +++ b/common/src/test/java/io/github/_4drian3d/authmevelocity/common/ConfigurationTest.java @@ -0,0 +1,63 @@ +/* + * Copyright (C) 2023 AuthMeVelocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github._4drian3d.authmevelocity.common; + +import io.github._4drian3d.authmevelocity.common.configuration.ConfigurationContainer; +import io.github._4drian3d.authmevelocity.common.configuration.PaperConfiguration; +import io.github._4drian3d.authmevelocity.common.configuration.ProxyConfiguration; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; + +import java.nio.file.Path; + +import static org.junit.jupiter.api.Assertions.*; +import static org.assertj.core.api.Assertions.assertThat; + +class ConfigurationTest { + @TempDir + Path path; + + @Test + void testProxyConfigurationCreation() { + final ConfigurationContainer proxyConfiguration = + assertDoesNotThrow( + () -> ConfigurationContainer.load(path, ProxyConfiguration.class) + ); + + assertThat(proxyConfiguration) + .isNotNull() + .extracting(ConfigurationContainer::get) + .isNotNull(); + } + + @Test + void testPaperConfigurationCreation() { + final ConfigurationContainer proxyConfiguration = + assertDoesNotThrow( + () -> ConfigurationContainer.load(path, PaperConfiguration.class) + ); + + assertThat(proxyConfiguration) + .isNotNull() + .extracting(ConfigurationContainer::get) + .isNotNull() + .extracting(PaperConfiguration::debug) + .isEqualTo(false); + + } +} diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 6f376d0..91c4173 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -18,6 +18,9 @@ geantyref = "1.3.13" indra = "3.0.1" runtask = "2.0.1" +# Test versions +assertj = "3.24.2" + [libraries] adventure = { group = "net.kyori", name = "adventure-api", version.ref = "adventure" } @@ -41,6 +44,8 @@ build-indra-common = { module = "net.kyori:indra-common", version.ref = "indra" build-indra-spotless = { module = "net.kyori:indra-licenser-spotless", version.ref = "indra" } plugin-shadow = { group = "com.github.johnrengelman", name = "shadow", version.ref = "shadow" } +assertj = { module = "org.assertj:assertj-core", version.ref = "assertj" } + [plugins] pluginyml-bukkit = { id = "net.minecrell.plugin-yml.bukkit", version.ref = "pluginyml" } diff --git a/velocity/build.gradle.kts b/velocity/build.gradle.kts index 4f2c616..58cac81 100644 --- a/velocity/build.gradle.kts +++ b/velocity/build.gradle.kts @@ -29,6 +29,10 @@ dependencies { implementation(libs.libby.velocity) implementation(libs.bstats.velocity) + + testImplementation(platform("org.junit:junit-bom:5.9.2")) + testImplementation("org.junit.jupiter:junit-jupiter") + testImplementation(libs.assertj) } tasks { @@ -49,5 +53,10 @@ tasks { runVelocity { velocityVersion(libs.versions.velocity.get()) } + test { + useJUnitPlatform() + testLogging { + events("passed", "failed") + } + } } - diff --git a/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeUtilsTest.java b/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeUtilsTest.java new file mode 100644 index 0000000..730ccbb --- /dev/null +++ b/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/AuthMeUtilsTest.java @@ -0,0 +1,37 @@ +/* + * Copyright (C) 2023 AuthMeVelocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github._4drian3d.authmevelocity.velocity; + +import io.github._4drian3d.authmevelocity.velocity.utils.AuthMeUtils; +import org.junit.jupiter.params.ParameterizedTest; +import org.junit.jupiter.params.provider.CsvSource; + +import static org.assertj.core.api.Assertions.assertThat; + +class AuthMeUtilsTest { + @ParameterizedTest + @CsvSource({ + "hola a todos, hola", + "hello there, hello", + "executeforall, executeforall" + }) + void testUtils(String full, String expected) { + assertThat(AuthMeUtils.getFirstArgument(full)) + .isEqualTo(expected); + } +} diff --git a/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/PairTest.java b/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/PairTest.java new file mode 100644 index 0000000..cc6f023 --- /dev/null +++ b/velocity/src/test/java/io/github/_4drian3d/authmevelocity/velocity/PairTest.java @@ -0,0 +1,34 @@ +/* + * Copyright (C) 2023 AuthMeVelocity Contributors + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU 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 General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package io.github._4drian3d.authmevelocity.velocity; + +import io.github._4drian3d.authmevelocity.velocity.utils.Pair; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class PairTest { + @Test + void pairTest() { + Pair pair = Pair.of("survival", null); + assertThat(pair) + .isNotNull() + .extracting(Pair::isEmpty) + .isEqualTo(true); + } +}