|
11 | 11 | import static org.mockito.Mockito.when; |
12 | 12 |
|
13 | 13 | import com.gmail.nossr50.config.experience.ExperienceConfig; |
| 14 | +import com.gmail.nossr50.datatypes.player.PlayerProfile; |
| 15 | +import com.gmail.nossr50.datatypes.player.UniqueDataType; |
| 16 | +import com.gmail.nossr50.datatypes.skills.PrimarySkillType; |
| 17 | +import com.gmail.nossr50.datatypes.skills.SuperAbilityType; |
14 | 18 | import java.lang.reflect.Field; |
| 19 | +import java.util.EnumMap; |
| 20 | +import java.util.Map; |
15 | 21 | import java.util.UUID; |
16 | 22 | import org.junit.jupiter.api.AfterEach; |
17 | 23 | import org.junit.jupiter.api.BeforeEach; |
@@ -288,4 +294,29 @@ void stateWithFutureExpiryHasActiveEntries() throws Exception { |
288 | 294 | "state with a future latestExpiryTimeMillis should report active entries"); |
289 | 295 | } |
290 | 296 | } |
| 297 | + |
| 298 | + @Nested |
| 299 | + class PlayerProfileConstructorIntegration { |
| 300 | + |
| 301 | + @Test |
| 302 | + void mapBasedConstructorShouldUseUuidCacheState() { |
| 303 | + // Given - a player UUID with an existing cached DR state |
| 304 | + final UUID playerUuid = UUID.randomUUID(); |
| 305 | + final DiminishedReturnsState cachedState = DiminishedReturnsCache.getOrCreate(playerUuid); |
| 306 | + |
| 307 | + final Map<PrimarySkillType, Integer> levelData = new EnumMap<>(PrimarySkillType.class); |
| 308 | + final Map<PrimarySkillType, Float> xpData = new EnumMap<>(PrimarySkillType.class); |
| 309 | + final Map<SuperAbilityType, Integer> cooldownData = new EnumMap<>(SuperAbilityType.class); |
| 310 | + final Map<UniqueDataType, Integer> uniqueData = new EnumMap<>(UniqueDataType.class); |
| 311 | + |
| 312 | + // When - profile is created using the map-based constructor used by DB loaders |
| 313 | + final PlayerProfile loadedProfile = new PlayerProfile("TestPlayer", playerUuid, |
| 314 | + levelData, xpData, cooldownData, 0, uniqueData, null); |
| 315 | + loadedProfile.registerXpGain(PrimarySkillType.MINING, 50F); |
| 316 | + |
| 317 | + // Then - cached state should reflect the XP registered by that loaded profile |
| 318 | + assertEquals(50F, cachedState.getRegisteredXpGain(PrimarySkillType.MINING), |
| 319 | + "loaded profiles with UUID must use the UUID-cached DR state"); |
| 320 | + } |
| 321 | + } |
291 | 322 | } |
0 commit comments