From c8565e1ce5a258b97cce9bdb5f3e53af2ee80f44 Mon Sep 17 00:00:00 2001 From: ljacqu Date: Sun, 4 Sep 2016 22:36:36 +0200 Subject: [PATCH] Minor - replace our BiConsumer interface in test with Java 8's --- .../command/CommandInitializerTest.java | 51 +++++++++---------- .../AbstractDataSourceConverterTest.java | 3 +- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java index 669f71d85..d5db0c550 100644 --- a/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandInitializerTest.java @@ -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 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 connectionTester = new BiConsumer() { @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 labelFormatTester = new BiConsumer() { @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 commandMappings = new HashSet<>(); - BiConsumer uniqueMappingTester = new BiConsumer() { + BiConsumer uniqueMappingTester = new BiConsumer() { @Override - public void accept(CommandDescription command, int depth) { + public void accept(CommandDescription command, Integer depth) { int initialSize = commandMappings.size(); List newMappings = getAbsoluteLabels(command); commandMappings.addAll(newMappings); @@ -136,9 +133,9 @@ public class CommandInitializerTest { @Test public void shouldHaveProperDescription() { // given - BiConsumer descriptionTester = new BiConsumer() { + BiConsumer descriptionTester = new BiConsumer() { @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 argumentOrderTester = new BiConsumer() { @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 noArgumentForParentChecker = new BiConsumer() { @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 adminPermissionChecker = new BiConsumer() { @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, Integer> mandatoryArguments = new HashMap<>(); final Map, Integer> totalArguments = new HashMap<>(); - BiConsumer argChecker = new BiConsumer() { + BiConsumer argChecker = new BiConsumer() { @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 commands, BiConsumer consumer) { + private static void walkThroughCommands(Collection commands, + BiConsumer consumer) { walkThroughCommands(commands, consumer, 0); } - private static void walkThroughCommands(Collection commands, BiConsumer consumer, int depth) { + private static void walkThroughCommands(Collection commands, + BiConsumer 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. diff --git a/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java b/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java index 00af5d979..b8378c1ee 100644 --- a/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java +++ b/src/test/java/fr/xephi/authme/converter/AbstractDataSourceConverterTest.java @@ -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 converter = Mockito.spy(new DataSourceConverterTestImpl<>(source, destination, destinationType)); doThrow(IllegalStateException.class).when(converter).getSource(); CommandSender sender = mock(CommandSender.class);