Fix #349 Create method on Messages to pass tag replacements

- Add tests
- Fix placeholder in some files
This commit is contained in:
ljacqu
2015-12-16 20:46:40 +01:00
parent 558a1240a6
commit dcc365c22f
7 changed files with 88 additions and 24 deletions
@@ -2,9 +2,11 @@ package fr.xephi.authme.output;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.util.WrapperMock;
import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player;
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
import java.io.File;
@@ -14,6 +16,8 @@ import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
/**
@@ -137,4 +141,58 @@ public class MessagesIntegrationTest {
verify(player).sendMessage(line);
}
}
@Test
public void shouldSendMessageToPlayerWithTagReplacement() {
// given
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
CommandSender sender = Mockito.mock(CommandSender.class);
// when
messages.send(sender, key, "1234");
// then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(sender, times(1)).sendMessage(captor.capture());
String message = captor.getValue();
assertThat(message, equalTo("Use /captcha 1234 to solve the captcha"));
}
@Test
public void shouldNotThrowForKeyWithNoTagReplacements() {
// given
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
CommandSender sender = mock(CommandSender.class);
// when
messages.send(sender, key);
// then
ArgumentCaptor<String> captor = ArgumentCaptor.forClass(String.class);
verify(sender, times(1)).sendMessage(captor.capture());
String message = captor.getValue();
assertThat(message, equalTo("Use /captcha THE_CAPTCHA to solve the captcha"));
}
@Test(expected = RuntimeException.class)
public void shouldThrowForInvalidReplacementCount() {
// given
MessageKey key = MessageKey.CAPTCHA_WRONG_ERROR;
// when
messages.send(mock(CommandSender.class), key, "rep", "rep2");
// then - expect exception
}
@Test(expected = RuntimeException.class)
public void shouldThrowForReplacementsOnKeyWithNoTags() {
// given
MessageKey key = MessageKey.UNKNOWN_USER;
// when
messages.send(mock(CommandSender.class), key, "Replacement");
// then - expect exception
}
}
+1
View File
@@ -4,3 +4,4 @@ not_logged_in: 'Apostrophes '' should be loaded correctly, don''t you think?'
reg_voluntarily: 'You can register yourself to the server with the command "/register <password> <ConfirmPassword>"'
usage_log: '&cUsage: /login <password>'
wrong_pwd: '&cWrong password!'
wrong_captcha: 'Use /captcha THE_CAPTCHA to solve the captcha'