2018-07-31 18:03:32 +02:00
|
|
|
package world.bentobox.bentobox.util.teleport;
|
2018-04-28 18:50:07 +02:00
|
|
|
|
2019-01-16 00:23:17 +01:00
|
|
|
import static org.junit.Assert.assertEquals;
|
|
|
|
import static org.junit.Assert.assertNull;
|
|
|
|
import static org.mockito.Matchers.any;
|
|
|
|
import static org.mockito.Mockito.mock;
|
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
|
|
import java.util.Optional;
|
|
|
|
|
2018-04-28 18:50:07 +02:00
|
|
|
import org.bukkit.Location;
|
|
|
|
import org.bukkit.entity.Player;
|
|
|
|
import org.junit.Before;
|
|
|
|
import org.junit.Test;
|
|
|
|
import org.junit.runner.RunWith;
|
|
|
|
import org.mockito.InjectMocks;
|
|
|
|
import org.mockito.Mock;
|
2019-01-16 00:23:17 +01:00
|
|
|
import org.mockito.Mockito;
|
2018-04-28 18:50:07 +02:00
|
|
|
import org.powermock.api.mockito.PowerMockito;
|
|
|
|
import org.powermock.core.classloader.annotations.PrepareForTest;
|
|
|
|
import org.powermock.modules.junit4.PowerMockRunner;
|
2019-01-16 00:23:17 +01:00
|
|
|
|
2018-07-31 18:03:32 +02:00
|
|
|
import world.bentobox.bentobox.BentoBox;
|
|
|
|
import world.bentobox.bentobox.api.user.User;
|
|
|
|
import world.bentobox.bentobox.database.objects.Island;
|
2019-01-16 00:23:17 +01:00
|
|
|
import world.bentobox.bentobox.managers.IslandWorldManager;
|
2018-07-31 18:03:32 +02:00
|
|
|
import world.bentobox.bentobox.managers.LocalesManager;
|
2018-04-28 18:50:07 +02:00
|
|
|
|
|
|
|
@RunWith(PowerMockRunner.class)
|
2018-09-15 12:38:51 +02:00
|
|
|
@PrepareForTest(SafeSpotTeleport.Builder.class)
|
|
|
|
public class SafeSpotTeleportBuilderTest {
|
2018-04-28 18:50:07 +02:00
|
|
|
|
|
|
|
@Mock
|
|
|
|
private SafeSpotTeleport sst;
|
|
|
|
@Mock
|
2018-07-29 22:21:46 +02:00
|
|
|
private BentoBox plugin;
|
2018-04-28 18:50:07 +02:00
|
|
|
@Mock
|
|
|
|
private Player player;
|
|
|
|
@Mock
|
|
|
|
private Location loc;
|
|
|
|
|
|
|
|
@InjectMocks
|
2018-09-15 12:38:51 +02:00
|
|
|
private SafeSpotTeleport.Builder sstb;
|
2018-04-28 18:50:07 +02:00
|
|
|
|
|
|
|
@Before
|
|
|
|
public void setUp() throws Exception {
|
|
|
|
PowerMockito.whenNew(SafeSpotTeleport.class).withAnyArguments().thenReturn(sst);
|
|
|
|
// Users
|
|
|
|
User.setPlugin(plugin);
|
2018-09-15 12:38:51 +02:00
|
|
|
// Locales - final
|
2018-04-28 18:50:07 +02:00
|
|
|
LocalesManager lm = mock(LocalesManager.class);
|
|
|
|
when(plugin.getLocalesManager()).thenReturn(lm);
|
|
|
|
when(lm.get(any(), any())).thenReturn("mock translation");
|
2019-01-16 00:23:17 +01:00
|
|
|
// Addon
|
|
|
|
IslandWorldManager iwm = mock(IslandWorldManager.class);
|
|
|
|
when(iwm.getAddon(Mockito.any())).thenReturn(Optional.empty());
|
|
|
|
when(plugin.getIWM()).thenReturn(iwm);
|
|
|
|
|
2018-04-28 18:50:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void test() throws Exception {
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
|
|
|
sstb.build();
|
2019-07-03 10:36:50 +02:00
|
|
|
SafeSpotTeleport ttt = new SafeSpotTeleport(plugin, player, loc, null, false, 0);
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, ttt);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
2018-09-15 12:38:51 +02:00
|
|
|
public void testBuilder() {
|
|
|
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Should fail because no data
|
2018-09-15 12:38:51 +02:00
|
|
|
assertNull(sstb.build());
|
2018-04-28 18:50:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testEntity() throws Exception {
|
|
|
|
// Start builder
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add entity
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.entity(player);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Test for error
|
2018-09-15 12:38:51 +02:00
|
|
|
assertNull(sstb.build());
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add location
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.location(loc);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Build - expect success
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport result = sstb.build();
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testIsland() {
|
|
|
|
// Start builder
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add entity
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.entity(player);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add island
|
|
|
|
Island island = mock(Island.class);
|
|
|
|
when(island.getCenter()).thenReturn(loc);
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.island(island);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Build - expect success
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport result = sstb.build();
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testHomeNumber() {
|
|
|
|
// Start builder
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add entity
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.entity(player);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add location
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.location(loc);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add home
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.homeNumber(10);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Build - expect success
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport result = sstb.build();
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, result);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testPortal() {
|
|
|
|
// Start builder
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add entity
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.entity(player);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add location
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.location(loc);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Portal
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.portal();
|
2018-04-28 18:50:07 +02:00
|
|
|
// Build - expect success
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport result = sstb.build();
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, result);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
|
|
public void testFailureMessage() {
|
|
|
|
// Start builder
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport.Builder sstb = new SafeSpotTeleport.Builder(plugin);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add entity
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.entity(player);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add location
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.location(loc);
|
2018-04-28 18:50:07 +02:00
|
|
|
// Add failure
|
2018-09-15 12:38:51 +02:00
|
|
|
sstb.failureMessage("testing 123");
|
2018-04-28 18:50:07 +02:00
|
|
|
// Build - expect success
|
2018-09-15 12:38:51 +02:00
|
|
|
SafeSpotTeleport result = sstb.build();
|
2018-04-28 18:50:07 +02:00
|
|
|
assertEquals(sst, result);
|
|
|
|
}
|
|
|
|
}
|