mirror of
https://github.com/GeyserMC/Geyser.git
synced 2024-08-14 23:57:35 +00:00
Simplify publish logic and move to GitHub Actions (#3579)
Co-authored-by: Tim203 <mctim203@gmail.com> Co-authored-by: rtm516 <ryantmilner@hotmail.co.uk>
This commit is contained in:
parent
50104c95ec
commit
a72e49527d
10 changed files with 135 additions and 146 deletions
|
@ -27,18 +27,20 @@ package org.geysermc.geyser.network.translators.chat;
|
|||
|
||||
import com.github.steveice10.mc.protocol.data.DefaultComponentSerializer;
|
||||
import org.geysermc.geyser.translator.text.MessageTranslator;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class MessageTranslatorTest {
|
||||
|
||||
private Map<String, String> messages = new HashMap<>();
|
||||
|
||||
@Before
|
||||
@BeforeAll
|
||||
public void setUp() throws Exception {
|
||||
messages.put("{\"text\":\"\",\"extra\":[{\"text\":\"DoctorMad9952 joined the game\",\"color\":\"yellow\"}]}",
|
||||
"§r§eDoctorMad9952 joined the game");
|
||||
|
@ -70,27 +72,27 @@ public class MessageTranslatorTest {
|
|||
public void convertMessage() {
|
||||
for (Map.Entry<String, String> entry : messages.entrySet()) {
|
||||
String bedrockMessage = MessageTranslator.convertMessage(entry.getKey(), "en_US");
|
||||
Assert.assertEquals("Translation of messages is incorrect", entry.getValue(), bedrockMessage);
|
||||
Assertions.assertEquals(entry.getValue(), bedrockMessage, "Translation of messages is incorrect");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertMessageLenient() {
|
||||
Assert.assertEquals("All newline message is not handled properly", "\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n"));
|
||||
Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertMessageLenient(""));
|
||||
Assert.assertEquals("Reset before message is not handled properly", "§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector"));
|
||||
Assert.assertEquals("Unimplemented formatting chars not stripped", "Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline"));
|
||||
Assertions.assertEquals("\n\n\n\n", MessageTranslator.convertMessageLenient("\n\n\n\n"), "All newline message is not handled properly");
|
||||
Assertions.assertEquals("", MessageTranslator.convertMessageLenient(""), "Empty message is not handled properly");
|
||||
Assertions.assertEquals("§r§eGame Selector", MessageTranslator.convertMessageLenient("§r§eGame Selector"), "Reset before message is not handled properly");
|
||||
Assertions.assertEquals("Bold Underline", MessageTranslator.convertMessageLenient("§m§nBold Underline"), "Unimplemented formatting chars not stripped");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void convertToPlainText() {
|
||||
Assert.assertEquals("JSON message is not handled properly", "Many colors here", MessageTranslator.convertToPlainText("{\"extra\":[{\"color\":\"red\",\"text\":\"M\"},{\"color\":\"gold\",\"text\":\"a\"},{\"color\":\"yellow\",\"text\":\"n\"},{\"color\":\"green\",\"text\":\"y \"},{\"color\":\"aqua\",\"text\":\"c\"},{\"color\":\"dark_purple\",\"text\":\"o\"},{\"color\":\"red\",\"text\":\"l\"},{\"color\":\"gold\",\"text\":\"o\"},{\"color\":\"yellow\",\"text\":\"r\"},{\"color\":\"green\",\"text\":\"s \"},{\"color\":\"aqua\",\"text\":\"h\"},{\"color\":\"dark_purple\",\"text\":\"e\"},{\"color\":\"red\",\"text\":\"r\"},{\"color\":\"gold\",\"text\":\"e\"}],\"text\":\"\"}", "en_US"));
|
||||
Assert.assertEquals("Legacy formatted message is not handled properly (Colors)", "Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e"));
|
||||
Assert.assertEquals("Legacy formatted message is not handled properly (Colors)", "Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e", "en_US"));
|
||||
Assert.assertEquals("Legacy formatted message is not handled properly (Style)", "Obf Bold Strikethrough Underline Italic Reset", MessageTranslator.convertToPlainText("§kObf §lBold §mStrikethrough §nUnderline §oItalic §rReset", "en_US"));
|
||||
Assert.assertEquals("Valid lenient JSON is not handled properly", "Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US"));
|
||||
Assert.assertEquals("Empty message is not handled properly", "", MessageTranslator.convertToPlainText("", "en_US"));
|
||||
Assert.assertEquals("Whitespace is not preserved", " ", MessageTranslator.convertToPlainText(" ", "en_US"));
|
||||
Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("{\"extra\":[{\"color\":\"red\",\"text\":\"M\"},{\"color\":\"gold\",\"text\":\"a\"},{\"color\":\"yellow\",\"text\":\"n\"},{\"color\":\"green\",\"text\":\"y \"},{\"color\":\"aqua\",\"text\":\"c\"},{\"color\":\"dark_purple\",\"text\":\"o\"},{\"color\":\"red\",\"text\":\"l\"},{\"color\":\"gold\",\"text\":\"o\"},{\"color\":\"yellow\",\"text\":\"r\"},{\"color\":\"green\",\"text\":\"s \"},{\"color\":\"aqua\",\"text\":\"h\"},{\"color\":\"dark_purple\",\"text\":\"e\"},{\"color\":\"red\",\"text\":\"r\"},{\"color\":\"gold\",\"text\":\"e\"}],\"text\":\"\"}", "en_US"), "JSON message is not handled properly");
|
||||
Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e"), "Legacy formatted message is not handled properly (Colors)");
|
||||
Assertions.assertEquals("Many colors here", MessageTranslator.convertToPlainText("§cM§6a§en§ay §bc§5o§cl§6o§er§as §bh§5e§cr§6e", "en_US"), "Legacy formatted message is not handled properly (Colors)");
|
||||
Assertions.assertEquals("Obf Bold Strikethrough Underline Italic Reset", MessageTranslator.convertToPlainText("§kObf §lBold §mStrikethrough §nUnderline §oItalic §rReset", "en_US"), "Legacy formatted message is not handled properly (Style)");
|
||||
Assertions.assertEquals("Strange", MessageTranslator.convertToPlainText("§rStrange", "en_US"), "Valid lenient JSON is not handled properly");
|
||||
Assertions.assertEquals("", MessageTranslator.convertToPlainText("", "en_US"), "Empty message is not handled properly");
|
||||
Assertions.assertEquals(" ", MessageTranslator.convertToPlainText(" ", "en_US"), "Whitespace is not preserved");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -36,20 +36,22 @@ import org.geysermc.geyser.api.item.custom.CustomItemOptions;
|
|||
import org.geysermc.geyser.api.util.TriState;
|
||||
import org.geysermc.geyser.item.GeyserCustomItemOptions;
|
||||
import org.geysermc.geyser.registry.type.ItemMapping;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.OptionalInt;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class CustomItemsTest {
|
||||
private ItemMapping testMappingWithDamage;
|
||||
private Object2IntMap<CompoundTag> tagToCustomItemWithDamage;
|
||||
private ItemMapping testMappingWithNoDamage;
|
||||
private Object2IntMap<CompoundTag> tagToCustomItemWithNoDamage;
|
||||
|
||||
@Before
|
||||
@BeforeAll
|
||||
public void setup() {
|
||||
CustomItemOptions a = new GeyserCustomItemOptions(TriState.TRUE, OptionalInt.of(2), OptionalInt.empty());
|
||||
CustomItemOptions b = new GeyserCustomItemOptions(TriState.FALSE, OptionalInt.of(5), OptionalInt.empty());
|
||||
|
@ -147,12 +149,12 @@ public class CustomItemsTest {
|
|||
public void testCustomItems() {
|
||||
for (Object2IntMap.Entry<CompoundTag> entry : this.tagToCustomItemWithDamage.object2IntEntrySet()) {
|
||||
int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithDamage);
|
||||
Assert.assertEquals(entry.getKey() + " did not produce the correct custom item", entry.getIntValue(), id);
|
||||
Assertions.assertEquals(entry.getIntValue(), id, entry.getKey() + " did not produce the correct custom item");
|
||||
}
|
||||
|
||||
for (Object2IntMap.Entry<CompoundTag> entry : this.tagToCustomItemWithNoDamage.object2IntEntrySet()) {
|
||||
int id = CustomItemTranslator.getCustomItem(entry.getKey(), this.testMappingWithNoDamage);
|
||||
Assert.assertEquals(entry.getKey() + " did not produce the correct custom item", entry.getIntValue(), id);
|
||||
Assertions.assertEquals(entry.getIntValue(), id, entry.getKey() + " did not produce the correct custom item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,9 +25,11 @@
|
|||
|
||||
package org.geysermc.geyser.util.collection;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.TestInstance;
|
||||
|
||||
@TestInstance(TestInstance.Lifecycle.PER_CLASS)
|
||||
public class GeyserCollectionsTest {
|
||||
private final byte[] bytes = new byte[] {(byte) 5, (byte) 4, (byte) 3, (byte) 2, (byte) 2, (byte) 1};
|
||||
private final boolean[] booleans = new boolean[] {true, false, false, true};
|
||||
|
@ -51,35 +53,35 @@ public class GeyserCollectionsTest {
|
|||
int lastKey = index;
|
||||
|
||||
// Easy, understandable out-of-bounds checks
|
||||
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey));
|
||||
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1));
|
||||
Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
|
||||
Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!");
|
||||
|
||||
// Ensure the first and last values do not throw an exception on get, and test getOrDefault
|
||||
map.get(start - 1);
|
||||
map.get(lastKey);
|
||||
Assert.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE);
|
||||
Assert.assertEquals(map.getOrDefault(lastKey, Byte.MAX_VALUE), Byte.MAX_VALUE);
|
||||
Assert.assertEquals(map.getOrDefault(lastKey, Byte.MIN_VALUE), Byte.MIN_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(start - 1, Byte.MAX_VALUE), Byte.MAX_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(lastKey, Byte.MAX_VALUE), Byte.MAX_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(lastKey, Byte.MIN_VALUE), Byte.MIN_VALUE);
|
||||
|
||||
Assert.assertEquals(map.size(), bytes.length);
|
||||
Assertions.assertEquals(map.size(), bytes.length);
|
||||
|
||||
for (int i = start; i < bytes.length; i++) {
|
||||
Assert.assertTrue(map.containsKey(i));
|
||||
Assert.assertEquals(map.get(i), bytes[i - start]);
|
||||
Assertions.assertTrue(map.containsKey(i));
|
||||
Assertions.assertEquals(map.get(i), bytes[i - start]);
|
||||
}
|
||||
|
||||
for (int i = start - 1; i >= (start - 6); i--) {
|
||||
// Lower than expected check
|
||||
Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start);
|
||||
}
|
||||
|
||||
for (int i = bytes.length + start; i < bytes.length + 5 + start; i++) {
|
||||
// Higher than expected check
|
||||
Assert.assertFalse(i + " is in a map that ends with " + (start + bytes.length), map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + bytes.length));
|
||||
}
|
||||
|
||||
for (byte b : bytes) {
|
||||
Assert.assertTrue(map.containsValue(b));
|
||||
Assertions.assertTrue(map.containsValue(b));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,33 +101,33 @@ public class GeyserCollectionsTest {
|
|||
int lastKey = index;
|
||||
|
||||
// Easy, understandable out-of-bounds checks
|
||||
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey));
|
||||
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1));
|
||||
Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
|
||||
Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!");
|
||||
|
||||
// Ensure the first and last values do not throw an exception on get
|
||||
map.get(start - 1);
|
||||
map.get(lastKey);
|
||||
Assert.assertTrue(map.getOrDefault(lastKey, true));
|
||||
Assertions.assertTrue(map.getOrDefault(lastKey, true));
|
||||
|
||||
Assert.assertEquals(map.size(), booleans.length);
|
||||
Assertions.assertEquals(map.size(), booleans.length);
|
||||
|
||||
for (int i = start; i < booleans.length; i++) {
|
||||
Assert.assertTrue(map.containsKey(i));
|
||||
Assert.assertEquals(map.get(i), booleans[i - start]);
|
||||
Assertions.assertTrue(map.containsKey(i));
|
||||
Assertions.assertEquals(map.get(i), booleans[i - start]);
|
||||
}
|
||||
|
||||
for (int i = start - 1; i >= (start - 6); i--) {
|
||||
// Lower than expected check
|
||||
Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start);
|
||||
}
|
||||
|
||||
for (int i = booleans.length + start; i < booleans.length + start + 5; i++) {
|
||||
// Higher than expected check
|
||||
Assert.assertFalse(i + " is in a map that ends with " + (start + booleans.length), map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + booleans.length));
|
||||
}
|
||||
|
||||
for (boolean b : booleans) {
|
||||
Assert.assertTrue(map.containsValue(b));
|
||||
Assertions.assertTrue(map.containsValue(b));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -145,35 +147,35 @@ public class GeyserCollectionsTest {
|
|||
int lastKey = index;
|
||||
|
||||
// Easy, understandable out-of-bounds checks
|
||||
Assert.assertFalse("Map contains key bigger by one!", map.containsKey(lastKey));
|
||||
Assert.assertTrue("Map doesn't contain final key!", map.containsKey(lastKey - 1));
|
||||
Assertions.assertFalse(map.containsKey(lastKey), "Map contains key bigger by one!");
|
||||
Assertions.assertTrue(map.containsKey(lastKey - 1), "Map doesn't contain final key!");
|
||||
|
||||
// Ensure the first and last values do not throw an exception on get, and test getOrDefault
|
||||
map.get(start - 1);
|
||||
map.get(lastKey);
|
||||
Assert.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE);
|
||||
Assert.assertEquals(map.getOrDefault(lastKey, Integer.MAX_VALUE), Integer.MAX_VALUE);
|
||||
Assert.assertEquals(map.getOrDefault(lastKey, Integer.MIN_VALUE), Integer.MIN_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(start - 1, Integer.MAX_VALUE), Integer.MAX_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(lastKey, Integer.MAX_VALUE), Integer.MAX_VALUE);
|
||||
Assertions.assertEquals(map.getOrDefault(lastKey, Integer.MIN_VALUE), Integer.MIN_VALUE);
|
||||
|
||||
Assert.assertEquals(map.size(), ints.length);
|
||||
Assertions.assertEquals(map.size(), ints.length);
|
||||
|
||||
for (int i = start; i < ints.length; i++) {
|
||||
Assert.assertTrue(map.containsKey(i));
|
||||
Assert.assertEquals(map.get(i), ints[i - start]);
|
||||
Assertions.assertTrue(map.containsKey(i));
|
||||
Assertions.assertEquals(map.get(i), ints[i - start]);
|
||||
}
|
||||
|
||||
for (int i = start - 1; i >= (start - 6); i--) {
|
||||
// Lower than expected check
|
||||
Assert.assertFalse(i + " is in a map that starts with " + start, map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that starts with " + start);
|
||||
}
|
||||
|
||||
for (int i = ints.length + start; i < ints.length + 5 + start; i++) {
|
||||
// Higher than expected check
|
||||
Assert.assertFalse(i + " is in a map that ends with " + (start + ints.length), map.containsKey(i));
|
||||
Assertions.assertFalse(map.containsKey(i), i + " is in a map that ends with " + (start + ints.length));
|
||||
}
|
||||
|
||||
for (int i : ints) {
|
||||
Assert.assertTrue(map.containsValue(i));
|
||||
Assertions.assertTrue(map.containsValue(i));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue