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