From e5e3503abc2c64b02ec94dadf26fa7eb19571534 Mon Sep 17 00:00:00 2001 From: Liam Date: Sat, 13 Apr 2024 17:21:33 +0100 Subject: [PATCH] fix tests --- .../fascinated/model/cache/CachedPlayerName.java | 14 +++++++++----- .../java/cc/fascinated/service/PlayerService.java | 1 + .../cc/fascinated/tests/PlayerControllerTests.java | 4 ++-- 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java b/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java index 480c624..4c01c0d 100644 --- a/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java +++ b/src/main/java/cc/fascinated/model/cache/CachedPlayerName.java @@ -9,19 +9,23 @@ import java.util.UUID; /** * @author Braydon */ -@AllArgsConstructor @Getter -@EqualsAndHashCode(onlyExplicitlyIncluded = true) @ToString @RedisHash(value = "playerName", timeToLive = 60L * 60L * 6) // 6 hours (in seconds) -public final class CachedPlayerName { +public final class CachedPlayerName extends CachedResponse { /** * The username of the player. */ - @Id @NonNull private String username; + @Id private final String username; /** * The unique id of the player. */ - @NonNull private UUID uniqueId; + private final UUID uniqueId; + + public CachedPlayerName(String username, UUID uniqueId) { + super(CacheInformation.defaultCache()); + this.username = username; + this.uniqueId = uniqueId; + } } \ No newline at end of file diff --git a/src/main/java/cc/fascinated/service/PlayerService.java b/src/main/java/cc/fascinated/service/PlayerService.java index ec34cb5..5d67ab7 100644 --- a/src/main/java/cc/fascinated/service/PlayerService.java +++ b/src/main/java/cc/fascinated/service/PlayerService.java @@ -115,6 +115,7 @@ public class PlayerService { CachedPlayerName player = new CachedPlayerName(username, uuid); playerNameCacheRepository.save(player); log.info("Got UUID from username: {} -> {}", username, uuid); + player.getCache().setCached(false); return player; } catch (RateLimitException exception) { throw new MojangAPIRateLimitException(); diff --git a/src/test/java/cc/fascinated/tests/PlayerControllerTests.java b/src/test/java/cc/fascinated/tests/PlayerControllerTests.java index 2a5d903..2a62bae 100644 --- a/src/test/java/cc/fascinated/tests/PlayerControllerTests.java +++ b/src/test/java/cc/fascinated/tests/PlayerControllerTests.java @@ -48,8 +48,8 @@ class PlayerControllerTests { .accept(MediaType.APPLICATION_JSON) .contentType(MediaType.APPLICATION_JSON)) .andExpect(status().isOk()) - .andExpect(jsonPath("$.player.username").value(testPlayer)) - .andExpect(jsonPath("$.player.uniqueId").value(testPlayerUuid)); + .andExpect(jsonPath("$.username").value(testPlayer)) + .andExpect(jsonPath("$.uniqueId").value(testPlayerUuid)); } @Test