diff --git a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/CargoArgsTest.java b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/CargoArgsTest.java index 1308d595..8eff2749 100644 --- a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/CargoArgsTest.java +++ b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/CargoArgsTest.java @@ -1,5 +1,5 @@ /********************************************************************* - * Copyright (c) 2019 Fraunhofer FOKUS and others. + * Copyright (c) 2019, 2021 Fraunhofer FOKUS and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -21,64 +21,60 @@ import org.junit.jupiter.api.Test; -public class CargoArgsTest { +class CargoArgsTest { private static final String SEPARATOR = "--"; @Test - public void testOnlyCommand() { + void testOnlyCommand() { String command = "fmt"; - String[] input = { command }; - CargoArgs result = CargoArgs.fromAllArguments(input); + CargoArgs result = CargoArgs.fromAllArguments(command); assertEquals(command, result.command); assertTrue(result.arguments.isEmpty()); assertTrue(result.options.isEmpty()); } @Test - public void testOnlyCommandAndSeparator() { + void testOnlyCommandAndSeparator() { String command = "fmt"; - String[] input = { command, SEPARATOR }; - CargoArgs result = CargoArgs.fromAllArguments(input); + CargoArgs result = CargoArgs.fromAllArguments(command, SEPARATOR); assertEquals(command, result.command); assertTrue(result.arguments.isEmpty()); assertTrue(result.options.isEmpty()); } @Test - public void testOnlyCommandAndOptions() { + void testOnlyCommandAndOptions() { String command = "build"; String opt1 = "--all"; String opt2 = "--release"; - String[] input = { command, opt1, opt2 }; - CargoArgs result = CargoArgs.fromAllArguments(input); + CargoArgs result = CargoArgs.fromAllArguments(command, opt1, opt2); assertEquals(command, result.command); assertEquals(Arrays.asList(opt1, opt2), result.options); assertTrue(result.arguments.isEmpty()); } @Test - public void testOnlyCommandAndOptionsAndSeparator() { + void testOnlyCommandAndOptionsAndSeparator() { String command = "build"; String opt1 = "--all"; String opt2 = "--release"; - String[] input = { command, opt1, opt2, SEPARATOR }; - CargoArgs result = CargoArgs.fromAllArguments(input); + CargoArgs result = CargoArgs.fromAllArguments(command, opt1, opt2, SEPARATOR); assertEquals(command, result.command); assertEquals(Arrays.asList(opt1, opt2), result.options); assertTrue(result.arguments.isEmpty()); } @Test - public void testOnlyCommandAndArguments() { + void testOnlyCommandAndArguments() { String command = "build"; - List arguments = Arrays.asList("--nocapture", "my_test"); + List arguments = List.of("--nocapture", "my_test"); List all_arguments = new ArrayList<>(); all_arguments.add(command); all_arguments.add(SEPARATOR); all_arguments.addAll(arguments); - String[] input = all_arguments.toArray(new String[] {}); + String[] input = all_arguments.toArray(String[]::new); CargoArgs result = CargoArgs.fromAllArguments(input); @@ -88,17 +84,17 @@ public void testOnlyCommandAndArguments() { } @Test - public void testOnlyCommandAndOptionsAndArguments() { + void testOnlyCommandAndOptionsAndArguments() { String command = "build"; - List options = Arrays.asList("--all", "--release"); - List arguments = Arrays.asList("--nocapture", "my_test"); + List options = List.of("--all", "--release"); + List arguments = List.of("--nocapture", "my_test"); List all_arguments = new ArrayList<>(); all_arguments.add(command); all_arguments.addAll(options); all_arguments.add(SEPARATOR); all_arguments.addAll(arguments); - String[] input = all_arguments.toArray(new String[] {}); + String[] input = all_arguments.toArray(String[]::new); CargoArgs result = CargoArgs.fromAllArguments(input); @@ -108,17 +104,17 @@ public void testOnlyCommandAndOptionsAndArguments() { } @Test - public void testOnlyCommandAndOptionsAndArgumentsIncludingSeparator() { + void testOnlyCommandAndOptionsAndArgumentsIncludingSeparator() { String command = "build"; - List options = Arrays.asList("--all", "--release"); - List arguments = Arrays.asList("--nocapture", SEPARATOR, "my_test"); + List options = List.of("--all", "--release"); + List arguments = List.of("--nocapture", SEPARATOR, "my_test"); List all_arguments = new ArrayList<>(); all_arguments.add(command); all_arguments.addAll(options); all_arguments.add(SEPARATOR); all_arguments.addAll(arguments); - String[] input = all_arguments.toArray(new String[] {}); + String[] input = all_arguments.toArray(String[]::new); CargoArgs result = CargoArgs.fromAllArguments(input); diff --git a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/RLSRunCommandTest.java b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/RLSRunCommandTest.java index f7ba52d4..529701f4 100644 --- a/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/RLSRunCommandTest.java +++ b/org.eclipse.corrosion.tests/src/org/eclipse/corrosion/launch/RLSRunCommandTest.java @@ -30,7 +30,7 @@ import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -public class RLSRunCommandTest { +class RLSRunCommandTest { private static final String TITLE = "Run test"; private static final String COMMAND_ID = "rls.run"; @@ -53,21 +53,21 @@ static Stream parameters() { @ParameterizedTest @MethodSource("parameters") - public void testMapEntryArgument(Map argument) { + void testMapEntryArgument(Map argument) { Command command = new Command(TITLE, COMMAND_ID, Arrays.asList(argument)); Optional lspCommand = RLSRunCommand.fromLSPCommand(command); assertFalse(lspCommand.isPresent()); } @Test - public void testNoArgument() { + void testNoArgument() { Command command = new Command(TITLE, COMMAND_ID, Arrays.asList()); Optional lspCommand = RLSRunCommand.fromLSPCommand(command); assertFalse(lspCommand.isPresent()); } @Test - public void testArgumentListNull() { + void testArgumentListNull() { Command command = new Command(TITLE, COMMAND_ID, null); Optional lspCommand = RLSRunCommand.fromLSPCommand(command); assertFalse(lspCommand.isPresent()); @@ -81,7 +81,7 @@ public void testArgumentListWrongEntry() { } @Test - public void testEmptyArguments() { + void testEmptyArguments() { Command command = new Command(TITLE, COMMAND_ID, Arrays.asList(createArgument(VALID_BINARY, EMPTY_ARGS, EMPTY_ENV))); Optional lspCommand = RLSRunCommand.fromLSPCommand(command); @@ -93,7 +93,7 @@ public void testEmptyArguments() { } @Test - public void testValidArguments() { + void testValidArguments() { Command command = new Command(TITLE, COMMAND_ID, Arrays.asList(createArgument(VALID_BINARY, VALID_ARGS, VALID_ENV))); Optional lspCommand = RLSRunCommand.fromLSPCommand(command); @@ -105,7 +105,7 @@ public void testValidArguments() { } @Test - public void testInvalidEnvEntry() { + void testInvalidEnvEntry() { Map env = new HashMap<>(); env.put("INVALID", null); env.put("RUST_BACKTRACE", "short"); diff --git a/org.eclipse.corrosion/src/org/eclipse/corrosion/launch/CargoArgs.java b/org.eclipse.corrosion/src/org/eclipse/corrosion/launch/CargoArgs.java index d323d7ca..2e8a723b 100644 --- a/org.eclipse.corrosion/src/org/eclipse/corrosion/launch/CargoArgs.java +++ b/org.eclipse.corrosion/src/org/eclipse/corrosion/launch/CargoArgs.java @@ -1,5 +1,5 @@ /********************************************************************* - * Copyright (c) 2019 Fraunhofer FOKUS and others. + * Copyright (c) 2019, 2021 Fraunhofer FOKUS and others. * * This program and the accompanying materials are made * available under the terms of the Eclipse Public License 2.0 @@ -21,7 +21,7 @@ * "test" or "run"), the options (flags for the command) and arguments (to be * passed to the executable called by cargo). Instances of this class can be * created via the static factory method - * {@link CargoArgs#fromAllArguments(String[])}. + * {@link CargoArgs#fromAllArguments(String...)}. */ class CargoArgs { public final List options; @@ -53,7 +53,7 @@ private CargoArgs(List options, List arguments, String command) * @param args all arguments after a sub-command (e.g. ) * @return instance of {@code CargoArgs} holding command, options and arguments */ - public static CargoArgs fromAllArguments(String[] args) { + public static CargoArgs fromAllArguments(String... args) { String resultCommand = ""; //$NON-NLS-1$ List resultOptions = Collections.emptyList(); @@ -84,5 +84,4 @@ public static CargoArgs fromAllArguments(String[] args) { } return new CargoArgs(resultOptions, resultArguments, resultCommand); } - // foo } \ No newline at end of file