From 01b253d3040c80c26c754e43ca77e187a06d6b74 Mon Sep 17 00:00:00 2001 From: Andreas Troelsen Date: Sat, 11 Jan 2020 01:25:16 +0100 Subject: [PATCH] Add list entry variable test case to RendersTemplate. Adds test cases that cover a some of what was changed in 6e8a3e1626cfebd7cd26586cae516c481d864a96. --- .../MobArena/signs/RendersTemplateTest.java | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/src/test/java/com/garbagemule/MobArena/signs/RendersTemplateTest.java b/src/test/java/com/garbagemule/MobArena/signs/RendersTemplateTest.java index 15fd6da..5a15b2c 100644 --- a/src/test/java/com/garbagemule/MobArena/signs/RendersTemplateTest.java +++ b/src/test/java/com/garbagemule/MobArena/signs/RendersTemplateTest.java @@ -6,6 +6,7 @@ import static org.mockito.Mockito.*; import com.garbagemule.MobArena.framework.Arena; import com.garbagemule.MobArena.waves.WaveManager; +import org.bukkit.entity.Player; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -94,6 +95,40 @@ public class RendersTemplateTest { assertThat(result, equalTo(joining)); } + @Test + public void rendersReadyListEntries() { + Player ready = mock(Player.class); + when(ready.getName()).thenReturn("Bobcat00"); + Player notready = mock(Player.class); + when(notready.getName()).thenReturn("garbagemule"); + Arena arena = mock(Arena.class); + when(arena.configName()).thenReturn("castle"); + when(arena.isRunning()).thenReturn(false); + when(arena.getNonreadyPlayers()).thenReturn(Collections.singletonList(notready)); + when(arena.getReadyPlayersInLobby()).thenReturn(Collections.singleton(ready)); + Template template = new Template.Builder("template") + .withBase(new String[]{"", "", "", ""}) + .build(); + + String[] result = subject.render(template, arena); + + String[] expected = {"Bobcat00", "", "garbagemule", ""}; + assertThat(result, equalTo(expected)); + } + + @Test + public void doesNotRenderInvalidListEntries() { + Arena arena = arena("castle", false, true); + String[] base = new String[]{"", "", "", ""}; + Template template = new Template.Builder("template") + .withBase(base) + .build(); + + String[] result = subject.render(template, arena); + + assertThat(result, equalTo(base)); + } + private Arena arena(String name, boolean running, boolean lobby) { Arena arena = mock(Arena.class); when(arena.configName()).thenReturn(name);