Use lambdas when possible

Replace anonymous inner classes with lambda declarations (when possible
using method references).

See gh-9781
This commit is contained in:
Emanuel Campolo
2017-07-24 23:11:47 -07:00
committed by Phillip Webb
parent d16af43664
commit 2626a3a795
150 changed files with 983 additions and 2596 deletions

View File

@@ -36,14 +36,7 @@ public interface FieldValuesParser {
/**
* Implementation of {@link FieldValuesParser} that always returns an empty result.
*/
FieldValuesParser NONE = new FieldValuesParser() {
@Override
public Map<String, Object> getFieldValues(TypeElement element) {
return Collections.emptyMap();
}
};
FieldValuesParser NONE = (element) -> Collections.emptyMap();
/**
* Return the field values for the given element.

View File

@@ -110,12 +110,7 @@ public class JarWriter implements LoaderClassesWriter, AutoCloseable {
*/
public void writeManifest(final Manifest manifest) throws IOException {
JarArchiveEntry entry = new JarArchiveEntry("META-INF/MANIFEST.MF");
writeEntry(entry, new EntryWriter() {
@Override
public void write(OutputStream outputStream) throws IOException {
manifest.write(outputStream);
}
});
writeEntry(entry, manifest::write);
}
/**

View File

@@ -29,10 +29,7 @@ public interface Libraries {
/**
* Represents no libraries.
*/
Libraries NONE = new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
}
Libraries NONE = (callback) -> {
};
/**

View File

@@ -61,19 +61,17 @@ public abstract class MainClassFinder {
private static final String MAIN_METHOD_NAME = "main";
private static final FileFilter CLASS_FILE_FILTER = new FileFilter() {
@Override
public boolean accept(File file) {
return (file.isFile() && file.getName().endsWith(DOT_CLASS));
}
};
private static final FileFilter CLASS_FILE_FILTER = MainClassFinder::isClassFile;
private static final FileFilter PACKAGE_FOLDER_FILTER = new FileFilter() {
@Override
public boolean accept(File file) {
return file.isDirectory() && !file.getName().startsWith(".");
}
};
private static final FileFilter PACKAGE_FOLDER_FILTER = MainClassFinder::isPackageFolder;
private static boolean isClassFile(File file) {
return file.isFile() && file.getName().endsWith(DOT_CLASS);
}
private static boolean isPackageFolder(File file) {
return file.isDirectory() && !file.getName().startsWith(".");
}
/**
* Find the main class from a given folder.
@@ -82,12 +80,7 @@ public abstract class MainClassFinder {
* @throws IOException if the folder cannot be read
*/
public static String findMainClass(File rootFolder) throws IOException {
return doWithMainClasses(rootFolder, new MainClassCallback<String>() {
@Override
public String doWith(MainClass mainClass) {
return mainClass.getName();
}
});
return doWithMainClasses(rootFolder, MainClass::getName);
}
/**
@@ -163,12 +156,7 @@ public abstract class MainClassFinder {
}
private static void pushAllSorted(Deque<File> stack, File[] files) {
Arrays.sort(files, new Comparator<File>() {
@Override
public int compare(File o1, File o2) {
return o1.getName().compareTo(o2.getName());
}
});
Arrays.sort(files, Comparator.comparing(File::getName));
for (File file : files) {
stack.push(file);
}
@@ -183,13 +171,7 @@ public abstract class MainClassFinder {
*/
public static String findMainClass(JarFile jarFile, String classesLocation)
throws IOException {
return doWithMainClasses(jarFile, classesLocation,
new MainClassCallback<String>() {
@Override
public String doWith(MainClass mainClass) {
return mainClass.getName();
}
});
return doWithMainClasses(jarFile, classesLocation, MainClass::getName);
}
/**

View File

@@ -230,21 +230,16 @@ public class Repackager {
try (JarWriter writer = new JarWriter(destination, launchScript)) {
final List<Library> unpackLibraries = new ArrayList<>();
final List<Library> standardLibraries = new ArrayList<>();
libraries.doWithLibraries(new LibraryCallback() {
@Override
public void library(Library library) throws IOException {
File file = library.getFile();
if (isZip(file)) {
if (library.isUnpackRequired()) {
unpackLibraries.add(library);
}
else {
standardLibraries.add(library);
}
libraries.doWithLibraries((library) -> {
File file = library.getFile();
if (isZip(file)) {
if (library.isUnpackRequired()) {
unpackLibraries.add(library);
}
else {
standardLibraries.add(library);
}
}
});
repackage(sourceJar, writer, unpackLibraries, standardLibraries);
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -87,12 +87,7 @@ public class RunProcess {
if (!inheritedIO) {
redirectOutput(process);
}
SignalUtils.attachSignalHandler(new Runnable() {
@Override
public void run() {
handleSigInt();
}
});
SignalUtils.attachSignalHandler(this::handleSigInt);
if (waitForProcess) {
try {
return process.waitFor();
@@ -154,25 +149,20 @@ public class RunProcess {
private void redirectOutput(Process process) {
final BufferedReader reader = new BufferedReader(
new InputStreamReader(process.getInputStream()));
new Thread() {
@Override
public void run() {
try {
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
System.out.flush();
}
reader.close();
}
catch (Exception ex) {
// Ignore
new Thread(() -> {
try {
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
System.out.flush();
}
reader.close();
}
}.start();
catch (Exception ex) {
// Ignore
}
}).start();
}
/**

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2012-2016 the original author or authors.
* Copyright 2012-2017 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,7 +17,6 @@
package org.springframework.boot.loader.tools;
import sun.misc.Signal;
import sun.misc.SignalHandler;
/**
* Utilities for working with signal handling.
@@ -39,12 +38,7 @@ public final class SignalUtils {
* @param runnable the runnable to call on SIGINT.
*/
public static void attachSignalHandler(final Runnable runnable) {
Signal.handle(SIG_INT, new SignalHandler() {
@Override
public void handle(Signal signal) {
runnable.run();
}
});
Signal.handle(SIG_INT, (signal) -> runnable.run());
}
}

View File

@@ -56,10 +56,7 @@ import static org.mockito.Mockito.mock;
*/
public class RepackagerTests {
private static final Libraries NO_LIBRARIES = new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
}
private static final Libraries NO_LIBRARIES = (callback) -> {
};
private static final long JAN_1_1980;
@@ -301,14 +298,10 @@ public class RepackagerTests {
File file = this.testJarFile.getFile();
libJarFile.setLastModified(JAN_1_1980);
Repackager repackager = new Repackager(file);
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(libJarFile, LibraryScope.COMPILE));
callback.library(
new Library(libJarFileToUnpack, LibraryScope.COMPILE, true));
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
}
repackager.repackage((callback) -> {
callback.library(new Library(libJarFile, LibraryScope.COMPILE));
callback.library(new Library(libJarFileToUnpack, LibraryScope.COMPILE, true));
callback.library(new Library(libNonJarFile, LibraryScope.COMPILE));
});
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFile.getName())).isTrue();
assertThat(hasEntry(file, "BOOT-INF/lib/" + libJarFileToUnpack.getName()))
@@ -331,12 +324,9 @@ public class RepackagerTests {
Repackager repackager = new Repackager(file);
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Duplicate library");
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
}
repackager.repackage((callback) -> {
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
callback.library(new Library(libJarFile, LibraryScope.COMPILE, false));
});
}
@@ -355,14 +345,8 @@ public class RepackagerTests {
given(layout.getLibraryDestination(anyString(), eq(LibraryScope.COMPILE)))
.willReturn("test-lib/");
repackager.setLayout(layout);
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(libJarFile, scope));
}
});
repackager.repackage(
(callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(hasEntry(file, "test/" + libJarFile.getName())).isTrue();
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isEqualTo("test-lib/");
@@ -382,14 +366,8 @@ public class RepackagerTests {
final LibraryScope scope = mock(LibraryScope.class);
given(layout.getLauncherClassName()).willReturn("testLauncher");
repackager.setLayout(layout);
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(libJarFile, scope));
}
});
repackager.repackage(
(callback) -> callback.library(new Library(libJarFile, scope)));
assertThat(getManifest(file).getMainAttributes().getValue("Spring-Boot-Lib"))
.isNull();
assertThat(getManifest(file).getMainAttributes().getValue("Main-Class"))
@@ -447,17 +425,13 @@ public class RepackagerTests {
public void dontRecompressZips() throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
final File nestedFile = nested.getFile();
File nestedFile = nested.getFile();
this.testJarFile.addFile("test/nested.jar", nestedFile);
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
}
});
repackager.repackage((callback) -> callback
.library(new Library(nestedFile, LibraryScope.COMPILE)));
try (JarFile jarFile = new JarFile(file)) {
assertThat(
@@ -494,25 +468,16 @@ public class RepackagerTests {
throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
final File nestedFile = nested.getFile();
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
nested.getFile());
File nestedFile = nested.getFile();
String name = "BOOT-INF/lib/" + nestedFile.getName();
this.testJarFile.addFile(name, nested.getFile());
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
callback.library(new Library(nestedFile, LibraryScope.COMPILE, true));
}
});
repackager.repackage((callback) -> callback
.library(new Library(nestedFile, LibraryScope.COMPILE, true)));
try (JarFile jarFile = new JarFile(file)) {
assertThat(
jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getComment())
.startsWith("UNPACK:");
assertThat(jarFile.getEntry(name).getComment()).startsWith("UNPACK:");
}
}
@@ -521,23 +486,18 @@ public class RepackagerTests {
throws Exception {
TestJarFile nested = new TestJarFile(this.temporaryFolder);
nested.addClass("a/b/C.class", ClassWithoutMainMethod.class);
final File nestedFile = nested.getFile();
File nestedFile = nested.getFile();
this.testJarFile.addFile("BOOT-INF/lib/" + nestedFile.getName(),
nested.getFile());
this.testJarFile.addClass("A.class", ClassWithMainMethod.class);
File file = this.testJarFile.getFile();
Repackager repackager = new Repackager(file);
long sourceLength = nestedFile.length();
repackager.repackage(new Libraries() {
@Override
public void doWithLibraries(LibraryCallback callback) throws IOException {
nestedFile.delete();
File toZip = RepackagerTests.this.temporaryFolder.newFile();
ZipUtil.packEntry(toZip, nestedFile);
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
}
repackager.repackage((callback) -> {
nestedFile.delete();
File toZip = RepackagerTests.this.temporaryFolder.newFile();
ZipUtil.packEntry(toZip, nestedFile);
callback.library(new Library(nestedFile, LibraryScope.COMPILE));
});
try (JarFile jarFile = new JarFile(file)) {
assertThat(jarFile.getEntry("BOOT-INF/lib/" + nestedFile.getName()).getSize())

View File

@@ -22,8 +22,6 @@ import java.util.jar.JarEntry;
import java.util.jar.Manifest;
import org.springframework.boot.loader.archive.Archive;
import org.springframework.boot.loader.archive.Archive.Entry;
import org.springframework.boot.loader.archive.Archive.EntryFilter;
/**
* Base class for executable archive {@link Launcher}s.
@@ -69,14 +67,7 @@ public abstract class ExecutableArchiveLauncher extends Launcher {
@Override
protected List<Archive> getClassPathArchives() throws Exception {
List<Archive> archives = new ArrayList<>(
this.archive.getNestedArchives(new EntryFilter() {
@Override
public boolean matches(Entry entry) {
return isNestedArchive(entry);
}
}));
this.archive.getNestedArchives(this::isNestedArchive));
postProcessClassPathArchives(archives);
return archives;
}

View File

@@ -128,32 +128,28 @@ public class LaunchedURLClassLoader extends URLClassLoader {
private void definePackage(final String className, final String packageName) {
try {
AccessController.doPrivileged(new PrivilegedExceptionAction<Object>() {
@Override
public Object run() throws ClassNotFoundException {
String packageEntryName = packageName.replace('.', '/') + "/";
String classEntryName = className.replace('.', '/') + ".class";
for (URL url : getURLs()) {
try {
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarFile jarFile = ((JarURLConnection) connection)
.getJarFile();
if (jarFile.getEntry(classEntryName) != null
&& jarFile.getEntry(packageEntryName) != null
&& jarFile.getManifest() != null) {
definePackage(packageName, jarFile.getManifest(),
url);
return null;
}
AccessController.doPrivileged((PrivilegedExceptionAction<Object>) () -> {
String packageEntryName = packageName.replace('.', '/') + "/";
String classEntryName = className.replace('.', '/') + ".class";
for (URL url : getURLs()) {
try {
URLConnection connection = url.openConnection();
if (connection instanceof JarURLConnection) {
JarFile jarFile = ((JarURLConnection) connection)
.getJarFile();
if (jarFile.getEntry(classEntryName) != null
&& jarFile.getEntry(packageEntryName) != null
&& jarFile.getManifest() != null) {
definePackage(packageName, jarFile.getManifest(), url);
return null;
}
}
catch (IOException ex) {
// Ignore
}
}
return null;
catch (IOException ex) {
// Ignore
}
}
return null;
}, AccessController.getContext());
}
catch (java.security.PrivilegedActionException ex) {

View File

@@ -537,16 +537,11 @@ public class PropertiesLauncher extends Launcher {
// directories, meaning we are running from an executable JAR. We add nested
// entries from there with low priority (i.e. at end).
try {
lib.addAll(this.parent.getNestedArchives(new EntryFilter() {
@Override
public boolean matches(Entry entry) {
if (entry.isDirectory()) {
return entry.getName().equals(JarLauncher.BOOT_INF_CLASSES);
}
return entry.getName().startsWith(JarLauncher.BOOT_INF_LIB);
lib.addAll(this.parent.getNestedArchives((entry) -> {
if (entry.isDirectory()) {
return entry.getName().equals(JarLauncher.BOOT_INF_CLASSES);
}
return entry.getName().startsWith(JarLauncher.BOOT_INF_LIB);
}));
}
catch (IOException ex) {

View File

@@ -258,16 +258,11 @@ public class JarFile extends java.util.jar.JarFile {
private JarFile createJarFileFromDirectoryEntry(JarEntry entry) throws IOException {
final AsciiBytes sourceName = new AsciiBytes(entry.getName());
JarEntryFilter filter = new JarEntryFilter() {
@Override
public AsciiBytes apply(AsciiBytes name) {
if (name.startsWith(sourceName) && !name.equals(sourceName)) {
return name.substring(sourceName.length());
}
return null;
JarEntryFilter filter = (name) -> {
if (name.startsWith(sourceName) && !name.equals(sourceName)) {
return name.substring(sourceName.length());
}
return null;
};
return new JarFile(this.rootFile,
this.pathFromRoot + "!/"

View File

@@ -26,7 +26,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.Callable;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
@@ -38,8 +37,6 @@ import org.junit.Test;
import org.junit.rules.ExpectedException;
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.springframework.boot.loader.data.RandomAccessData.ResourceAccess;
import org.springframework.boot.loader.data.RandomAccessDataFile.FilePool;
@@ -290,17 +287,12 @@ public class RandomAccessDataFileTests {
ExecutorService executorService = Executors.newFixedThreadPool(20);
List<Future<Boolean>> results = new ArrayList<>();
for (int i = 0; i < 100; i++) {
results.add(executorService.submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
.getSubsection(0, 256)
.getInputStream(ResourceAccess.PER_READ);
byte[] b = new byte[256];
subsectionInputStream.read(b);
return Arrays.equals(b, BYTES);
}
results.add(executorService.submit(() -> {
InputStream subsectionInputStream = RandomAccessDataFileTests.this.file
.getSubsection(0, 256).getInputStream(ResourceAccess.PER_READ);
byte[] b = new byte[256];
subsectionInputStream.read(b);
return Arrays.equals(b, BYTES);
}));
}
for (Future<Boolean> future : results) {
@@ -327,21 +319,15 @@ public class RandomAccessDataFileTests {
"filePool");
FilePool spiedPool = spy(filePool);
ReflectionTestUtils.setField(this.file, "filePool", spiedPool);
willAnswer(new Answer<RandomAccessFile>() {
@Override
public RandomAccessFile answer(InvocationOnMock invocation) throws Throwable {
RandomAccessFile originalFile = (RandomAccessFile) invocation
.callRealMethod();
if (Mockito.mockingDetails(originalFile).isSpy()) {
return originalFile;
}
RandomAccessFile spiedFile = spy(originalFile);
willThrow(new IOException("Seek failed")).given(spiedFile)
.seek(anyLong());
return spiedFile;
willAnswer((invocation) -> {
RandomAccessFile originalFile = (RandomAccessFile) invocation
.callRealMethod();
if (Mockito.mockingDetails(originalFile).isSpy()) {
return originalFile;
}
RandomAccessFile spiedFile = spy(originalFile);
willThrow(new IOException("Seek failed")).given(spiedFile).seek(anyLong());
return spiedFile;
}).given(spiedPool).acquire();
for (int i = 0; i < 5; i++) {

View File

@@ -228,14 +228,7 @@ public class StartMojo extends AbstractRunMojo {
final SpringApplicationAdminClient client = new SpringApplicationAdminClient(
connection, this.jmxName);
try {
execute(this.wait, this.maxAttempts, new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
return (client.isReady() ? true : null);
}
});
execute(this.wait, this.maxAttempts, () -> (client.isReady() ? true : null));
}
catch (ReflectionException ex) {
throw new MojoExecutionException("Unable to retrieve 'ready' attribute",

View File

@@ -83,13 +83,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
protected Object createTest() throws Exception {
ModifiedClassPathTestClass testClass = (ModifiedClassPathTestClass) getTestClass();
return testClass.doWithModifiedClassPathThreadContextClassLoader(
new ModifiedClassPathTestClass.ModifiedClassPathTcclAction<Object, Exception>() {
@Override
public Object perform() throws Exception {
return ModifiedClassPathRunner.super.createTest();
}
});
() -> ModifiedClassPathRunner.super.createTest());
}
private URLClassLoader createTestClassLoader(Class<?> testClass) throws Exception {
@@ -299,15 +293,8 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
public Object invokeExplosively(final Object target, final Object... params)
throws Throwable {
return doWithModifiedClassPathThreadContextClassLoader(
new ModifiedClassPathTcclAction<Object, Throwable>() {
@Override
public Object perform() throws Throwable {
return ModifiedClassPathFrameworkMethod.super.invokeExplosively(
target, params);
}
});
() -> ModifiedClassPathFrameworkMethod.super.invokeExplosively(
target, params));
}
}

View File

@@ -32,9 +32,6 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletRegistration;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.BDDMockito.given;
@@ -70,50 +67,31 @@ public abstract class MockServletWebServer {
try {
this.servletContext = mock(ServletContext.class);
given(this.servletContext.addServlet(anyString(), (Servlet) any()))
.willAnswer(new Answer<ServletRegistration.Dynamic>() {
@Override
public ServletRegistration.Dynamic answer(
InvocationOnMock invocation) throws Throwable {
RegisteredServlet registeredServlet = new RegisteredServlet(
(Servlet) invocation.getArguments()[1]);
MockServletWebServer.this.registeredServlets
.add(registeredServlet);
return registeredServlet.getRegistration();
}
.willAnswer((invocation) -> {
RegisteredServlet registeredServlet = new RegisteredServlet(
(Servlet) invocation.getArguments()[1]);
MockServletWebServer.this.registeredServlets
.add(registeredServlet);
return registeredServlet.getRegistration();
});
given(this.servletContext.addFilter(anyString(), (Filter) any()))
.willAnswer(new Answer<FilterRegistration.Dynamic>() {
@Override
public FilterRegistration.Dynamic answer(
InvocationOnMock invocation) throws Throwable {
RegisteredFilter registeredFilter = new RegisteredFilter(
(Filter) invocation.getArguments()[1]);
MockServletWebServer.this.registeredFilters
.add(registeredFilter);
return registeredFilter.getRegistration();
}
.willAnswer((invocation) -> {
RegisteredFilter registeredFilter = new RegisteredFilter(
(Filter) invocation.getArguments()[1]);
MockServletWebServer.this.registeredFilters.add(registeredFilter);
return registeredFilter.getRegistration();
});
final Map<String, String> initParameters = new HashMap<>();
given(this.servletContext.setInitParameter(anyString(), anyString()))
.will(new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
initParameters.put(invocation.getArgument(0),
invocation.getArgument(1));
return null;
}
.will((invocation) -> {
initParameters.put(invocation.getArgument(0),
invocation.getArgument(1));
return null;
});
given(this.servletContext.getInitParameterNames())
.willReturn(Collections.enumeration(initParameters.keySet()));
given(this.servletContext.getInitParameter(anyString()))
.willAnswer(new Answer<String>() {
@Override
public String answer(InvocationOnMock invocation)
throws Throwable {
return initParameters.get(invocation.getArgument(0));
}
});
given(this.servletContext.getInitParameter(anyString())).willAnswer(
(invocation) -> initParameters.get(invocation.getArgument(0)));
given(this.servletContext.getAttributeNames())
.willReturn(MockServletWebServer.<String>emptyEnumeration());
given(this.servletContext.getNamedDispatcher("default"))