Skip to content

Commit

Permalink
Add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
OliverSchlueter committed Nov 21, 2024
1 parent 10a3de1 commit bb1ed47
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/main/java/de/oliver/fancynpcs/skins/SkinFetcherImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import de.oliver.fancynpcs.FancyNpcs;
import de.oliver.fancynpcs.api.skins.SkinData;
import de.oliver.fancynpcs.api.skins.SkinFetcher;
import org.bukkit.Bukkit;
import org.bukkit.OfflinePlayer;
import org.mineskin.JsoupRequestHandler;
import org.mineskin.MineSkinClient;
import org.mineskin.data.CodeAndMessage;
Expand Down Expand Up @@ -35,6 +37,7 @@ public SkinFetcherImpl() {

this.client = MineSkinClient.builder()
.requestHandler(JsoupRequestHandler::new)
.userAgent("FancyNpcs")
.getExecutor(executor)
.generateExecutor(executor)
.generateRequestScheduler(executor)
Expand Down Expand Up @@ -63,7 +66,9 @@ public SkinData getByUUID(UUID uuid) {

@Override
public SkinData getByUsername(String username) {
GenerateRequest genReq = GenerateRequest.user(username);
OfflinePlayer offlinePlayer = Bukkit.getOfflinePlayer(username); // TODO: implement a better way to get the UUID

GenerateRequest genReq = GenerateRequest.user(offlinePlayer.getUniqueId());
SkinInfo skinInfo = executeRequest(genReq);

if (skinInfo == null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package de.oliver.fancynpcs.tests.impl;

import de.oliver.fancynpcs.tests.FNTestClass;
import de.oliver.fancynpcs.tests.impl.api.ChatColorHandlerTest;
import de.oliver.fancynpcs.tests.impl.api.CreateNpcTest;
import de.oliver.fancynpcs.tests.impl.api.skin.SkinFetcherTest;
import de.oliver.fancynpcs.tests.impl.commands.*;
import org.bukkit.entity.Player;

Expand All @@ -20,7 +20,8 @@ public class FancyNpcsTests {
public FancyNpcsTests() {
// api tests
addTest(CreateNpcTest.class);
addTest(ChatColorHandlerTest.class);
// addTest(ChatColorHandlerTest.class);
addTest(SkinFetcherTest.class);

// command tests
addTest(CreateCMDTest.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package de.oliver.fancynpcs.tests.impl.api.skin;

import de.oliver.fancynpcs.api.skins.SkinData;
import de.oliver.fancynpcs.skins.SkinFetcherImpl;
import de.oliver.fancynpcs.tests.annotations.FNBeforeEach;
import de.oliver.fancynpcs.tests.annotations.FNTest;
import org.bukkit.entity.Player;

public class SkinFetcherTest {

private SkinFetcherImpl skinFetcher;

@FNBeforeEach
public void setUp(Player player) {
skinFetcher = new SkinFetcherImpl();
}

@FNTest(name = "Test fetch skin by UUID")
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();
}

@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();
}

@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();
}

}

0 comments on commit bb1ed47

Please sign in to comment.