From 02363ab1bde65e024e4be9b0d36ee96c13ce4dd4 Mon Sep 17 00:00:00 2001 From: Oliver Date: Thu, 21 Nov 2024 13:38:28 +0100 Subject: [PATCH] Refactor assertions to use `expect` utility in tests --- .../tests/impl/api/skin/SkinFetcherTest.java | 69 +++++++++++-------- 1 file changed, 39 insertions(+), 30 deletions(-) diff --git a/src/main/java/de/oliver/fancynpcs/tests/impl/api/skin/SkinFetcherTest.java b/src/main/java/de/oliver/fancynpcs/tests/impl/api/skin/SkinFetcherTest.java index 2a5e955e..9022381b 100644 --- a/src/main/java/de/oliver/fancynpcs/tests/impl/api/skin/SkinFetcherTest.java +++ b/src/main/java/de/oliver/fancynpcs/tests/impl/api/skin/SkinFetcherTest.java @@ -9,6 +9,8 @@ import java.io.File; +import static de.oliver.fancynpcs.tests.Expectable.expect; + public class SkinFetcherTest { private SkinFetcherImpl skinFetcher; @@ -22,36 +24,41 @@ public void setUp(Player player) { public void testSkinByUUID(Player player) { SkinData skin = skinFetcher.getByUUID(player.getUniqueId()); - assert skin != null; - assert skin.identifier().equals(player.getUniqueId().toString()); - assert skin.type().equals(SkinData.SkinType.UUID); - assert skin.variant().equals(SkinData.SkinVariant.DEFAULT); - assert skin.textureValue() != null && !skin.textureValue().isEmpty(); - assert skin.textureSignature() != null && !skin.textureSignature().isEmpty(); + expect(skin).toBeDefined(); + expect(skin.identifier()).toEqual(player.getUniqueId().toString()); + expect(skin.type()).toEqual(SkinData.SkinType.UUID); + expect(skin.variant()).toEqual(SkinData.SkinVariant.DEFAULT); + expect(skin.textureValue()).toBeDefined(); + expect(skin.textureValue().length()).toBeGreaterThan(0); + expect(skin.textureSignature()).toBeDefined(); + expect(skin.textureSignature().length()).toBeGreaterThan(0); } @FNTest(name = "Test fetch skin by username") public void testSkinByUsername(Player player) { SkinData skin = skinFetcher.getByUsername(player.getName()); - assert skin != null; - assert skin.identifier().equals(player.getName()); - assert skin.type().equals(SkinData.SkinType.USERNAME); - assert skin.variant().equals(SkinData.SkinVariant.DEFAULT); - assert skin.textureValue() != null && !skin.textureValue().isEmpty(); - assert skin.textureSignature() != null && !skin.textureSignature().isEmpty(); + expect(skin).toBeDefined(); + expect(skin.identifier()).toEqual(player.getName()); + expect(skin.type()).toEqual(SkinData.SkinType.USERNAME); + expect(skin.variant()).toEqual(SkinData.SkinVariant.DEFAULT); + expect(skin.textureValue()).toBeDefined(); + expect(skin.textureValue().length()).toBeGreaterThan(0); + expect(skin.textureSignature()).toBeDefined(); } @FNTest(name = "Test fetch skin by URL") public void testSkinByURL(Player player) { SkinData skin = skinFetcher.getByURL("https://s.namemc.com/i/de7d8a3ffd1f584c.png"); - assert skin != null; - assert skin.identifier().equals("https://s.namemc.com/i/de7d8a3ffd1f584c.png"); - assert skin.type().equals(SkinData.SkinType.URL); - assert skin.variant().equals(SkinData.SkinVariant.DEFAULT); - assert skin.textureValue() != null && !skin.textureValue().isEmpty(); - assert skin.textureSignature() != null && !skin.textureSignature().isEmpty(); + expect(skin).toBeDefined(); + expect(skin.identifier()).toEqual("https://s.namemc.com/i/de7d8a3ffd1f584c.png"); + expect(skin.type()).toEqual(SkinData.SkinType.URL); + expect(skin.variant()).toEqual(SkinData.SkinVariant.DEFAULT); + expect(skin.textureValue()).toBeDefined(); + expect(skin.textureValue().length()).toBeGreaterThan(0); + expect(skin.textureSignature()).toBeDefined(); + expect(skin.textureSignature().length()).toBeGreaterThan(0); } @FNTest(name = "Test fetch skin by file") @@ -59,12 +66,14 @@ public void testSkinByFile(Player player) { SkinData skin = skinFetcher.getByFile("plugins/FancyNpcs/testskin.png"); FancyNpcs.getInstance().getPlugin().saveResource("testskin.png", false); - assert skin != null; - assert skin.identifier().equals("src/test/resources/skin.png"); - assert skin.type().equals(SkinData.SkinType.FILE); - assert skin.variant().equals(SkinData.SkinVariant.DEFAULT); - assert skin.textureValue() != null && !skin.textureValue().isEmpty(); - assert skin.textureSignature() != null && !skin.textureSignature().isEmpty(); + expect(skin).toBeDefined(); + expect(skin.identifier()).toEqual("plugins/FancyNpcs/testskin.png"); + expect(skin.type()).toEqual(SkinData.SkinType.FILE); + expect(skin.variant()).toEqual(SkinData.SkinVariant.DEFAULT); + expect(skin.textureValue()).toBeDefined(); + expect(skin.textureValue().length()).toBeGreaterThan(0); + expect(skin.textureSignature()).toBeDefined(); + expect(skin.textureSignature().length()).toBeGreaterThan(0); new File("plugins/FancyNpcs/testskin.png").delete(); } @@ -73,11 +82,11 @@ public void testSkinByFile(Player player) { public void testGetSkin(Player player) { SkinData skin = skinFetcher.get("skinname", "value", "signature"); - assert skin != null; - assert skin.identifier().equals("skinname"); - assert skin.type().equals(SkinData.SkinType.VALUE_SIGNATURE); - assert skin.variant().equals(SkinData.SkinVariant.DEFAULT); - assert skin.textureValue().equals("value"); - assert skin.textureSignature().equals("signature"); + expect(skin).toBeDefined(); + expect(skin.identifier()).toEqual("skinname"); + expect(skin.type()).toEqual(SkinData.SkinType.VALUE_SIGNATURE); + expect(skin.variant()).toEqual(SkinData.SkinVariant.DEFAULT); + expect(skin.textureValue()).toEqual("value"); + expect(skin.textureSignature()).toEqual("signature"); } }