mirror of
https://github.com/AuthMe/AuthMeReloaded.git
synced 2024-11-03 09:10:01 +01:00
Minor - replace our BiConsumer interface in test with Java 8's
This commit is contained in:
parent
80ee018cc3
commit
c8565e1ce5
@ -13,6 +13,7 @@ import java.util.HashSet;
|
|||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.BiConsumer;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
import static fr.xephi.authme.permission.DefaultPermission.OP_ONLY;
|
||||||
@ -54,12 +55,8 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldNotBeNestedExcessively() {
|
public void shouldNotBeNestedExcessively() {
|
||||||
// given
|
// given
|
||||||
BiConsumer descriptionTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> descriptionTester =
|
||||||
@Override
|
(command, depth) -> assertThat(depth <= MAX_ALLOWED_DEPTH, equalTo(true));
|
||||||
public void accept(CommandDescription command, int depth) {
|
|
||||||
assertThat(depth <= MAX_ALLOWED_DEPTH, equalTo(true));
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// when/then
|
// when/then
|
||||||
walkThroughCommands(commands, descriptionTester);
|
walkThroughCommands(commands, descriptionTester);
|
||||||
@ -69,9 +66,9 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveConnectionBetweenParentAndChild() {
|
public void shouldHaveConnectionBetweenParentAndChild() {
|
||||||
// given
|
// given
|
||||||
BiConsumer connectionTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> connectionTester = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
if (!command.getChildren().isEmpty()) {
|
if (!command.getChildren().isEmpty()) {
|
||||||
for (CommandDescription child : command.getChildren()) {
|
for (CommandDescription child : command.getChildren()) {
|
||||||
assertThat(command.equals(child.getParent()), equalTo(true));
|
assertThat(command.equals(child.getParent()), equalTo(true));
|
||||||
@ -91,9 +88,9 @@ public class CommandInitializerTest {
|
|||||||
public void shouldUseProperLowerCaseLabels() {
|
public void shouldUseProperLowerCaseLabels() {
|
||||||
// given
|
// given
|
||||||
final Pattern invalidPattern = Pattern.compile("\\s");
|
final Pattern invalidPattern = Pattern.compile("\\s");
|
||||||
BiConsumer labelFormatTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> labelFormatTester = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
for (String label : command.getLabels()) {
|
for (String label : command.getLabels()) {
|
||||||
if (!label.equals(label.toLowerCase())) {
|
if (!label.equals(label.toLowerCase())) {
|
||||||
fail("Label '" + label + "' should be lowercase");
|
fail("Label '" + label + "' should be lowercase");
|
||||||
@ -112,9 +109,9 @@ public class CommandInitializerTest {
|
|||||||
public void shouldNotDefineSameLabelTwice() {
|
public void shouldNotDefineSameLabelTwice() {
|
||||||
// given
|
// given
|
||||||
final Set<String> commandMappings = new HashSet<>();
|
final Set<String> commandMappings = new HashSet<>();
|
||||||
BiConsumer uniqueMappingTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> uniqueMappingTester = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
int initialSize = commandMappings.size();
|
int initialSize = commandMappings.size();
|
||||||
List<String> newMappings = getAbsoluteLabels(command);
|
List<String> newMappings = getAbsoluteLabels(command);
|
||||||
commandMappings.addAll(newMappings);
|
commandMappings.addAll(newMappings);
|
||||||
@ -136,9 +133,9 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveProperDescription() {
|
public void shouldHaveProperDescription() {
|
||||||
// given
|
// given
|
||||||
BiConsumer descriptionTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> descriptionTester = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
String forCommandText = " for command with labels '" + command.getLabels() + "'";
|
String forCommandText = " for command with labels '" + command.getLabels() + "'";
|
||||||
|
|
||||||
assertThat("has description" + forCommandText,
|
assertThat("has description" + forCommandText,
|
||||||
@ -159,9 +156,9 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldHaveOptionalArgumentsAfterMandatoryOnes() {
|
public void shouldHaveOptionalArgumentsAfterMandatoryOnes() {
|
||||||
// given
|
// given
|
||||||
BiConsumer argumentOrderTester = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> argumentOrderTester = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
boolean encounteredOptionalArg = false;
|
boolean encounteredOptionalArg = false;
|
||||||
for (CommandArgumentDescription argument : command.getArguments()) {
|
for (CommandArgumentDescription argument : command.getArguments()) {
|
||||||
if (argument.isOptional()) {
|
if (argument.isOptional()) {
|
||||||
@ -185,9 +182,9 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldNotHaveArgumentsIfCommandHasChildren() {
|
public void shouldNotHaveArgumentsIfCommandHasChildren() {
|
||||||
// given
|
// given
|
||||||
BiConsumer noArgumentForParentChecker = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> noArgumentForParentChecker = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
// Fail if the command has children and has arguments at the same time
|
// Fail if the command has children and has arguments at the same time
|
||||||
// Exception: If the parent only has one child defining the help label, it is acceptable
|
// Exception: If the parent only has one child defining the help label, it is acceptable
|
||||||
if (!command.getChildren().isEmpty() && !command.getArguments().isEmpty()
|
if (!command.getChildren().isEmpty() && !command.getArguments().isEmpty()
|
||||||
@ -207,9 +204,9 @@ public class CommandInitializerTest {
|
|||||||
@Test
|
@Test
|
||||||
public void shouldNotHavePlayerPermissionIfDefaultsToOpOnly() {
|
public void shouldNotHavePlayerPermissionIfDefaultsToOpOnly() {
|
||||||
// given
|
// given
|
||||||
BiConsumer adminPermissionChecker = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> adminPermissionChecker = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
PermissionNode permission = command.getPermission();
|
PermissionNode permission = command.getPermission();
|
||||||
if (permission != null && OP_ONLY.equals(permission.getDefaultPermission())
|
if (permission != null && OP_ONLY.equals(permission.getDefaultPermission())
|
||||||
&& !hasAdminNode(permission)) {
|
&& !hasAdminNode(permission)) {
|
||||||
@ -237,9 +234,9 @@ public class CommandInitializerTest {
|
|||||||
final Map<Class<? extends ExecutableCommand>, Integer> mandatoryArguments = new HashMap<>();
|
final Map<Class<? extends ExecutableCommand>, Integer> mandatoryArguments = new HashMap<>();
|
||||||
final Map<Class<? extends ExecutableCommand>, Integer> totalArguments = new HashMap<>();
|
final Map<Class<? extends ExecutableCommand>, Integer> totalArguments = new HashMap<>();
|
||||||
|
|
||||||
BiConsumer argChecker = new BiConsumer() {
|
BiConsumer<CommandDescription, Integer> argChecker = new BiConsumer<CommandDescription, Integer>() {
|
||||||
@Override
|
@Override
|
||||||
public void accept(CommandDescription command, int depth) {
|
public void accept(CommandDescription command, Integer depth) {
|
||||||
testCollectionForCommand(command, CommandUtils.getMinNumberOfArguments(command), mandatoryArguments);
|
testCollectionForCommand(command, CommandUtils.getMinNumberOfArguments(command), mandatoryArguments);
|
||||||
testCollectionForCommand(command, CommandUtils.getMaxNumberOfArguments(command), totalArguments);
|
testCollectionForCommand(command, CommandUtils.getMaxNumberOfArguments(command), totalArguments);
|
||||||
}
|
}
|
||||||
@ -266,11 +263,13 @@ public class CommandInitializerTest {
|
|||||||
// ------------
|
// ------------
|
||||||
// Helper methods
|
// Helper methods
|
||||||
// ------------
|
// ------------
|
||||||
private static void walkThroughCommands(Collection<CommandDescription> commands, BiConsumer consumer) {
|
private static void walkThroughCommands(Collection<CommandDescription> commands,
|
||||||
|
BiConsumer<CommandDescription, Integer> consumer) {
|
||||||
walkThroughCommands(commands, consumer, 0);
|
walkThroughCommands(commands, consumer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void walkThroughCommands(Collection<CommandDescription> commands, BiConsumer consumer, int depth) {
|
private static void walkThroughCommands(Collection<CommandDescription> commands,
|
||||||
|
BiConsumer<CommandDescription, Integer> consumer, int depth) {
|
||||||
for (CommandDescription command : commands) {
|
for (CommandDescription command : commands) {
|
||||||
consumer.accept(command, depth);
|
consumer.accept(command, depth);
|
||||||
if (!command.getChildren().isEmpty()) {
|
if (!command.getChildren().isEmpty()) {
|
||||||
@ -288,10 +287,6 @@ public class CommandInitializerTest {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private interface BiConsumer {
|
|
||||||
void accept(CommandDescription command, int depth);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get the absolute binding that a command defines. Note: Assumes that only the passed command can have
|
* Get the absolute binding that a command defines. Note: Assumes that only the passed command can have
|
||||||
* multiple labels; only considering the first label for all of the command's parents.
|
* multiple labels; only considering the first label for all of the command's parents.
|
||||||
|
@ -54,7 +54,6 @@ public class AbstractDataSourceConverterTest {
|
|||||||
verifyZeroInteractions(source);
|
verifyZeroInteractions(source);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("rawtypes")
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldHandleSourceThrowingException() {
|
public void shouldHandleSourceThrowingException() {
|
||||||
// given
|
// given
|
||||||
@ -62,7 +61,7 @@ public class AbstractDataSourceConverterTest {
|
|||||||
DataSource destination = mock(DataSource.class);
|
DataSource destination = mock(DataSource.class);
|
||||||
DataSourceType destinationType = DataSourceType.SQLITE;
|
DataSourceType destinationType = DataSourceType.SQLITE;
|
||||||
given(destination.getType()).willReturn(destinationType);
|
given(destination.getType()).willReturn(destinationType);
|
||||||
DataSourceConverterTestImpl converter =
|
DataSourceConverterTestImpl<DataSource> converter =
|
||||||
Mockito.spy(new DataSourceConverterTestImpl<>(source, destination, destinationType));
|
Mockito.spy(new DataSourceConverterTestImpl<>(source, destination, destinationType));
|
||||||
doThrow(IllegalStateException.class).when(converter).getSource();
|
doThrow(IllegalStateException.class).when(converter).getSource();
|
||||||
CommandSender sender = mock(CommandSender.class);
|
CommandSender sender = mock(CommandSender.class);
|
||||||
|
Loading…
Reference in New Issue
Block a user