Trivial code householding
- Replace `if (!x) ... else ...` with `if(x) ... else ...` - Avoid throwing RuntimeException; use children
This commit is contained in:
@@ -22,6 +22,7 @@ import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertSame;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Matchers.any;
|
||||
@@ -187,12 +188,12 @@ public class CommandInitializerTest {
|
||||
assertThat(command.getExecutableCommand(), not(nullValue()));
|
||||
ExecutableCommand commandExec = command.getExecutableCommand();
|
||||
ExecutableCommand storedExec = implementations.get(command.getExecutableCommand().getClass());
|
||||
if (storedExec != null) {
|
||||
assertThat("has same implementation of '" + storedExec.getClass().getName() + "' for command with "
|
||||
+ "parent " + (command.getParent() == null ? "null" : command.getParent().getLabels()),
|
||||
storedExec == commandExec, equalTo(true));
|
||||
} else {
|
||||
if (storedExec == null) {
|
||||
implementations.put(commandExec.getClass(), commandExec);
|
||||
} else {
|
||||
assertSame("has same implementation of '" + storedExec.getClass().getName() + "' for command with "
|
||||
+ "parent " + (command.getParent() == null ? "null" : command.getParent().getLabels()),
|
||||
storedExec, commandExec);
|
||||
}
|
||||
}
|
||||
};
|
||||
@@ -211,7 +212,7 @@ public class CommandInitializerTest {
|
||||
for (CommandArgumentDescription argument : command.getArguments()) {
|
||||
if (argument.isOptional()) {
|
||||
encounteredOptionalArg = true;
|
||||
} else if (!argument.isOptional() && encounteredOptionalArg) {
|
||||
} else if (encounteredOptionalArg) {
|
||||
fail("Mandatory arguments should come before optional ones for command with labels '"
|
||||
+ command.getLabels() + "'");
|
||||
}
|
||||
@@ -256,11 +257,10 @@ public class CommandInitializerTest {
|
||||
@Override
|
||||
public void accept(CommandDescription command, int depth) {
|
||||
CommandPermissions permissions = command.getCommandPermissions();
|
||||
if (permissions != null && OP_ONLY.equals(permissions.getDefaultPermission())) {
|
||||
if (!hasAdminNode(permissions)) {
|
||||
fail("The command with labels " + command.getLabels() + " has OP_ONLY default "
|
||||
+ "permission but no permission node on admin level");
|
||||
}
|
||||
if (permissions != null && OP_ONLY.equals(permissions.getDefaultPermission())
|
||||
&& !hasAdminNode(permissions)) {
|
||||
fail("The command with labels " + command.getLabels() + " has OP_ONLY default "
|
||||
+ "permission but no permission node on admin level");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,13 +298,13 @@ public class CommandInitializerTest {
|
||||
Map<Class<? extends ExecutableCommand>, Integer> collection) {
|
||||
final Class<? extends ExecutableCommand> clazz = command.getExecutableCommand().getClass();
|
||||
Integer existingCount = collection.get(clazz);
|
||||
if (existingCount != null) {
|
||||
if (existingCount == null) {
|
||||
collection.put(clazz, argCount);
|
||||
} else {
|
||||
String commandDescription = "Command with label '" + command.getLabels().get(0) + "' and parent '"
|
||||
+ (command.getParent() != null ? command.getLabels().get(0) : "null") + "' ";
|
||||
+ (command.getParent() == null ? "null" : command.getLabels().get(0)) + "' ";
|
||||
assertThat(commandDescription + "should point to " + clazz + " with arguments consistent to others",
|
||||
argCount, equalTo(existingCount));
|
||||
} else {
|
||||
collection.put(clazz, argCount);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -6,7 +6,6 @@ import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@@ -52,7 +51,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldMapPartsToLoginChildCommand() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "login", "test1");
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -71,7 +70,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldMapPartsToCommandWithNoCaseSensitivity() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("Authme", "REG", "arg1", "arg2");
|
||||
List<String> parts = asList("Authme", "REG", "arg1", "arg2");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -89,7 +88,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldRejectCommandWithTooManyArguments() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "register", "pass123", "pass123", "pass123");
|
||||
List<String> parts = asList("authme", "register", "pass123", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -107,7 +106,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldRejectCommandWithTooFewArguments() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "Reg");
|
||||
List<String> parts = asList("authme", "Reg");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -125,7 +124,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldSuggestCommandWithSimilarLabel() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "reh", "pass123", "pass123");
|
||||
List<String> parts = asList("authme", "reh", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -144,7 +143,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldSuggestMostSimilarCommand() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "asdfawetawty4asdca");
|
||||
List<String> parts = asList("authme", "asdfawetawty4asdca");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(true);
|
||||
|
||||
@@ -259,7 +258,7 @@ public class CommandMapperTest {
|
||||
@Test
|
||||
public void shouldRecognizeMissingPermissionForCommand() {
|
||||
// given
|
||||
List<String> parts = Arrays.asList("authme", "login", "test1");
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(CommandDescription.class))).willReturn(false);
|
||||
|
||||
|
||||
@@ -85,11 +85,11 @@ public final class TestCommandsUtil {
|
||||
private static CommandDescription createCommand(PermissionNode permission, CommandDescription parent,
|
||||
List<String> labels, CommandArgumentDescription... arguments) {
|
||||
PermissionNode[] notNullPermission;
|
||||
if (permission != null) {
|
||||
if (permission == null) {
|
||||
notNullPermission = new PermissionNode[0];
|
||||
} else {
|
||||
notNullPermission = new PermissionNode[1];
|
||||
notNullPermission[0] = permission;
|
||||
} else {
|
||||
notNullPermission = new PermissionNode[0];
|
||||
}
|
||||
|
||||
CommandDescription.CommandBuilder command = CommandDescription.builder()
|
||||
|
||||
Reference in New Issue
Block a user