diff --git a/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java b/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java index ef6771a10..aee4ff1fd 100644 --- a/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java +++ b/src/test/java/org/bukkit/craftbukkit/profile/PlayerProfileTest.java @@ -12,6 +12,7 @@ import org.bukkit.configuration.file.YamlConfiguration; import org.bukkit.configuration.serialization.ConfigurationSerialization; import org.bukkit.profile.PlayerProfile; import org.bukkit.profile.PlayerTextures; +import org.bukkit.support.condition.EnableIfMojangServerAvailable; import org.junit.jupiter.api.Test; public class PlayerProfileTest { @@ -60,6 +61,7 @@ public class PlayerProfileTest { } @Test + @EnableIfMojangServerAvailable public void testProvidedValues() { Property property = new Property(CraftPlayerTextures.PROPERTY_NAME, VALUE, SIGNATURE); assertTrue(CraftProfileProperty.hasValidSignature(property), "Invalid test property signature, has the public key changed?"); @@ -117,6 +119,7 @@ public class PlayerProfileTest { } @Test + @EnableIfMojangServerAvailable public void testBuildGameProfile() { CraftPlayerProfile profile = buildPlayerProfile(); GameProfile gameProfile = profile.buildGameProfile(); @@ -140,6 +143,7 @@ public class PlayerProfileTest { } @Test + @EnableIfMojangServerAvailable public void testSignatureValidation() { CraftPlayerProfile profile = buildPlayerProfile(); assertTrue(profile.getTextures().isSigned(), "Signature is not valid"); diff --git a/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailable.java b/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailable.java new file mode 100644 index 000000000..7486c5d6e --- /dev/null +++ b/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailable.java @@ -0,0 +1,15 @@ +package org.bukkit.support.condition; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; + +@Target({ElementType.TYPE, ElementType.METHOD}) +@Retention(RetentionPolicy.RUNTIME) +@Documented +@ExtendWith(EnableIfMojangServerAvailableCondition.class) +public @interface EnableIfMojangServerAvailable { +} diff --git a/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailableCondition.java b/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailableCondition.java new file mode 100644 index 000000000..89819cbbf --- /dev/null +++ b/src/test/java/org/bukkit/support/condition/EnableIfMojangServerAvailableCondition.java @@ -0,0 +1,26 @@ +package org.bukkit.support.condition; + +import com.mojang.authlib.yggdrasil.YggdrasilEnvironment; +import java.net.InetAddress; +import java.util.concurrent.TimeUnit; +import org.junit.jupiter.api.extension.ConditionEvaluationResult; +import org.junit.jupiter.api.extension.ExecutionCondition; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class EnableIfMojangServerAvailableCondition implements ExecutionCondition { + + @Override + public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext extensionContext) { + try { + InetAddress address = InetAddress.getByName(YggdrasilEnvironment.PROD.getEnvironment().servicesHost()); + + if (!address.isReachable((int) TimeUnit.SECONDS.toMillis(1))) { + return ConditionEvaluationResult.disabled("Mojang server is not available"); + } + + return ConditionEvaluationResult.enabled("Mojang server available"); + } catch (Exception e) { + return ConditionEvaluationResult.disabled(e.getMessage()); + } + } +}