Skip to content

Commit

Permalink
Use Java 11 functionality where possible (#689)
Browse files Browse the repository at this point in the history
  • Loading branch information
basil authored Mar 9, 2023
1 parent f5d38ca commit a1c684a
Show file tree
Hide file tree
Showing 18 changed files with 26 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.apache.maven.repository.internal.MavenRepositorySystemUtils;
import org.eclipse.aether.DefaultRepositorySystemSession;
Expand Down Expand Up @@ -34,7 +33,7 @@ public class ArtifactTransporter {

public ArtifactTransporter(Path localRepositoryLocation, RemoteRepository... remoteLocations) {
this.localRepositoryLocation = localRepositoryLocation;
this.remoteLocations = Arrays.asList(remoteLocations);
this.remoteLocations = List.of(remoteLocations);

// todo: proxies: https://github.com/jenkinsci/acceptance-test-harness/blob/b27c150f35a386dfced4a5960127bf62f9c34363/src/main/java/org/jenkinsci/test/acceptance/utils/aether/ArtifactResolverUtil.java
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static net.serenitybdd.screenplay.Tasks.instrumented;

import com.smartcodeltd.jenkinsci.plugins.build_monitor.tasks.configuration.SaveTheChangesToBuildMonitor;
import java.util.Arrays;
import java.util.List;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
Expand All @@ -14,7 +13,7 @@
public class ConfigureEmptyBuildMonitorView implements Task {

public static ConfigureEmptyBuildMonitorView to(Task... configurationTasks) {
return instrumented(ConfigureEmptyBuildMonitorView.class, Arrays.asList(configurationTasks));
return instrumented(ConfigureEmptyBuildMonitorView.class, List.of(configurationTasks));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static net.serenitybdd.screenplay.Tasks.instrumented;

import com.smartcodeltd.jenkinsci.plugins.build_monitor.user_interface.BuildMonitorDashboard;
import java.util.Arrays;
import java.util.List;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
Expand All @@ -15,7 +14,7 @@
public class ModifyControlPanelOptions implements Task {

public static ModifyControlPanelOptions to(Task... configurationTasks) {
return instrumented(ModifyControlPanelOptions.class, Arrays.asList(configurationTasks));
return instrumented(ModifyControlPanelOptions.class, List.of(configurationTasks));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static net.serenitybdd.screenplay.Tasks.instrumented;

import com.sonyericsson.jenkins.plugins.bfa.user_interface.JenkinsHomePageWithBFA;
import java.util.Arrays;
import java.util.List;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Task;
Expand All @@ -14,7 +13,7 @@

public class UseFailureCauseManagement implements Task {
public static UseFailureCauseManagement to(Task... defineFailureCauses) {
return instrumented(UseFailureCauseManagement.class, Arrays.asList(defineFailureCauses));
return instrumented(UseFailureCauseManagement.class, List.of(defineFailureCauses));
}

@Step("{0} uses the 'Failure Cause Management'")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package net.serenitybdd.integration.jenkins;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.serenitybdd.integration.jenkins.environment.rules.ApplicativeTestRule;

Expand All @@ -20,11 +19,11 @@ public JenkinsInstance create() {
}

public <ATR extends ApplicativeTestRule<JenkinsInstance>> TestEnvironment beforeStart(ATR... rules) {
return beforeStart(Arrays.asList(rules));
return beforeStart(List.of(rules));
}

public <ATR extends ApplicativeTestRule<JenkinsInstance>> TestEnvironment afterStart(ATR... rules) {
return afterStart(Arrays.asList(rules));
return afterStart(List.of(rules));
}

public <ATR extends ApplicativeTestRule<JenkinsInstance>> TestEnvironment beforeStart(List<ATR> rules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.regex.Matcher;
import net.serenitybdd.integration.jenkins.process.JenkinsProcess;
Expand Down Expand Up @@ -164,8 +163,8 @@ private int executeCommand(String... args) {
//TODO use RealJenkinsRule
//return executor.call(args).execute(noManualInput(), info(logger), error(logger));
try {
List<String> cliArgs = new ArrayList<>(Arrays.asList("-s", jenkinsUrl.toString(), "-http"));
cliArgs.addAll(Arrays.asList(args));
List<String> cliArgs = new ArrayList<>(List.of("-s", jenkinsUrl.toString(), "-http"));
cliArgs.addAll(List.of(args));

return CLI._main(cliArgs.toArray(new String[0]));
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand All @@ -24,7 +23,7 @@ public class UpdateCenter {
= "https://updates.jenkins.io/update-center.json?version=%s";
private final Path tempDir;

private List<Version> jenkinsLTSVersions = Arrays.asList(
private List<Version> jenkinsLTSVersions = List.of(
Version.valueOf("2.375.4"),
Version.valueOf("2.375.3"),
Version.valueOf("2.375.2"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.StandardCopyOption;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import net.serenitybdd.integration.jenkins.JenkinsInstance;
Expand All @@ -23,7 +22,7 @@ public class InstallPluginsFromDisk implements ApplicativeTestRule<JenkinsInstan

public InstallPluginsFromDisk(Path... pluginsToInstall) {
this.pluginIDs = List.of();
this.pluginsToInstall = Arrays.asList(pluginsToInstall);
this.pluginsToInstall = List.of(pluginsToInstall);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import java.io.IOException;
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -114,7 +113,7 @@ public void stop() {

private ProcessBuilder process(Path executable, String... arguments) {
List<String> args = new ArrayList<>(windowsOrUnix(executable));
args.addAll(Arrays.asList(arguments));
args.addAll(List.of(arguments));

return new ProcessBuilder(args);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package net.serenitybdd.integration.utils;

import java.util.Arrays;
import java.util.List;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;

public class RuleChains {
public static RuleChain from(TestRule... rules) {
return from(Arrays.asList(rules));
return from(List.of(rules));
}

private static RuleChain from(List<TestRule> testRules) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import static net.serenitybdd.screenplay.Tasks.instrumented;

import java.util.Arrays;
import java.util.List;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Interaction;
Expand All @@ -13,7 +12,7 @@

public class EnterCode {
public static EnterCode asFollows(String... lines) {
return new EnterCode(Arrays.asList(lines));
return new EnterCode(List.of(lines));
}

public Interaction intoTheCodeMirror(Target editorField) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import static net.serenitybdd.screenplay.Tasks.instrumented;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import net.serenitybdd.screenplay.Actor;
import net.serenitybdd.screenplay.Performable;
Expand All @@ -21,7 +20,7 @@ public <T extends Performable> TodoList add(T task) {
}

public <T extends Performable> TodoList addAll(T... tasks) {
todos.addAll(Arrays.asList(tasks));
todos.addAll(List.of(tasks));

return this;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class GroovyScript {

Expand All @@ -17,7 +17,7 @@ public GroovyScript separatedBy(String lineSeparator) {
}

public GroovyScript definedAs(String... lines) {
return this.definedAs(Arrays.asList(lines));
return this.definedAs(List.of(lines));
}

public GroovyScript definedAs(List<String> lines) {
Expand All @@ -27,7 +27,7 @@ public GroovyScript definedAs(List<String> lines) {
}

public GroovyScript andOutputs(String... lines) {
return definedAs(Arrays.stream(lines).map(line -> String.format("echo \"%s\";", line)).collect(Collectors.toList()));
return definedAs(Stream.of(lines).map(line -> String.format("echo \"%s\";", line)).collect(Collectors.toList()));
}

public String code() {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package net.serenitybdd.screenplay.jenkins.tasks.configuration.build_steps;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class ShellScript {

Expand All @@ -11,7 +11,7 @@ public static ShellScript that(String descriptionOfScriptsBehaviour) {
}

public ShellScript definedAs(String... lines) {
return this.definedAs(Arrays.asList(lines));
return this.definedAs(List.of(lines));
}

public ShellScript definedAs(List<String> lines) {
Expand All @@ -21,7 +21,7 @@ public ShellScript definedAs(List<String> lines) {
}

public ShellScript andOutputs(String... lines) {
return definedAs(Arrays.stream(lines).map(line -> String.format("echo \"%s\";", line)).collect(Collectors.toList()));
return definedAs(Stream.of(lines).map(line -> String.format("echo \"%s\";", line)).collect(Collectors.toList()));
}

public String code() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.containsInAnyOrder;

import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import org.junit.Test;
Expand Down Expand Up @@ -55,7 +54,7 @@ private static class TestNode {
TestNode(String displayName, Type type, TestNode[] parents) {
this.displayName = displayName;
this.type = type;
this.parents = Arrays.asList(parents);
this.parents = List.of(parents);
}

String getDisplayName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import static org.hamcrest.core.Is.is;

import com.smartcodeltd.jenkinsci.plugins.buildmonitor.readability.Lister;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;

Expand Down Expand Up @@ -46,6 +45,6 @@ public void should_allow_to_use_a_different_template_to_describe_a_list_with_one
}

private <T> List<T> listOf(T... items) {
return Arrays.asList(items);
return List.of(items);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import com.smartcodeltd.jenkinsci.plugins.buildmonitor.viewmodel.features.Feature;
import hudson.model.Job;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.function.Supplier;
Expand All @@ -24,7 +23,7 @@ public JobViewRecipe of(Job<?, ?> job) {
}

public JobViewRecipe which(Feature... features) {
this.features = Arrays.asList(features);
this.features = List.of(features);
return this;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import java.util.List;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import java.util.stream.Stream;

/**
* @author Jan Molak
Expand All @@ -15,7 +16,7 @@ public static <T> List<T> asFollows(T... examples) {
}

public static <T> List<T> asFollows(Supplier<T>... examples) {
return Arrays.stream(examples).map(Supplier::get).collect(Collectors.toList());
return Stream.of(examples).map(Supplier::get).collect(Collectors.toList());
}

}
}

0 comments on commit a1c684a

Please sign in to comment.