Skip to content

Commit

Permalink
Fixed tests by fixing the default rank value.
Browse files Browse the repository at this point in the history
Flag was marked as deprecated, which may be okay, but because it caused
a lot of warnings in the tests because they bypass the builder I removed
the deprecation but kept the warning in the JavaDoc.
  • Loading branch information
tastybento committed Dec 24, 2018
1 parent cc15aa1 commit 68d6b00
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 27 deletions.
29 changes: 14 additions & 15 deletions src/main/java/world/bentobox/bentobox/api/flags/Flag.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,8 @@ public Material getIcon() {
private final boolean subPanel;

/**
* @deprecated {@link Flag.Builder} should be used instead.
* {@link Flag.Builder} should be used instead. This is only used for testing.
*/
@Deprecated
Flag(String id, Material icon, Listener listener, Type type, int defaultRank, PanelItem.ClickHandler clickListener, boolean subPanel) {
this.id = id;
this.icon = icon;
Expand Down Expand Up @@ -282,7 +281,7 @@ public static class Builder {

// Default settings
private boolean defaultSetting;
private int defaultRank;
private int defaultRank = RanksManager.MEMBER_RANK;

// ClickHandler - default depends on the type
private PanelItem.ClickHandler clickHandler;
Expand Down Expand Up @@ -329,18 +328,18 @@ public Flag build() {
// If no clickHandler has been set, then apply default ones
if (clickHandler == null) {
switch (type){
case PROTECTION:
clickHandler = new CycleClick(id);
break;
case SETTING:
clickHandler = new IslandToggleClick(id);
break;
case WORLD_SETTING:
clickHandler = new WorldToggleClick(id);
break;
default:
clickHandler = new CycleClick(id);
break;
case PROTECTION:
clickHandler = new CycleClick(id);
break;
case SETTING:
clickHandler = new IslandToggleClick(id);
break;
case WORLD_SETTING:
clickHandler = new WorldToggleClick(id);
break;
default:
clickHandler = new CycleClick(id);
break;
}
}

Expand Down
37 changes: 35 additions & 2 deletions src/main/java/world/bentobox/bentobox/lists/Flags.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,42 @@

import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.Flag.Type;
import world.bentobox.bentobox.api.flags.FlagBuilder;
import world.bentobox.bentobox.api.flags.clicklisteners.CycleClick;
import world.bentobox.bentobox.listeners.flags.*;
import world.bentobox.bentobox.listeners.flags.BlockInteractionListener;
import world.bentobox.bentobox.listeners.flags.BreakBlocksListener;
import world.bentobox.bentobox.listeners.flags.BreedingListener;
import world.bentobox.bentobox.listeners.flags.BucketListener;
import world.bentobox.bentobox.listeners.flags.ChestDamageListener;
import world.bentobox.bentobox.listeners.flags.CleanSuperFlatListener;
import world.bentobox.bentobox.listeners.flags.CoarseDirtTillingListener;
import world.bentobox.bentobox.listeners.flags.CreeperListener;
import world.bentobox.bentobox.listeners.flags.EggListener;
import world.bentobox.bentobox.listeners.flags.EnderChestListener;
import world.bentobox.bentobox.listeners.flags.EndermanListener;
import world.bentobox.bentobox.listeners.flags.EnterExitListener;
import world.bentobox.bentobox.listeners.flags.EntityInteractListener;
import world.bentobox.bentobox.listeners.flags.ExperiencePickupListener;
import world.bentobox.bentobox.listeners.flags.FireListener;
import world.bentobox.bentobox.listeners.flags.GeoLimitMobsListener;
import world.bentobox.bentobox.listeners.flags.HurtingListener;
import world.bentobox.bentobox.listeners.flags.InventoryListener;
import world.bentobox.bentobox.listeners.flags.InvincibleVisitorsListener;
import world.bentobox.bentobox.listeners.flags.IslandRespawnListener;
import world.bentobox.bentobox.listeners.flags.ItemDropPickUpListener;
import world.bentobox.bentobox.listeners.flags.ItemFrameListener;
import world.bentobox.bentobox.listeners.flags.LeashListener;
import world.bentobox.bentobox.listeners.flags.LockAndBanListener;
import world.bentobox.bentobox.listeners.flags.MobSpawnListener;
import world.bentobox.bentobox.listeners.flags.OfflineRedstoneListener;
import world.bentobox.bentobox.listeners.flags.PVPListener;
import world.bentobox.bentobox.listeners.flags.PhysicalInteractionListener;
import world.bentobox.bentobox.listeners.flags.PistonPushListener;
import world.bentobox.bentobox.listeners.flags.PlaceBlocksListener;
import world.bentobox.bentobox.listeners.flags.PortalListener;
import world.bentobox.bentobox.listeners.flags.RemoveMobsListener;
import world.bentobox.bentobox.listeners.flags.ShearingListener;
import world.bentobox.bentobox.listeners.flags.TNTListener;
import world.bentobox.bentobox.listeners.flags.TeleportationListener;
import world.bentobox.bentobox.listeners.flags.clicklisteners.CommandRankClickListener;
import world.bentobox.bentobox.listeners.flags.clicklisteners.GeoLimitClickListener;
import world.bentobox.bentobox.managers.RanksManager;
Expand Down
3 changes: 1 addition & 2 deletions src/test/java/world/bentobox/bentobox/TestBentoBox.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import world.bentobox.bentobox.api.events.IslandBaseEvent;
import world.bentobox.bentobox.api.events.team.TeamEvent;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagBuilder;
import world.bentobox.bentobox.api.flags.FlagListener;
import world.bentobox.bentobox.api.user.User;
import world.bentobox.bentobox.database.objects.Island;
Expand Down Expand Up @@ -500,7 +499,7 @@ public void testDefaultFlags() {
public void testCustomFlags() {
// Custom
TestFlagListener fl = new TestFlagListener(plugin);
Flag customFlag = new FlagBuilder().id("CUSTOM_FLAG").icon(Material.DIAMOND).listener(fl).build();
Flag customFlag = new Flag.Builder("CUSTOM_FLAG", Material.DIAMOND).listener(fl).build();
assertEquals("CUSTOM_FLAG", customFlag.getID());
assertEquals(Material.DIAMOND, customFlag.getIcon());
assertEquals(fl, customFlag.getListener().get());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@

import world.bentobox.bentobox.BentoBox;
import world.bentobox.bentobox.api.flags.Flag;
import world.bentobox.bentobox.api.flags.FlagBuilder;
import world.bentobox.bentobox.listeners.flags.BreakBlocksListener;
import world.bentobox.bentobox.lists.Flags;

Expand Down Expand Up @@ -97,11 +96,9 @@ public void testRegisterDuplicateFlag() {
public void testRegisterDuplicateFlagIcons() {
FlagsManager fm = new FlagsManager(plugin);
// Change the ID to something random, but use every icon that is already used
Flags.values().forEach(dupe -> assertFalse(fm.registerFlag(new FlagBuilder()
.id(UUID.randomUUID().toString())
.icon(dupe.getIcon())
.listener(new BreakBlocksListener())
.build())));
Flags.values().forEach(dupe -> assertFalse(fm.registerFlag(
new Flag.Builder(UUID.randomUUID().toString(), dupe.getIcon()).listener(new BreakBlocksListener()).build()
)));
}


Expand All @@ -111,12 +108,12 @@ public void testRegisterOriginalFlagOriginalListener() {
FlagsManager fm = new FlagsManager(plugin);
// This should pass
OriginalListener ol = new OriginalListener();
Flag originalFlag = new FlagBuilder().id("ORIGINAL").icon(Material.EMERALD_BLOCK).listener(ol).build();
Flag originalFlag = new Flag.Builder("ORIGINAL", Material.EMERALD_BLOCK).listener(ol).build();
assertTrue(fm.registerFlag(originalFlag));
// Verify registered
Mockito.verify(server).getPluginManager();
// Register another flag with same listener
Flag originalFlag2 = new FlagBuilder().id("ORIGINAL2").icon(Material.COAL_ORE).listener(ol).build();
Flag originalFlag2 = new Flag.Builder("ORIGINAL2", Material.COAL_ORE).listener(ol).build();
assertTrue(fm.registerFlag(originalFlag2));
// Verify registered only once
Mockito.verify(server).getPluginManager();
Expand Down

0 comments on commit 68d6b00

Please sign in to comment.