Fixes tests. Initializes background in constructor.

The background might be customizable in the future.
This commit is contained in:
tastybento 2020-06-28 10:08:08 -07:00
parent 631b664059
commit baf0ba0974
2 changed files with 23 additions and 2 deletions

View File

@ -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<>();
@ -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) {
@ -73,6 +75,8 @@ public class LevelsManager {
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) {
@ -169,7 +173,7 @@ public class LevelsManager {
.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;

View File

@ -14,13 +14,17 @@ import java.util.Collections;
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;
@ -77,6 +81,8 @@ public class AdminTopRemoveCommandTest {
private TopTenData ttd;
@Mock
private LevelsManager manager;
@Mock
private Server server;
@Before
public void setUp() {
@ -112,6 +118,17 @@ public class AdminTopRemoveCommandTest {
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);
}