Skip to content

Commit

Permalink
Fixes tests. Initializes background in constructor.
Browse files Browse the repository at this point in the history
The background might be customizable in the future.
  • Loading branch information
tastybento committed Jun 28, 2020
1 parent 631b664 commit baf0ba0
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/main/java/world/bentobox/level/LevelsManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ public class LevelsManager {
private static final TreeMap<BigInteger, String> LEVELS;
private static final int[] SLOTS = new int[] {4, 12, 14, 19, 20, 21, 22, 23, 24, 25};
private static final BigInteger THOUSAND = BigInteger.valueOf(1000);
private static final PanelItem BACKGROUND = new PanelItemBuilder().icon(Material.BLACK_STAINED_GLASS_PANE).name("").build();
static {
LEVELS = new TreeMap<>();

Expand All @@ -59,6 +58,9 @@ public class LevelsManager {
private final Database<TopTenData> topTenHandler;
// Top ten lists
private Map<World,TopTenData> topTenLists;
// Background
private final PanelItem background;



public LevelsManager(Level addon) {
Expand All @@ -73,6 +75,8 @@ public LevelsManager(Level addon) {
levelsCache = new HashMap<>();
// Initialize top ten lists
topTenLists = new HashMap<>();
// Background
background = new PanelItemBuilder().icon(Material.BLACK_STAINED_GLASS_PANE).name("").build();
}

private void addToTopTen(@NonNull World world, @NonNull UUID targetPlayer, long lv) {
Expand Down Expand Up @@ -169,7 +173,7 @@ public void getGUI(World world, final User user) {
.size(54)
.user(user);
// Background
for (int j = 0; j < 54; panel.item(j++, BACKGROUND));
for (int j = 0; j < 54; panel.item(j++, background));

// Top Ten
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,17 @@
import java.util.UUID;

import org.bukkit.Bukkit;
import org.bukkit.Server;
import org.bukkit.World;
import org.bukkit.entity.Player;
import org.bukkit.inventory.ItemFactory;
import org.bukkit.inventory.meta.ItemMeta;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
Expand Down Expand Up @@ -77,6 +81,8 @@ public class AdminTopRemoveCommandTest {
private TopTenData ttd;
@Mock
private LevelsManager manager;
@Mock
private Server server;

@Before
public void setUp() {
Expand Down Expand Up @@ -112,6 +118,17 @@ public void setUp() {
when(user.getUniqueId()).thenReturn(uuid);
when(user.getTranslation(any())).thenAnswer(invocation -> invocation.getArgument(0, String.class));

// Bukkit
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
// Mock item factory (for itemstacks)
ItemFactory itemFactory = mock(ItemFactory.class);
ItemMeta itemMeta = mock(ItemMeta.class);
when(itemFactory.getItemMeta(any())).thenReturn(itemMeta);
when(server.getItemFactory()).thenReturn(itemFactory);
when(Bukkit.getItemFactory()).thenReturn(itemFactory);


atrc = new AdminTopRemoveCommand(addon, ic);
}

Expand Down

0 comments on commit baf0ba0

Please sign in to comment.