|
27 | 27 | import org.mockito.Mockito; |
28 | 28 | import org.mockito.stubbing.Answer; |
29 | 29 |
|
| 30 | +import world.bentobox.aoneblock.AOneBlock; |
| 31 | +import world.bentobox.aoneblock.dataobjects.OneBlockIslands; |
| 32 | +import world.bentobox.aoneblock.oneblocks.OneBlockPhase; |
| 33 | +import world.bentobox.aoneblock.oneblocks.OneBlocksManager; |
30 | 34 | import world.bentobox.bentobox.api.addons.AddonDescription; |
31 | 35 | import world.bentobox.bentobox.api.addons.GameModeAddon; |
32 | 36 | import world.bentobox.bentobox.api.user.User; |
@@ -571,6 +575,73 @@ void testCheckGeneratorUnlockStatusKeepsDependentLockedWhenPrerequisiteLocked() |
571 | 575 | assertFalse(data.getUnlockedTiers().contains("magiccobblegenerator_gen2")); |
572 | 576 | } |
573 | 577 |
|
| 578 | + /** |
| 579 | + * Sets up an AOneBlock world whose island has reached the given block count, plus a phase "Underground" that starts |
| 580 | + * at block 100, and a phase-gated generator. Returns the island's data object (#121). |
| 581 | + */ |
| 582 | + private GeneratorDataObject seedPhaseGenerator(String tierId, int islandBlockCount, boolean aOneBlockWorld) { |
| 583 | + sgm.addWorld(world); |
| 584 | + when(island.getUniqueId()).thenReturn("island-121"); |
| 585 | + when(island.getWorld()).thenReturn(world); |
| 586 | + when(island.isSpawn()).thenReturn(false); |
| 587 | + s.setNotifyUnlockedGenerators(false); |
| 588 | + |
| 589 | + if (aOneBlockWorld) { |
| 590 | + AOneBlock aoneBlock = mock(AOneBlock.class); |
| 591 | + when(aoneBlock.getDescription()).thenReturn( |
| 592 | + new AddonDescription.Builder("", "AOneBlock", "1.0").build()); |
| 593 | + OneBlockPhase phase = mock(OneBlockPhase.class); |
| 594 | + when(phase.getBlockNumberValue()).thenReturn(100); |
| 595 | + OneBlocksManager obManager = mock(OneBlocksManager.class); |
| 596 | + when(obManager.getPhase("Underground")).thenReturn(Optional.of(phase)); |
| 597 | + when(aoneBlock.getOneBlockManager()).thenReturn(obManager); |
| 598 | + OneBlockIslands obIsland = mock(OneBlockIslands.class); |
| 599 | + when(obIsland.getBlockNumber()).thenReturn(islandBlockCount); |
| 600 | + when(aoneBlock.getOneBlocksIsland(island)).thenReturn(obIsland); |
| 601 | + when(iwm.getAddon(world)).thenReturn(Optional.of(aoneBlock)); |
| 602 | + } |
| 603 | + // Otherwise the default (non-AOneBlock) game mode from CommonTestSetup is used. |
| 604 | + |
| 605 | + GeneratorTierObject tier = prerequisiteTier(tierId, "Phase Gen", 10); |
| 606 | + when(tier.getRequiredPhase()).thenReturn("Underground"); |
| 607 | + sgm.loadGeneratorTier(tier, true, null); |
| 608 | + |
| 609 | + GeneratorDataObject data = sgm.getGeneratorData(island); |
| 610 | + assertNotNull(data); |
| 611 | + return data; |
| 612 | + } |
| 613 | + |
| 614 | + @Test |
| 615 | + void testUnlocksPhaseGeneratorWhenPhaseReached() { |
| 616 | + // Island at block 150, past the phase's start block of 100. |
| 617 | + GeneratorDataObject data = seedPhaseGenerator("aoneblock_phasegen", 150, true); |
| 618 | + |
| 619 | + sgm.checkGeneratorUnlockStatus(island, null, null); |
| 620 | + |
| 621 | + assertTrue(data.getUnlockedTiers().contains("aoneblock_phasegen")); |
| 622 | + } |
| 623 | + |
| 624 | + @Test |
| 625 | + void testKeepsPhaseGeneratorLockedWhenPhaseNotReached() { |
| 626 | + // Island at block 50, before the phase's start block of 100. |
| 627 | + GeneratorDataObject data = seedPhaseGenerator("aoneblock_phasegen", 50, true); |
| 628 | + |
| 629 | + sgm.checkGeneratorUnlockStatus(island, null, null); |
| 630 | + |
| 631 | + assertFalse(data.getUnlockedTiers().contains("aoneblock_phasegen")); |
| 632 | + } |
| 633 | + |
| 634 | + @Test |
| 635 | + void testKeepsPhaseGeneratorLockedInNonAOneBlockWorld() { |
| 636 | + // Not an AOneBlock world: the phase requirement can never be satisfied. The tier id matches the default |
| 637 | + // game mode so it is still evaluated. |
| 638 | + GeneratorDataObject data = seedPhaseGenerator("magiccobblegenerator_phasegen", 150, false); |
| 639 | + |
| 640 | + sgm.checkGeneratorUnlockStatus(island, null, null); |
| 641 | + |
| 642 | + assertFalse(data.getUnlockedTiers().contains("magiccobblegenerator_phasegen")); |
| 643 | + } |
| 644 | + |
574 | 645 | @Test |
575 | 646 | void testGetGeneratorDataIsland() { |
576 | 647 | assertNotNull(sgm.getGeneratorData(island)); |
|
0 commit comments