Start refactoring for Messages class

This commit is contained in:
ljacqu
2015-11-24 22:54:54 +01:00
parent 2e5b7ecf29
commit cf4e47488b
3 changed files with 116 additions and 74 deletions
@@ -9,7 +9,10 @@ import org.junit.Test;
import java.io.File;
import java.net.URL;
import static java.util.Arrays.asList;
import static org.hamcrest.Matchers.arrayWithSize;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.assertThat;
/**
* Test for {@link Messages}.
@@ -19,6 +22,11 @@ public class MessagesTest {
private static final String YML_TEST_FILE = "messages_test.yml";
private Messages messages;
/**
* Loads the messages in the file {@code messages_test.yml} in the test resources folder.
* The file does not contain all messages defined in {@link MessageKey} and its contents
* reflect various test cases -- not what the keys stand for.
*/
@Before
public void setUpMessages() {
AuthMe authMe = AuthMeMockUtil.mockAuthMeInstance();
@@ -35,10 +43,55 @@ public class MessagesTest {
}
@Test
public void shouldLoadMessages() {
public void shouldLoadMessageAndSplitAtNewLines() {
// given
MessageKey key = MessageKey.UNKNOWN_USER;
// when
String[] send = messages.send(MessageKey.CAPTCHA_WRONG_ERROR.getKey());
System.out.println(asList(send));
String[] send = messages.send(key);
// then
String[] lines = new String[]{"This test message", "includes", "some new lines"};
assertThat(send, equalTo(lines));
}
@Test
public void shouldFormatColorCodes() {
// given
MessageKey key = MessageKey.UNSAFE_QUIT_LOCATION;
// when
String[] message = messages.send(key);
// then
assertThat(message, arrayWithSize(1));
assertThat(message[0], equalTo("§cHere we have§bdefined some colors §dand some other §lthings"));
}
@Test
public void shouldRetainApostrophes() {
// given
MessageKey key = MessageKey.NOT_LOGGED_IN;
// when
String[] message = messages.send(key);
// then
assertThat(message, arrayWithSize(1));
assertThat(message[0], equalTo("Apostrophes ' should be loaded correctly, don't you think?"));
}
@Test
public void shouldReturnErrorForUnknownCode() {
// given
// The following is a key that is not defined in the test file
MessageKey key = MessageKey.UNREGISTERED_SUCCESS;
// when
String[] message = messages.send(key);
// then
assertThat(message, arrayWithSize(1));
assertThat(message[0], startsWith("Error getting message with key '"));
}
}
+3 -55
View File
@@ -1,58 +1,6 @@
unknown_user: '&cCan''t find the requested user in the database!'
unsafe_spawn: '&cYour quit location was unsafe, you have been teleported to the world''s spawnpoint.'
not_logged_in: '&cYou''re not logged in!'
unknown_user: 'This test message&nincludes&nsome new lines'
unsafe_spawn: '&cHere we have&bdefined some colors &dand some other &lthings'
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!'
unregistered: '&cSuccessfully unregistered!'
reg_disabled: '&cIn-game registration is disabled!'
valid_session: '&2Logged-in due to Session Reconnection.'
login: '&2Successful login!'
vb_nonActiv: '&cYour account isn''t activated yet, please check your emails!'
user_regged: '&cYou already have registered this username!'
usage_reg: '&cUsage: /register <password> <ConfirmPassword>'
max_reg: '&cYou have exceeded the maximum number of registrations for your connection!'
no_perm: '&4You don''t have the permission to perform this action!'
error: '&4An unexpected error occurred, please contact an Administrator!'
login_msg: '&cPlease, login with the command "/login <password>"'
reg_msg: '&3Please, register to the server with the command "/register <password> <ConfirmPassword>"'
reg_email_msg: '&3Please, register to the server with the command "/register <email> <confirmEmail>"'
usage_unreg: '&cUsage: /unregister <password>'
pwd_changed: '&2Password changed successfully!'
user_unknown: '&cThis user isn''t registered!'
password_error: '&cPasswords didn''t match, check them again!'
password_error_nick: '&cYou can''t use your name as password, please choose another one...'
password_error_unsafe: '&cThe chosen password isn''t safe, please choose another one...'
invalid_session: '&cYour IP has been changed and your session data has expired!'
reg_only: '&4Only registered users can join the server! Please visit http://example.com to register yourself!'
logged_in: '&cYou''re already logged in!'
logout: '&2Logged-out successfully!'
same_nick: '&4The same username is already playing on the server!'
registered: '&2Successfully registered!'
pass_len: '&cYour password is too short or too long! Please try with another one!'
reload: '&2Configuration and database have been reloaded correctly!'
timeout: '&4Login timeout exceeded, you have been kicked from the server, please try again!'
usage_changepassword: '&cUsage: /changepassword <oldPassword> <newPassword>'
name_len: '&4Your username is either too short or too long!'
regex: '&4Your username contains illegal characters. Allowed chars: REG_EX'
add_email: '&3Please add your email to your account with the command "/email add <yourEmail> <confirmEmail>"'
recovery_email: '&3Forgot your password? Please use the command "/email recovery <yourEmail>"'
usage_captcha: '&3To login you have to solve a captcha code, please use the command "/captcha <theCaptcha>"'
wrong_captcha: '&cWrong Captcha, please type "/captcha THE_CAPTCHA" into the chat!'
valid_captcha: '&2Captcha code solved correctly!'
kick_forvip: '&3A VIP Player has joined the server when it was full!'
kick_fullserver: '&4The server is full, try again later!'
usage_email_add: '&cUsage: /email add <email> <confirmEmail>'
usage_email_change: '&cUsage: /email change <oldEmail> <newEmail>'
usage_email_recovery: '&cUsage: /email recovery <Email>'
new_email_invalid: '&cInvalid New Email, try again!'
old_email_invalid: '&cInvalid Old Email, try again!'
email_invalid: '&cInvalid Email address, try again!'
email_added: '&2Email address successfully added to your account!'
email_confirm: '&cPlease confirm your email address!'
email_changed: '&2Email address changed correctly!'
email_send: '&2Recovery email sent correctly! Check your email inbox!'
email_exists: '&cA recovery email was already sent! You can discart it and send a new one using the command below:'
country_banned: '&4Your country is banned from this server!'
antibot_auto_enabled: '&4[AntiBotService] AntiBot enabled due to the huge number of connections!'
antibot_auto_disabled: '&2[AntiBotService] AntiBot disabled disabled after %m minutes!'