#1015 Distinguish player-dependent tags from "simple" tags
This commit is contained in:
@@ -9,6 +9,7 @@ import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.GeoIpService;
|
||||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -19,6 +20,7 @@ import org.mockito.Mock;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
@@ -66,9 +68,8 @@ public class WelcomeMessageConfigurationTest {
|
||||
public void shouldLoadWelcomeMessage() throws IOException {
|
||||
// given
|
||||
String welcomeMessage = "This is my welcome message for testing\nBye!";
|
||||
Files.write(welcomeFile.toPath(), welcomeMessage.getBytes());
|
||||
setWelcomeMessageAndReload(welcomeMessage);
|
||||
Player player = mock(Player.class);
|
||||
welcomeMessageConfiguration.reload();
|
||||
|
||||
// when
|
||||
List<String> result = welcomeMessageConfiguration.getWelcomeMessage(player);
|
||||
@@ -83,8 +84,7 @@ public class WelcomeMessageConfigurationTest {
|
||||
public void shouldReplaceNameAndIpAndCountry() throws IOException {
|
||||
// given
|
||||
String welcomeMessage = "Hello {PLAYER}, your IP is {IP}\nYour country is {COUNTRY}.\nWelcome to {SERVER}!";
|
||||
Files.write(welcomeFile.toPath(), welcomeMessage.getBytes());
|
||||
welcomeMessageConfiguration.reload();
|
||||
setWelcomeMessageAndReload(welcomeMessage);
|
||||
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn("Bobby");
|
||||
@@ -103,4 +103,39 @@ public class WelcomeMessageConfigurationTest {
|
||||
verify(server, only()).getServerName();
|
||||
verifyZeroInteractions(playerCache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldApplyOtherReplacements() throws IOException {
|
||||
// given
|
||||
String welcomeMessage = "{ONLINE}/{MAXPLAYERS} online\n{LOGINS} logged in\nYour world is {WORLD}\nServer: {VERSION}";
|
||||
setWelcomeMessageAndReload(welcomeMessage);
|
||||
given(bukkitService.getOnlinePlayers()).willReturn((List) Arrays.asList(mock(Player.class), mock(Player.class)));
|
||||
given(server.getMaxPlayers()).willReturn(20);
|
||||
given(playerCache.getLogged()).willReturn(1);
|
||||
given(server.getBukkitVersion()).willReturn("Bukkit-456.77.8");
|
||||
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn("Hub");
|
||||
Player player = mock(Player.class);
|
||||
given(player.getWorld()).willReturn(world);
|
||||
|
||||
// when
|
||||
List<String> result = welcomeMessageConfiguration.getWelcomeMessage(player);
|
||||
|
||||
// then
|
||||
assertThat(result, hasSize(4));
|
||||
assertThat(result.get(0), equalTo("2/20 online"));
|
||||
assertThat(result.get(1), equalTo("1 logged in"));
|
||||
assertThat(result.get(2), equalTo("Your world is Hub"));
|
||||
assertThat(result.get(3), equalTo("Server: Bukkit-456.77.8"));
|
||||
}
|
||||
|
||||
private void setWelcomeMessageAndReload(String welcomeMessage) {
|
||||
try {
|
||||
Files.write(welcomeFile.toPath(), welcomeMessage.getBytes());
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException("Could not write to '" + welcomeFile + "'", e);
|
||||
}
|
||||
welcomeMessageConfiguration.reload();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user