Remove old methods in Messages and add StringUtils tests

StringUtils - merge the two join methods to one common implementation with two interface; add tests

Messages - remove the methods taking a String as code after the kind refactoring by @DNx5
This commit is contained in:
ljacqu
2015-11-26 23:21:19 +01:00
parent 210b691353
commit 8ed672e89d
4 changed files with 54 additions and 47 deletions
@@ -1,8 +1,5 @@
package fr.xephi.authme.settings;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.AuthMeMockUtil;
import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.util.WrapperMock;
import org.bukkit.entity.Player;
import org.junit.Before;
@@ -51,11 +48,23 @@ public class MessagesTest {
MessageKey key = MessageKey.UNKNOWN_USER;
// when
String[] send = messages.retrieve(key);
String[] message = messages.retrieve(key);
// then
String[] lines = new String[]{"This test message", "includes", "some new lines"};
assertThat(send, equalTo(lines));
assertThat(message, equalTo(lines));
}
@Test
public void shouldLoadMessageAsStringWithNewLines() {
// given
MessageKey key = MessageKey.UNKNOWN_USER;
// when
String message = messages.retrieveSingle(key);
// then
assertThat(message, equalTo("This test message\nincludes\nsome new lines"));
}
@Test
@@ -65,7 +65,7 @@ public class StringUtilsTest {
}
@Test
public void shouldJoinString() {
public void shouldJoinStrings() {
// given
List<String> elements = Arrays.asList("test", "for", null, "join", "StringUtils");
@@ -76,6 +76,18 @@ public class StringUtilsTest {
assertThat(result, equalTo("test, for, join, StringUtils"));
}
@Test
public void shouldJoinStringArray() {
// given
String[] elements = {"A", "test", "sentence", "for", "the join", null, "method"};
// when
String result = StringUtils.join("_", elements);
// then
assertThat(result, equalTo("A_test_sentence_for_the join_method"));
}
@Test
public void shouldNotHaveDelimiter() {
// given
@@ -88,6 +100,15 @@ public class StringUtilsTest {
assertThat(result, equalTo("hello"));
}
@Test
public void shouldJoinWithNullDelimiter() {
// given/when
String result = StringUtils.join(null, "A", "Few", "Words", "\n", "To", "Join");
// then
assertThat(result, equalTo("AFewWordsToJoin"));
}
@Test
public void shouldFormatException() {
// given