feat(commands): add toggle autocomplete aliases
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
package games.dmg.spigotbase;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.UnaryOperator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class BaseFlightCommandTest {
|
||||
@Test
|
||||
void autocompletesExplicitModes() {
|
||||
BaseFlightCommand command = new BaseFlightCommand(
|
||||
mock(BaseStateManager.class),
|
||||
mock(BaseFlightController.class)
|
||||
);
|
||||
|
||||
assertEquals(
|
||||
List.of("off"),
|
||||
command.onTabComplete(null, null, "baseflight", new String[] {"of"})
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitOnIsIdempotent() {
|
||||
UUID playerId = UUID.randomUUID();
|
||||
Player player = mock(Player.class);
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(player.getName()).thenReturn("Builder");
|
||||
|
||||
PlayerState current = PlayerState.newPlayer(playerId, "Builder")
|
||||
.withAdministrativeLevels(1, 0, 1, 0, 0, false, true, false);
|
||||
AtomicReference<PlayerState> updated = new AtomicReference<>();
|
||||
BaseStateManager stateManager = mock(BaseStateManager.class);
|
||||
when(stateManager.player(playerId, "Builder")).thenReturn(current);
|
||||
when(stateManager.update(any(), anyString(), any())).thenAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
UnaryOperator<PlayerState> operation = invocation.getArgument(2);
|
||||
PlayerState result = operation.apply(current);
|
||||
updated.set(result);
|
||||
return result;
|
||||
});
|
||||
|
||||
BaseFlightCommand command = new BaseFlightCommand(
|
||||
stateManager,
|
||||
mock(BaseFlightController.class)
|
||||
);
|
||||
command.onCommand(player, null, "baseflight", new String[] {"on"});
|
||||
|
||||
assertTrue(updated.get().flightEnabled());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,53 @@
|
||||
package games.dmg.spigotbase;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
import java.util.function.UnaryOperator;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class BaseVisitorsCommandTest {
|
||||
@Test
|
||||
void autocompletesExplicitModes() {
|
||||
BaseVisitorsCommand command = new BaseVisitorsCommand(mock(BaseStateManager.class));
|
||||
|
||||
assertEquals(
|
||||
List.of("on"),
|
||||
command.onTabComplete(null, null, "basevisitors", new String[] {"on"})
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitOnIsIdempotent() {
|
||||
UUID playerId = UUID.randomUUID();
|
||||
Player player = mock(Player.class);
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(player.getName()).thenReturn("Host");
|
||||
|
||||
PlayerState current = PlayerState.newPlayer(playerId, "Host")
|
||||
.withAdministrativeLevels(4, 0, 0, 0, 0, false, false, true);
|
||||
AtomicReference<PlayerState> updated = new AtomicReference<>();
|
||||
BaseStateManager stateManager = mock(BaseStateManager.class);
|
||||
when(stateManager.player(playerId, "Host")).thenReturn(current);
|
||||
when(stateManager.update(any(), anyString(), any())).thenAnswer(invocation -> {
|
||||
@SuppressWarnings("unchecked")
|
||||
UnaryOperator<PlayerState> operation = invocation.getArgument(2);
|
||||
PlayerState result = operation.apply(current);
|
||||
updated.set(result);
|
||||
return result;
|
||||
});
|
||||
|
||||
BaseVisitorsCommand command = new BaseVisitorsCommand(stateManager);
|
||||
command.onCommand(player, null, "basevisitors", new String[] {"on"});
|
||||
|
||||
assertTrue(updated.get().visitorsEnabled());
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
package games.dmg.spigotbase;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class NavigationPreferenceTest {
|
||||
@Test
|
||||
void noArgumentTogglesCurrentPreference() {
|
||||
assertFalse(NavigationPreference.resolve(true, new String[0]));
|
||||
assertTrue(NavigationPreference.resolve(false, new String[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitModesAreIdempotent() {
|
||||
assertTrue(NavigationPreference.resolve(true, new String[] {"on"}));
|
||||
assertTrue(NavigationPreference.resolve(false, new String[] {"on"}));
|
||||
assertFalse(NavigationPreference.resolve(true, new String[] {"off"}));
|
||||
assertFalse(NavigationPreference.resolve(false, new String[] {"off"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsUnknownOrExtraArguments() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> NavigationPreference.resolve(false, new String[] {"maybe"})
|
||||
);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> NavigationPreference.resolve(false, new String[] {"on", "off"})
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -26,6 +26,30 @@ final class PluginMetadataTest {
|
||||
assertEquals(List.of("home"), base.get("aliases"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void homevisitorsAliasesBasevisitors() {
|
||||
Map<?, ?> commands = commands();
|
||||
|
||||
Map<?, ?> visitors = (Map<?, ?>) commands.get("basevisitors");
|
||||
assertEquals(List.of("homevisitors"), visitors.get("aliases"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void homeflightAliasesBaseflight() {
|
||||
Map<?, ?> commands = commands();
|
||||
|
||||
Map<?, ?> flight = (Map<?, ?>) commands.get("baseflight");
|
||||
assertEquals(List.of("homeflight"), flight.get("aliases"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void homenavigationAliasesBasenavigation() {
|
||||
Map<?, ?> commands = commands();
|
||||
|
||||
Map<?, ?> navigation = (Map<?, ?>) commands.get("basenavigation");
|
||||
assertEquals(List.of("homenavigation"), navigation.get("aliases"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void visitAliasesGotobase() {
|
||||
Map<?, ?> commands = commands();
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
package games.dmg.spigotbase;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertThrows;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
final class TogglePreferenceTest {
|
||||
@Test
|
||||
void noArgumentTogglesCurrentPreference() {
|
||||
assertFalse(TogglePreference.resolve(true, new String[0]));
|
||||
assertTrue(TogglePreference.resolve(false, new String[0]));
|
||||
}
|
||||
|
||||
@Test
|
||||
void explicitModesAreIdempotent() {
|
||||
assertTrue(TogglePreference.resolve(true, new String[] {"on"}));
|
||||
assertTrue(TogglePreference.resolve(false, new String[] {"on"}));
|
||||
assertFalse(TogglePreference.resolve(true, new String[] {"off"}));
|
||||
assertFalse(TogglePreference.resolve(false, new String[] {"off"}));
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsUnknownOrExtraArguments() {
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> TogglePreference.resolve(false, new String[] {"maybe"})
|
||||
);
|
||||
assertThrows(
|
||||
IllegalArgumentException.class,
|
||||
() -> TogglePreference.resolve(false, new String[] {"on", "off"})
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user