Updates spotless and adds a license header.
This commit is contained in:
@@ -1,53 +1,70 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import org.bukkit.Location;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
class CuboidTest {
|
||||
@Test
|
||||
void convertsWorldEditBoundsToCuboidCoordinates() {
|
||||
Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
@Test
|
||||
void convertsWorldEditBoundsToCuboidCoordinates() {
|
||||
Cuboid cuboid = new Cuboid(BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
|
||||
assertEquals(1, cuboid.getMinX());
|
||||
assertEquals(2, cuboid.getMinY());
|
||||
assertEquals(3, cuboid.getMinZ());
|
||||
assertEquals(4, cuboid.getMaxX());
|
||||
assertEquals(5, cuboid.getMaxY());
|
||||
assertEquals(6, cuboid.getMaxZ());
|
||||
}
|
||||
assertEquals(1, cuboid.getMinX());
|
||||
assertEquals(2, cuboid.getMinY());
|
||||
assertEquals(3, cuboid.getMinZ());
|
||||
assertEquals(4, cuboid.getMaxX());
|
||||
assertEquals(5, cuboid.getMaxY());
|
||||
assertEquals(6, cuboid.getMaxZ());
|
||||
}
|
||||
|
||||
@Test
|
||||
void comparesVectorsByXThenZThenYAndHandlesNulls() {
|
||||
assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO));
|
||||
assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, null));
|
||||
assertEquals(0, Cuboid.compareBlockVectors(null, null));
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 0), BlockVector3.at(2, 0, 0)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 1), BlockVector3.at(1, 0, 2)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0);
|
||||
}
|
||||
@Test
|
||||
void comparesVectorsByXThenZThenYAndHandlesNulls() {
|
||||
assertEquals(-1, Cuboid.compareBlockVectors(null, BlockVector3.ZERO));
|
||||
assertEquals(1, Cuboid.compareBlockVectors(BlockVector3.ZERO, null));
|
||||
assertEquals(0, Cuboid.compareBlockVectors(null, null));
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 0), BlockVector3.at(2, 0, 0)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 0, 1), BlockVector3.at(1, 0, 2)) < 0);
|
||||
assertTrue(Cuboid.compareBlockVectors(BlockVector3.at(1, 1, 2), BlockVector3.at(1, 2, 2)) < 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void treatsTouchingBoundsAsIntersecting() {
|
||||
Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10);
|
||||
Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20);
|
||||
Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10);
|
||||
@Test
|
||||
void treatsTouchingBoundsAsIntersecting() {
|
||||
Cuboid first = new Cuboid(0, 0, 0, 10, 10, 10);
|
||||
Cuboid touching = new Cuboid(10, 10, 10, 20, 20, 20);
|
||||
Cuboid separate = new Cuboid(11, 0, 0, 20, 10, 10);
|
||||
|
||||
assertTrue(first.intersects(touching));
|
||||
assertFalse(first.intersects(separate));
|
||||
}
|
||||
assertTrue(first.intersects(touching));
|
||||
assertFalse(first.intersects(separate));
|
||||
}
|
||||
|
||||
@Test
|
||||
void containsPointsOnBoundsButRejectsPointsOutside() {
|
||||
Cuboid cuboid = new Cuboid(1, 2, 3, 4, 5, 6);
|
||||
@Test
|
||||
void containsPointsOnBoundsButRejectsPointsOutside() {
|
||||
Cuboid cuboid = new Cuboid(1, 2, 3, 4, 5, 6);
|
||||
|
||||
assertTrue(cuboid.contains(new Location(null, 1, 2, 3)));
|
||||
assertTrue(cuboid.contains(new Location(null, 4, 5, 6)));
|
||||
assertFalse(cuboid.contains(new Location(null, 5, 5, 6)));
|
||||
}
|
||||
}
|
||||
assertTrue(cuboid.contains(new Location(null, 1, 2, 3)));
|
||||
assertTrue(cuboid.contains(new Location(null, 4, 5, 6)));
|
||||
assertFalse(cuboid.contains(new Location(null, 5, 5, 6)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -11,31 +28,34 @@ import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
class CurrentHomesStoreTest {
|
||||
@TempDir
|
||||
File temporaryDirectory;
|
||||
@TempDir File temporaryDirectory;
|
||||
|
||||
@Test
|
||||
void roundTripsHomesByUuid() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
Map<UUID, Integer> expected = Map.of(playerId, 3);
|
||||
@Test
|
||||
void roundTripsHomesByUuid() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
Map<UUID, Integer> expected = Map.of(playerId, 3);
|
||||
|
||||
CurrentHomesStore.save(file, expected);
|
||||
CurrentHomesStore.save(file, expected);
|
||||
|
||||
assertEquals(expected, CurrentHomesStore.load(file, ignored -> null));
|
||||
}
|
||||
assertEquals(expected, CurrentHomesStore.load(file, ignored -> null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolvesLegacyPlayerNameKeys() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.set("OldPlayerName", 2);
|
||||
yaml.save(file);
|
||||
@Test
|
||||
void resolvesLegacyPlayerNameKeys() throws Exception {
|
||||
File file = new File(temporaryDirectory, "currentHomes.yml");
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
YamlConfiguration yaml = new YamlConfiguration();
|
||||
yaml.set("OldPlayerName", 2);
|
||||
yaml.save(file);
|
||||
|
||||
assertEquals(Map.of(playerId, 2), CurrentHomesStore.load(file, name -> {
|
||||
assertEquals("OldPlayerName", name);
|
||||
return playerId;
|
||||
}));
|
||||
}
|
||||
}
|
||||
assertEquals(
|
||||
Map.of(playerId, 2),
|
||||
CurrentHomesStore.load(
|
||||
file,
|
||||
name -> {
|
||||
assertEquals("OldPlayerName", name);
|
||||
return playerId;
|
||||
}));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,27 +1,41 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
class PlayerHomeTest {
|
||||
@Test
|
||||
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
PlayerHome home = new PlayerHome(
|
||||
playerId,
|
||||
"PlayerName",
|
||||
2,
|
||||
BlockVector3.at(1, 2, 3),
|
||||
BlockVector3.at(4, 5, 6));
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
assertEquals(playerId, home.getPlayerId());
|
||||
assertEquals("PlayerName", home.getPlayerName());
|
||||
assertEquals(2, home.getNumber());
|
||||
assertEquals("h_2_" + playerId, home.getRegionName());
|
||||
}
|
||||
}
|
||||
class PlayerHomeTest {
|
||||
@Test
|
||||
void buildsUuidBasedRegionIdentityAndPreservesDisplayName() {
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
PlayerHome home =
|
||||
new PlayerHome(
|
||||
playerId, "PlayerName", 2, BlockVector3.at(1, 2, 3), BlockVector3.at(4, 5, 6));
|
||||
|
||||
assertEquals(playerId, home.getPlayerId());
|
||||
assertEquals("PlayerName", home.getPlayerName());
|
||||
assertEquals(2, home.getNumber());
|
||||
assertEquals("h_2_" + playerId, home.getRegionName());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
@@ -11,12 +28,12 @@ import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PlayerLookupTest {
|
||||
@Test
|
||||
void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() {
|
||||
Player player = mock(Player.class);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
@Test
|
||||
void matchesOnlinePlayerNamesCaseInsensitivelyButNotByPrefix() {
|
||||
Player player = mock(Player.class);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
|
||||
assertSame(player, PlayerLookup.findOnline("playername", List.of(player)));
|
||||
assertNull(PlayerLookup.findOnline("Player", List.of(player)));
|
||||
}
|
||||
}
|
||||
assertSame(player, PlayerLookup.findOnline("playername", List.of(player)));
|
||||
assertNull(PlayerLookup.findOnline("Player", List.of(player)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,24 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.assertFalse;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -9,40 +26,40 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
class MetropolisHomeAcquireTest {
|
||||
@Test
|
||||
void assignsAPlotWhenThePlayerIsBelowTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(0);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
@Test
|
||||
void assignsAPlotWhenThePlayerIsBelowTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(0);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
|
||||
assertTrue(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
|
||||
assertTrue(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
|
||||
|
||||
verify(plugin).assignPlot(player);
|
||||
}
|
||||
verify(plugin).assignPlot(player);
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(1);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
@Test
|
||||
void doesNotAssignAPlotAfterThePlayerReachesTheirLimit() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
UUID playerId = UUID.fromString("123e4567-e89b-12d3-a456-426614174000");
|
||||
when(player.getUniqueId()).thenReturn(playerId);
|
||||
when(plugin.getNumPlots(playerId)).thenReturn(1);
|
||||
when(plugin.getMaxPlots(playerId)).thenReturn(1);
|
||||
MetropolisHomeAcquire executor = new MetropolisHomeAcquire(plugin);
|
||||
|
||||
assertFalse(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
|
||||
assertFalse(executor.onCommand(player, mock(Command.class), "acquire", new String[0]));
|
||||
|
||||
verify(plugin, never()).assignPlot(player);
|
||||
}
|
||||
}
|
||||
verify(plugin, never()).assignPlot(player);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.commands;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
@@ -8,42 +25,46 @@ import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
import org.bukkit.command.Command;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.Cuboid;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
|
||||
class MetropolisPlotReserveCommandTest {
|
||||
@Test
|
||||
void reservesCoordinatesFromAllSixArguments() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
@Test
|
||||
void reservesCoordinatesFromAllSixArguments() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
|
||||
assertTrue(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"}));
|
||||
assertTrue(
|
||||
executor.onCommand(
|
||||
sender, command, "reserve", new String[] {"north", "1", "2", "3", "4", "5", "6"}));
|
||||
|
||||
ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class);
|
||||
verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
|
||||
assertEquals(1, cuboid.getValue().getMinX());
|
||||
assertEquals(2, cuboid.getValue().getMinY());
|
||||
assertEquals(3, cuboid.getValue().getMinZ());
|
||||
assertEquals(4, cuboid.getValue().getMaxX());
|
||||
assertEquals(5, cuboid.getValue().getMaxY());
|
||||
assertEquals(6, cuboid.getValue().getMaxZ());
|
||||
}
|
||||
ArgumentCaptor<Cuboid> cuboid = ArgumentCaptor.forClass(Cuboid.class);
|
||||
verify(plugin).reserveCuboid(eq("north"), cuboid.capture());
|
||||
assertEquals(1, cuboid.getValue().getMinX());
|
||||
assertEquals(2, cuboid.getValue().getMinY());
|
||||
assertEquals(3, cuboid.getValue().getMinZ());
|
||||
assertEquals(4, cuboid.getValue().getMaxX());
|
||||
assertEquals(5, cuboid.getValue().getMaxY());
|
||||
assertEquals(6, cuboid.getValue().getMaxZ());
|
||||
}
|
||||
|
||||
@Test
|
||||
void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
@Test
|
||||
void rejectsMalformedCoordinateArgumentsWithoutCallingPlugin() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
Command command = mock(Command.class);
|
||||
MetropolisPlotReserveCommand executor = new MetropolisPlotReserveCommand(plugin);
|
||||
|
||||
assertFalse(executor.onCommand(sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"}));
|
||||
verifyNoInteractions(plugin);
|
||||
}
|
||||
}
|
||||
assertFalse(
|
||||
executor.onCommand(
|
||||
sender, command, "reserve", new String[] {"north", "1", "two", "3", "4", "5", "6"}));
|
||||
verifyNoInteractions(plugin);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,3 +1,20 @@
|
||||
/*
|
||||
This file is part of Metropolis.
|
||||
|
||||
Metropolis is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
Metropolis is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with Metropolis. If not, see <https://www.gnu.org/licenses/agpl-3.0.txt>.
|
||||
*/
|
||||
|
||||
package com.majinnaibu.bukkitplugins.metropolis.eventlisteners;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.contains;
|
||||
@@ -7,31 +24,33 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import com.majinnaibu.bukkitplugins.metropolis.MetropolisPlugin;
|
||||
import com.majinnaibu.bukkitplugins.metropolis.PlayerHome;
|
||||
import com.sk89q.worldedit.math.BlockVector3;
|
||||
|
||||
import org.bukkit.entity.Player;
|
||||
import org.bukkit.event.player.PlayerJoinEvent;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class PlayerJoinListenerTest {
|
||||
@Test
|
||||
void tellsJoiningPlayerTheirHomeBounds() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
PlayerJoinEvent event = mock(PlayerJoinEvent.class);
|
||||
when(event.getPlayer()).thenReturn(player);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
when(plugin.getPlayerHome(player)).thenReturn(new PlayerHome(
|
||||
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
|
||||
"PlayerName",
|
||||
1,
|
||||
BlockVector3.at(1, 2, 3),
|
||||
BlockVector3.at(4, 5, 6)));
|
||||
@Test
|
||||
void tellsJoiningPlayerTheirHomeBounds() {
|
||||
MetropolisPlugin plugin = mock(MetropolisPlugin.class);
|
||||
Player player = mock(Player.class);
|
||||
PlayerJoinEvent event = mock(PlayerJoinEvent.class);
|
||||
when(event.getPlayer()).thenReturn(player);
|
||||
when(player.getName()).thenReturn("PlayerName");
|
||||
when(plugin.getPlayerHome(player))
|
||||
.thenReturn(
|
||||
new PlayerHome(
|
||||
UUID.fromString("123e4567-e89b-12d3-a456-426614174000"),
|
||||
"PlayerName",
|
||||
1,
|
||||
BlockVector3.at(1, 2, 3),
|
||||
BlockVector3.at(4, 5, 6)));
|
||||
|
||||
new PlayerJoinListener(plugin).onPlayerJoin(event);
|
||||
new PlayerJoinListener(plugin).onPlayerJoin(event);
|
||||
|
||||
verify(player).sendMessage(contains("home is between (1, 2, 3) and (4, 5, 6)"));
|
||||
}
|
||||
}
|
||||
verify(player).sendMessage(contains("home is between (1, 2, 3) and (4, 5, 6)"));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user