@@ -54,6 +54,7 @@ public class InvincibleVisitorsListenerTest {
5454 private IslandsManager im ;
5555 private List <String > ivSettings ;
5656 private Player player ;
57+ private Optional <Island > optionalIsland ;
5758
5859 /**
5960 * @throws java.lang.Exception
@@ -104,6 +105,7 @@ public void setUp() throws Exception {
104105 Island island = mock (Island .class );
105106 when (island .getOwner ()).thenReturn (uuid );
106107 when (im .getIsland (Mockito .any (World .class ), Mockito .any (User .class ))).thenReturn (island );
108+ optionalIsland = Optional .of (island );
107109 // Visitor
108110 when (im .userIsOnIsland (Mockito .any (), Mockito .any ())).thenReturn (false );
109111 when (plugin .getIslands ()).thenReturn (im );
@@ -220,15 +222,39 @@ public void testOnVisitorGetDamageNotVoid() {
220222 Mockito .verify (player , Mockito .never ()).setGameMode (Mockito .eq (GameMode .SPECTATOR ));
221223 }
222224
225+
223226 @ Test
224- public void testOnVisitorGetDamageVoid () {
225- // For testing, have no island to teleport to
226- when (im .getIslandAt (Mockito .any ())).thenReturn (Optional .empty ());
227+ public void testOnVisitorGetDamageVoidIslandHere () {
228+ when (im .getIslandAt (Mockito .any ())).thenReturn (optionalIsland );
227229 EntityDamageEvent e = new EntityDamageEvent (player , EntityDamageEvent .DamageCause .VOID , 0D );
230+ // Player should be teleported to this island
228231 listener .onVisitorGetDamage (e );
229232 assertTrue (e .isCancelled ());
230233 Mockito .verify (player ).setGameMode (Mockito .eq (GameMode .SPECTATOR ));
231- Mockito .verify (im ).getIslandAt (Mockito .any ());
232234 }
233235
236+ @ Test
237+ public void testOnVisitorGetDamageVoidNoIslandHerePlayerHasNoIsland () {
238+ when (im .getIslandAt (Mockito .any ())).thenReturn (Optional .empty ());
239+ when (im .hasIsland (Mockito .any (), Mockito .any (UUID .class ))).thenReturn (false );
240+ EntityDamageEvent e = new EntityDamageEvent (player , EntityDamageEvent .DamageCause .VOID , 0D );
241+ // Player should die
242+ listener .onVisitorGetDamage (e );
243+ assertFalse (e .isCancelled ());
244+ Mockito .verify (player , Mockito .never ()).setGameMode (Mockito .eq (GameMode .SPECTATOR ));
245+ }
246+
247+ @ Test
248+ public void testOnVisitorGetDamageVoidPlayerHasIsland () {
249+ when (im .getIslandAt (Mockito .any ())).thenReturn (Optional .empty ());
250+ when (im .hasIsland (Mockito .any (), Mockito .any (UUID .class ))).thenReturn (true );
251+ EntityDamageEvent e = new EntityDamageEvent (player , EntityDamageEvent .DamageCause .VOID , 0D );
252+ // Player should be teleported to their island
253+ listener .onVisitorGetDamage (e );
254+ assertTrue (e .isCancelled ());
255+ Mockito .verify (player , Mockito .never ()).setGameMode (Mockito .eq (GameMode .SPECTATOR ));
256+ Mockito .verify (im ).homeTeleport (Mockito .any (), Mockito .eq (player ));
257+ }
258+
259+
234260}
0 commit comments