Merge ListUtil into StringUtil; refactor HelpSyntaxHelper + create test

The HelpSyntaxHelper had suppressed warnings for string concatenation within StringBuilder - the point of the StringBuilder is that it is faster when you use it to concatenate many elements. If you still use string concatenation with + within these calls it beats the purpose.
This commit is contained in:
ljacqu
2015-11-21 11:57:04 +01:00
parent a3f24bcb9a
commit b3d0a71dec
6 changed files with 159 additions and 91 deletions
@@ -0,0 +1,38 @@
package fr.xephi.authme.command;
import org.junit.Test;
import java.util.Arrays;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
/**
* Test for {@link CommandParts}.
*/
public class CommandPartsTest {
@Test
public void shouldPrintPartsForStringRepresentation() {
// given
CommandParts parts = new CommandParts(Arrays.asList("some", "parts", "for", "test"));
// when
String str = parts.toString();
// then
assertThat(str, equalTo("some parts for test"));
}
@Test
public void shouldPrintEmptyStringForNoArguments() {
// given
CommandParts parts = new CommandParts();
// when
String str = parts.toString();
// then
assertThat(str, equalTo(""));
}
}
@@ -2,8 +2,13 @@ package fr.xephi.authme.util;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
/**
* Test for {@link StringUtils}.
@@ -43,4 +48,40 @@ public class StringUtilsTest {
// then
assertThat(result, equalTo(false));
}
@Test
public void shouldCheckIsEmptyUtil() {
// Should be true for null/empty/whitespace
assertTrue(StringUtils.isEmpty(null));
assertTrue(StringUtils.isEmpty(""));
assertTrue(StringUtils.isEmpty(" \t"));
// Should be false if string has content
assertFalse(StringUtils.isEmpty("P"));
assertFalse(StringUtils.isEmpty(" test"));
}
@Test
public void shouldJoinString() {
// given
List<String> elements = Arrays.asList("test", "for", null, "join", "StringUtils");
// when
String result = StringUtils.join(", ", elements);
// then
assertThat(result, equalTo("test, for, join, StringUtils"));
}
@Test
public void shouldNotHaveDelimiter() {
// given
List<String> elements = Arrays.asList(" ", null, "\t", "hello", null);
// when
String result = StringUtils.join("-", elements);
// then
assertThat(result, equalTo("hello"));
}
}