Skip to content

Commit

Permalink
Update to latest API and fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tastybento committed Oct 5, 2024
1 parent aa6da34 commit 672a5b9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 7 deletions.
1 change: 1 addition & 0 deletions .github/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/.DS_Store
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
<powermock.version>2.0.9</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.20.6-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>2.4.0-SNAPSHOT</bentobox.version>
<bentobox.version>2.5.4</bentobox.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>
<!-- Do not change unless you want different name for local builds. -->
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/world/bentobox/bank/BankManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, DatabaseSetup.class, Util.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, DatabaseSetup.class, Util.class, IslandsManager.class })
public class BankManagerTest {

@Mock
Expand Down Expand Up @@ -105,6 +105,7 @@ public void setUp() {
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
// The database type has to be created one line before the thenReturn() to work!
DatabaseType value = DatabaseType.JSON;
when(plugin.getSettings()).thenReturn(pluginSettings);
Expand Down
3 changes: 2 additions & 1 deletion src/test/java/world/bentobox/bank/BankTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@

@SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, User.class, IslandsManager.class })
public class BankTest {

private static File jFile;
Expand Down Expand Up @@ -136,6 +136,7 @@ public static void beforeClass() throws IOException {
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Bukkit.class, Mockito.RETURNS_MOCKS);
PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);
// Set up plugin
Whitebox.setInternalState(BentoBox.class, "instance", plugin);

Expand Down
11 changes: 7 additions & 4 deletions src/test/java/world/bentobox/bank/PhManagerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;

Expand All @@ -33,6 +35,7 @@
import world.bentobox.bentobox.api.addons.AddonDescription;
import world.bentobox.bentobox.api.addons.GameModeAddon;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.DatabaseSetup;
import world.bentobox.bentobox.database.objects.Island;
import world.bentobox.bentobox.hooks.VaultHook;
import world.bentobox.bentobox.managers.IslandsManager;
Expand All @@ -44,7 +47,7 @@
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class})
@PrepareForTest({ Bukkit.class, BentoBox.class, DatabaseSetup.class, IslandsManager.class })
public class PhManagerTest {

// Class under test
Expand Down Expand Up @@ -73,12 +76,11 @@ public class PhManagerTest {
@Mock
private PlayersManager plm;


/**
*/
@Before
public void setUp() {

PowerMockito.mockStatic(IslandsManager.class, Mockito.RETURNS_MOCKS);

AddonDescription desc = new AddonDescription.Builder("main", "AcidIsland", "1.0.2").build();
when(gm.getDescription()).thenReturn(desc);
when(addon.getPlugin()).thenReturn(plugin);
Expand All @@ -91,6 +93,7 @@ public void setUp() {
when(addon.getVault()).thenReturn(vh);
when(addon.getIslands()).thenReturn(im);
when(user.getLocation()).thenReturn(location);

when(im.getIslandAt(eq(location))).thenReturn(Optional.of(island));
when(bm.getBalance(eq(island))).thenReturn(new Money(1234.56D));
map = new LinkedHashMap<>();
Expand Down

0 comments on commit 672a5b9

Please sign in to comment.