Remove StringUtils#join in favor of String#join (Java 8)

This commit is contained in:
ljacqu
2016-10-02 12:44:10 +02:00
parent e07c685d2a
commit 71ac86ff02
19 changed files with 27 additions and 181 deletions
@@ -4,7 +4,6 @@ import fr.xephi.authme.output.LogLevel;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.PluginSettings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.StringUtils;
import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
@@ -135,7 +134,7 @@ public class ConsoleLoggerTest {
assertThat(loggedLines.get(1),
containsString("[WARN] Exception occurred: [IllegalStateException]: Test exception message"));
// Check that we have this class' full name somewhere in the file -> stacktrace of Exception e
assertThat(StringUtils.join("", loggedLines), containsString(getClass().getCanonicalName()));
assertThat(String.join("", loggedLines), containsString(getClass().getCanonicalName()));
}
@Test
@@ -296,17 +296,12 @@ public class CommandInitializerTest {
* @return List of all bindings that lead to the command
*/
private static List<String> getAbsoluteLabels(CommandDescription command) {
String parentPath = "";
CommandDescription elem = command.getParent();
while (elem != null) {
parentPath = elem.getLabels().get(0) + " " + parentPath;
elem = elem.getParent();
}
parentPath = parentPath.trim();
CommandDescription parent = command.getParent();
String parentPath = (parent == null) ? "" : parent.getLabels().get(0) + " ";
List<String> bindings = new ArrayList<>(command.getLabels().size());
for (String label : command.getLabels()) {
bindings.add(StringUtils.join(" ", parentPath, label));
bindings.add(parentPath + label);
}
return bindings;
}
@@ -3,10 +3,6 @@ package fr.xephi.authme.command;
import fr.xephi.authme.TestHelper;
import org.junit.Test;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
@@ -15,42 +11,6 @@ import static org.junit.Assert.assertThat;
*/
public class CommandUtilsTest {
@Test
public void shouldPrintPartsForStringRepresentation() {
// given
Iterable<String> parts = Arrays.asList("some", "parts", "for", "test");
// when
String str = CommandUtils.labelsToString(parts);
// then
assertThat(str, equalTo("some parts for test"));
}
@Test
public void shouldPrintEmptyStringForNoArguments() {
// given
List<String> parts = Collections.emptyList();
// when
String str = CommandUtils.labelsToString(parts);
// then
assertThat(str, equalTo(""));
}
@Test
public void shouldPrintLabels() {
// given
List<String> labels = Arrays.asList("authme", "help", "reload");
// when
String result = CommandUtils.labelsToString(labels);
// then
assertThat(result, equalTo("authme help reload"));
}
@Test
public void shouldReturnCommandPath() {
// given
@@ -13,7 +13,6 @@ import fr.xephi.authme.settings.properties.ProtectionSettings;
import fr.xephi.authme.settings.properties.RegistrationSettings;
import fr.xephi.authme.settings.properties.RestrictionSettings;
import fr.xephi.authme.util.BukkitService;
import fr.xephi.authme.util.StringUtils;
import fr.xephi.authme.util.ValidationService;
import org.bukkit.Server;
import org.bukkit.entity.Player;
@@ -511,7 +510,7 @@ public class OnJoinVerifierTest {
@Override
public void describeTo(Description description) {
description.appendValue("VerificationFailedException: reason=" + messageKey + ";args="
+ (args == null ? "null" : StringUtils.join(", ", args)));
+ (args == null ? "null" : String.join(", ", args)));
}
};
}
@@ -32,7 +32,7 @@ public class MessagesFileConsistencyTest {
if (!errors.isEmpty()) {
fail("Validation errors in " + MESSAGES_FILE + ":\n- "
+ StringUtils.join("\n- ", errors));
+ String.join("\n- ", errors));
}
}
@@ -55,7 +55,7 @@ public class MessagesFileConsistencyTest {
if (!missingTags.isEmpty()) {
String pluralS = missingTags.size() > 1 ? "s" : "";
errors.add(String.format("Message with key '%s' missing tag%s: %s", key, pluralS,
StringUtils.join(", ", missingTags)));
String.join(", ", missingTags)));
}
}
}
@@ -48,7 +48,7 @@ public class MessagesFileYamlCheckerTest {
// then
if (!errors.isEmpty()) {
fail("Errors during verification of message files:\n-" + StringUtils.join("\n-", errors));
fail("Errors during verification of message files:\n-" + String.join("\n-", errors));
}
}
@@ -2,7 +2,6 @@ package fr.xephi.authme.permission;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -65,7 +64,7 @@ public class PermissionConsistencyTest {
// then
if (!errors.isEmpty()) {
fail("Found consistency issues!\n" + StringUtils.join("\n", errors));
fail("Found consistency issues!\n" + String.join("\n", errors));
}
}
@@ -90,7 +89,7 @@ public class PermissionConsistencyTest {
// then
if (!errors.isEmpty()) {
fail("Found consistency issues!\n" + StringUtils.join("\n", errors));
fail("Found consistency issues!\n" + String.join("\n", errors));
}
}
@@ -172,7 +171,7 @@ public class PermissionConsistencyTest {
}
if (!badChildren.isEmpty()) {
errorList.add("Permission '" + definition.node + "' has children that are not logically below it: "
+ StringUtils.join(", ", badChildren));
+ String.join(", ", badChildren));
}
}
@@ -8,7 +8,6 @@ import com.github.authme.configme.resource.PropertyResource;
import com.github.authme.configme.resource.YamlFileResource;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.settings.properties.AuthMeSettingsRetriever;
import fr.xephi.authme.util.StringUtils;
import org.bukkit.configuration.MemorySection;
import org.bukkit.configuration.file.FileConfiguration;
import org.bukkit.configuration.file.YamlConfiguration;
@@ -54,7 +53,7 @@ public class ConfigFileConsistencyTest {
missingProperties.add(path);
}
}
fail("Found missing properties!\n-" + StringUtils.join("\n-", missingProperties));
fail("Found missing properties!\n-" + String.join("\n-", missingProperties));
}
}
@@ -78,7 +77,7 @@ public class ConfigFileConsistencyTest {
// then
if (!unknownPaths.isEmpty()) {
fail("Found " + unknownPaths.size() + " unknown property paths in the project's config.yml: \n- "
+ StringUtils.join("\n- ", unknownPaths));
+ String.join("\n- ", unknownPaths));
}
}
@@ -5,8 +5,6 @@ import org.junit.Test;
import java.io.File;
import java.net.MalformedURLException;
import java.util.Arrays;
import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.greaterThan;
@@ -65,51 +63,6 @@ public class StringUtilsTest {
assertFalse(StringUtils.isEmpty(" test"));
}
@Test
public void shouldJoinStrings() {
// 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 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
List<String> elements = Arrays.asList(" ", null, "\t", "hello", null);
// when
String result = StringUtils.join("-", elements);
// then
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