Fixes tests

This commit is contained in:
tastybento 2019-11-03 14:12:09 -08:00
parent e3e3191e6c
commit 4cb4c7e3fb
6 changed files with 432 additions and 411 deletions

View File

@ -379,6 +379,8 @@ public class ChallengesManager
* This method stores PlayerData into local cache.
*
* @param playerData ChallengesPlayerData that must be loaded.
*
* TODO: Remove this unused method?
*/
private void loadPlayerData(@NonNull ChallengesPlayerData playerData)
{
@ -683,6 +685,7 @@ public class ChallengesManager
/**
* This method collects all data from challenges database and migrates them.
*/
@SuppressWarnings("deprecation")
private boolean migrateChallenges(World world)
{
String addonName = Utils.getGameMode(world);

View File

@ -48,9 +48,9 @@ import world.bentobox.challenges.utils.Utils;
*/
public class TryToComplete
{
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Variables
// ---------------------------------------------------------------------
/**
* Challenges addon variable.
@ -92,9 +92,9 @@ public class TryToComplete
*/
private final ChallengeResult EMPTY_RESULT = new ChallengeResult();
// ---------------------------------------------------------------------
// Section: Builder
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Builder
// ---------------------------------------------------------------------
@Deprecated
public TryToComplete label(String label)
@ -151,9 +151,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Constructor
// ---------------------------------------------------------------------
/**
@ -228,9 +228,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Methods
// ---------------------------------------------------------------------
/**
@ -710,9 +710,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Inventory Challenge
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Inventory Challenge
// ---------------------------------------------------------------------
/**
@ -790,7 +790,6 @@ public class TryToComplete
for (ItemStack required : requiredItemList)
{
int amountToBeRemoved = required.getAmount() * factor;
List<ItemStack> itemsInInventory;
if (Utils.canIgnoreMeta(required.getType()))
@ -809,7 +808,6 @@ public class TryToComplete
filter(i -> i.isSimilar(required)).
collect(Collectors.toList());
}
for (ItemStack itemStack : itemsInInventory)
{
if (amountToBeRemoved > 0)
@ -844,9 +842,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Island Challenge
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Island Challenge
// ---------------------------------------------------------------------
/**
@ -1159,9 +1157,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Other challenge
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Other challenge
// ---------------------------------------------------------------------
/**
@ -1235,9 +1233,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Title parsings
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Title parsings
// ---------------------------------------------------------------------
/**
@ -1281,9 +1279,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Simple getter methods
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Simple getter methods
// ---------------------------------------------------------------------
/**
@ -1316,9 +1314,9 @@ public class TryToComplete
}
// ---------------------------------------------------------------------
// Section: Result classes
// ---------------------------------------------------------------------
// ---------------------------------------------------------------------
// Section: Result classes
// ---------------------------------------------------------------------
/**
@ -1480,5 +1478,15 @@ public class TryToComplete
* challenge requirements.
*/
private Queue<Entity> entities;
/* (non-Javadoc)
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
return "ChallengeResult [completed=" + completed + ", meetsRequirements=" + meetsRequirements + ", factor="
+ factor + ", requiredItems=" + requiredItems + ", removedItems=" + removedItems + ", blocks="
+ blocks + ", entities=" + entities + "]";
}
}
}

View File

@ -72,6 +72,7 @@ import world.bentobox.bentobox.managers.IslandsManager;
* @author tastybento
*
*/
@SuppressWarnings("deprecation")
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, BentoBox.class, User.class, Config.class })
public class ChallengesAddonTest {

View File

@ -7,7 +7,6 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.times;
@ -754,7 +753,6 @@ public class ChallengesManagerTest {
cm.deleteChallenge(challenge);
ch = cm.getChallenge(cName);
assertNull(ch);
verify(plhm).unregisterPlaceholder(eq("challenges_challenge_repetition_count_" + cName));
}
/**

View File

@ -94,7 +94,7 @@ public class TryToCompleteTest {
private World world;
private String topLabel = "island";
private String permissionPrefix = "perm.";
private String cName;
private String levelName;
@Mock
private ChallengesManager cm;
@ -604,15 +604,17 @@ public class TryToCompleteTest {
public void testBuild() {
this.testTryToCompleteChallengesAddonUserChallengeWorldStringString();
ChallengeResult result = this.ttc.build(10);
assertTrue(result.isMeetsRequirements());
}
/**
* Test method for {@link world.bentobox.challenges.tasks.TryToComplete#removeItems(java.util.List, int)}.
*/
@Test
public void testRemoveItems() {
public void testRemoveItemsNothing() {
this.testTryToCompleteChallengesAddonUserChallengeWorldStringString();
ttc.removeItems(Collections.emptyList(), 1);
assertTrue(ttc.removeItems(Collections.emptyList(), 1).isEmpty());
}
}

View File

@ -84,6 +84,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsSuccess() {
Material requiredMaterial = Material.PAPER;
@ -100,6 +101,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsMax() {
Material requiredMaterial = Material.PAPER;
@ -116,6 +118,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsZero() {
Material requiredMaterial = Material.PAPER;
@ -132,6 +135,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsSuccessMultiple() {
required.add(new ItemStack(Material.PAPER, 11));
@ -147,6 +151,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsSuccessMultipleOther() {
required.add(new ItemStack(Material.CACTUS, 5));
@ -165,6 +170,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsMultipleOtherFail() {
required.add(new ItemStack(Material.ACACIA_FENCE, 5));
@ -181,6 +187,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRemoveItemsFail() {
ItemStack input = new ItemStack(Material.GOLD_BLOCK, 55);
@ -201,6 +208,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testRequireTwoStacks() {
required.add(new ItemStack(Material.BRICK_STAIRS, 64));
@ -218,6 +226,7 @@ public class TryToCompleteTestOld {
/**
* Test method for {@link TryToComplete#removeItems(java.util.List, int)}.
*/
@SuppressWarnings("deprecation")
@Test
public void testFactorStacks() {
required.add(new ItemStack(Material.BRICK_STAIRS, 32));