Merge branch '2.1.x'
Closes gh-17079
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -38,17 +38,14 @@ public class BuildOutput {
|
||||
*/
|
||||
public File getTestClassesLocation() {
|
||||
try {
|
||||
File location = new File(this.testClass.getProtectionDomain().getCodeSource()
|
||||
.getLocation().toURI());
|
||||
File location = new File(this.testClass.getProtectionDomain().getCodeSource().getLocation().toURI());
|
||||
if (location.getPath().endsWith(path("target", "test-classes"))) {
|
||||
return location;
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Unexpected test classes location '" + location + "'");
|
||||
throw new IllegalStateException("Unexpected test classes location '" + location + "'");
|
||||
}
|
||||
catch (URISyntaxException ex) {
|
||||
throw new IllegalStateException("Invalid test class code source location",
|
||||
ex);
|
||||
throw new IllegalStateException("Invalid test class code source location", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,8 +59,7 @@ public class BuildOutput {
|
||||
return testClassesLocation;
|
||||
}
|
||||
throw new IllegalStateException(
|
||||
"Cannot determine test resources location from classes location '"
|
||||
+ testClassesLocation + "'");
|
||||
"Cannot determine test resources location from classes location '" + testClassesLocation + "'");
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -55,8 +55,7 @@ public class TestCompiler {
|
||||
this(ToolProvider.getSystemJavaCompiler(), temporaryFolder);
|
||||
}
|
||||
|
||||
public TestCompiler(JavaCompiler compiler, TemporaryFolder temporaryFolder)
|
||||
throws IOException {
|
||||
public TestCompiler(JavaCompiler compiler, TemporaryFolder temporaryFolder) throws IOException {
|
||||
this.compiler = compiler;
|
||||
this.fileManager = compiler.getStandardFileManager(null, null, null);
|
||||
this.outputLocation = temporaryFolder.newFolder();
|
||||
@@ -66,8 +65,7 @@ public class TestCompiler {
|
||||
}
|
||||
|
||||
public TestCompilationTask getTask(Collection<File> sourceFiles) {
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = this.fileManager
|
||||
.getJavaFileObjectsFromFiles(sourceFiles);
|
||||
Iterable<? extends JavaFileObject> javaFileObjects = this.fileManager.getJavaFileObjectsFromFiles(sourceFiles);
|
||||
return getTask(javaFileObjects);
|
||||
}
|
||||
|
||||
@@ -76,10 +74,9 @@ public class TestCompiler {
|
||||
return getTask(javaFileObjects);
|
||||
}
|
||||
|
||||
private TestCompilationTask getTask(
|
||||
Iterable<? extends JavaFileObject> javaFileObjects) {
|
||||
return new TestCompilationTask(this.compiler.getTask(null, this.fileManager, null,
|
||||
null, null, javaFileObjects));
|
||||
private TestCompilationTask getTask(Iterable<? extends JavaFileObject> javaFileObjects) {
|
||||
return new TestCompilationTask(
|
||||
this.compiler.getTask(null, this.fileManager, null, null, null, javaFileObjects));
|
||||
}
|
||||
|
||||
public File getOutputLocation() {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -52,12 +52,11 @@ public abstract class AbstractConfigurationClassTests {
|
||||
public void allBeanMethodsArePublic() throws IOException {
|
||||
Set<String> nonPublicBeanMethods = new HashSet<>();
|
||||
for (AnnotationMetadata configurationClass : findConfigurationClasses()) {
|
||||
Set<MethodMetadata> beanMethods = configurationClass
|
||||
.getAnnotatedMethods(Bean.class.getName());
|
||||
Set<MethodMetadata> beanMethods = configurationClass.getAnnotatedMethods(Bean.class.getName());
|
||||
for (MethodMetadata methodMetadata : beanMethods) {
|
||||
if (!isPublic(methodMetadata)) {
|
||||
nonPublicBeanMethods.add(methodMetadata.getDeclaringClassName() + "."
|
||||
+ methodMetadata.getMethodName());
|
||||
nonPublicBeanMethods
|
||||
.add(methodMetadata.getDeclaringClassName() + "." + methodMetadata.getMethodName());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,16 +65,13 @@ public abstract class AbstractConfigurationClassTests {
|
||||
|
||||
private Set<AnnotationMetadata> findConfigurationClasses() throws IOException {
|
||||
Set<AnnotationMetadata> configurationClasses = new HashSet<>();
|
||||
Resource[] resources = this.resolver.getResources("classpath*:"
|
||||
+ getClass().getPackage().getName().replace('.', '/') + "/**/*.class");
|
||||
Resource[] resources = this.resolver
|
||||
.getResources("classpath*:" + getClass().getPackage().getName().replace('.', '/') + "/**/*.class");
|
||||
for (Resource resource : resources) {
|
||||
if (!isTestClass(resource)) {
|
||||
MetadataReader metadataReader = new SimpleMetadataReaderFactory()
|
||||
.getMetadataReader(resource);
|
||||
AnnotationMetadata annotationMetadata = metadataReader
|
||||
.getAnnotationMetadata();
|
||||
if (annotationMetadata.getAnnotationTypes()
|
||||
.contains(Configuration.class.getName())) {
|
||||
MetadataReader metadataReader = new SimpleMetadataReaderFactory().getMetadataReader(resource);
|
||||
AnnotationMetadata annotationMetadata = metadataReader.getAnnotationMetadata();
|
||||
if (annotationMetadata.getAnnotationTypes().contains(Configuration.class.getName())) {
|
||||
configurationClasses.add(annotationMetadata);
|
||||
}
|
||||
}
|
||||
@@ -89,8 +85,7 @@ public abstract class AbstractConfigurationClassTests {
|
||||
}
|
||||
|
||||
private boolean isPublic(MethodMetadata methodMetadata) {
|
||||
int access = (Integer) new DirectFieldAccessor(methodMetadata)
|
||||
.getPropertyValue("access");
|
||||
int access = (Integer) new DirectFieldAccessor(methodMetadata).getPropertyValue("access");
|
||||
return (access & Opcodes.ACC_PUBLIC) != 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -70,8 +70,7 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private static final Pattern INTELLIJ_CLASSPATH_JAR_PATTERN = Pattern
|
||||
.compile(".*classpath(\\d+)?\\.jar");
|
||||
private static final Pattern INTELLIJ_CLASSPATH_JAR_PATTERN = Pattern.compile(".*classpath(\\d+)?\\.jar");
|
||||
|
||||
public ModifiedClassPathRunner(Class<?> testClass) throws InitializationError {
|
||||
super(testClass);
|
||||
@@ -91,15 +90,14 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
@Override
|
||||
protected Object createTest() throws Exception {
|
||||
ModifiedClassPathTestClass testClass = (ModifiedClassPathTestClass) getTestClass();
|
||||
return testClass.doWithModifiedClassPathThreadContextClassLoader(
|
||||
() -> ModifiedClassPathRunner.super.createTest());
|
||||
return testClass
|
||||
.doWithModifiedClassPathThreadContextClassLoader(() -> ModifiedClassPathRunner.super.createTest());
|
||||
}
|
||||
|
||||
private URLClassLoader createTestClassLoader(Class<?> testClass) throws Exception {
|
||||
ClassLoader classLoader = this.getClass().getClassLoader();
|
||||
return new ModifiedClassPathClassLoader(
|
||||
processUrls(extractUrls(classLoader), testClass), classLoader.getParent(),
|
||||
classLoader);
|
||||
return new ModifiedClassPathClassLoader(processUrls(extractUrls(classLoader), testClass),
|
||||
classLoader.getParent(), classLoader);
|
||||
}
|
||||
|
||||
private URL[] extractUrls(ClassLoader classLoader) throws Exception {
|
||||
@@ -119,8 +117,8 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
if (classLoader instanceof URLClassLoader) {
|
||||
return Stream.of(((URLClassLoader) classLoader).getURLs());
|
||||
}
|
||||
return Stream.of(ManagementFactory.getRuntimeMXBean().getClassPath()
|
||||
.split(File.pathSeparator)).map(this::toURL);
|
||||
return Stream.of(ManagementFactory.getRuntimeMXBean().getClassPath().split(File.pathSeparator))
|
||||
.map(this::toURL);
|
||||
}
|
||||
|
||||
private URL toURL(String entry) {
|
||||
@@ -170,8 +168,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private String[] getClassPath(URL booterJar) throws Exception {
|
||||
Attributes attributes = getManifestMainAttributesFromUrl(booterJar);
|
||||
return StringUtils.delimitedListToStringArray(
|
||||
attributes.getValue(Attributes.Name.CLASS_PATH), " ");
|
||||
return StringUtils.delimitedListToStringArray(attributes.getValue(Attributes.Name.CLASS_PATH), " ");
|
||||
}
|
||||
|
||||
private Attributes getManifestMainAttributesFromUrl(URL url) throws Exception {
|
||||
@@ -181,13 +178,10 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
}
|
||||
|
||||
private URL[] processUrls(URL[] urls, Class<?> testClass) throws Exception {
|
||||
MergedAnnotations annotations = MergedAnnotations.from(testClass,
|
||||
SearchStrategy.EXHAUSTIVE);
|
||||
ClassPathEntryFilter filter = new ClassPathEntryFilter(
|
||||
annotations.get(ClassPathExclusions.class));
|
||||
MergedAnnotations annotations = MergedAnnotations.from(testClass, SearchStrategy.EXHAUSTIVE);
|
||||
ClassPathEntryFilter filter = new ClassPathEntryFilter(annotations.get(ClassPathExclusions.class));
|
||||
List<URL> processedUrls = new ArrayList<>();
|
||||
List<URL> additionalUrls = getAdditionalUrls(
|
||||
annotations.get(ClassPathOverrides.class));
|
||||
List<URL> additionalUrls = getAdditionalUrls(annotations.get(ClassPathOverrides.class));
|
||||
processedUrls.addAll(additionalUrls);
|
||||
for (URL url : urls) {
|
||||
if (!filter.isExcluded(url)) {
|
||||
@@ -197,8 +191,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
return processedUrls.toArray(new URL[0]);
|
||||
}
|
||||
|
||||
private List<URL> getAdditionalUrls(MergedAnnotation<ClassPathOverrides> annotation)
|
||||
throws Exception {
|
||||
private List<URL> getAdditionalUrls(MergedAnnotation<ClassPathOverrides> annotation) throws Exception {
|
||||
if (!annotation.isPresent()) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -206,26 +199,19 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
}
|
||||
|
||||
private List<URL> resolveCoordinates(String[] coordinates) throws Exception {
|
||||
DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils
|
||||
.newServiceLocator();
|
||||
serviceLocator.addService(RepositoryConnectorFactory.class,
|
||||
BasicRepositoryConnectorFactory.class);
|
||||
DefaultServiceLocator serviceLocator = MavenRepositorySystemUtils.newServiceLocator();
|
||||
serviceLocator.addService(RepositoryConnectorFactory.class, BasicRepositoryConnectorFactory.class);
|
||||
serviceLocator.addService(TransporterFactory.class, HttpTransporterFactory.class);
|
||||
RepositorySystem repositorySystem = serviceLocator
|
||||
.getService(RepositorySystem.class);
|
||||
RepositorySystem repositorySystem = serviceLocator.getService(RepositorySystem.class);
|
||||
DefaultRepositorySystemSession session = MavenRepositorySystemUtils.newSession();
|
||||
LocalRepository localRepository = new LocalRepository(
|
||||
System.getProperty("user.home") + "/.m2/repository");
|
||||
session.setLocalRepositoryManager(
|
||||
repositorySystem.newLocalRepositoryManager(session, localRepository));
|
||||
CollectRequest collectRequest = new CollectRequest(null,
|
||||
Arrays.asList(new RemoteRepository.Builder("central", "default",
|
||||
"https://repo.maven.apache.org/maven2").build()));
|
||||
LocalRepository localRepository = new LocalRepository(System.getProperty("user.home") + "/.m2/repository");
|
||||
session.setLocalRepositoryManager(repositorySystem.newLocalRepositoryManager(session, localRepository));
|
||||
CollectRequest collectRequest = new CollectRequest(null, Arrays.asList(
|
||||
new RemoteRepository.Builder("central", "default", "https://repo.maven.apache.org/maven2").build()));
|
||||
|
||||
collectRequest.setDependencies(createDependencies(coordinates));
|
||||
DependencyRequest dependencyRequest = new DependencyRequest(collectRequest, null);
|
||||
DependencyResult result = repositorySystem.resolveDependencies(session,
|
||||
dependencyRequest);
|
||||
DependencyResult result = repositorySystem.resolveDependencies(session, dependencyRequest);
|
||||
List<URL> resolvedArtifacts = new ArrayList<>();
|
||||
for (ArtifactResult artifact : result.getArtifactResults()) {
|
||||
resolvedArtifacts.add(artifact.getArtifact().getFile().toURI().toURL());
|
||||
@@ -250,13 +236,11 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private final AntPathMatcher matcher = new AntPathMatcher();
|
||||
|
||||
private ClassPathEntryFilter(MergedAnnotation<ClassPathExclusions> annotation)
|
||||
throws Exception {
|
||||
private ClassPathEntryFilter(MergedAnnotation<ClassPathExclusions> annotation) throws Exception {
|
||||
this.exclusions = new ArrayList<>();
|
||||
this.exclusions.add("log4j-*.jar");
|
||||
if (annotation.isPresent()) {
|
||||
this.exclusions.addAll(
|
||||
Arrays.asList(annotation.getStringArray(MergedAnnotation.VALUE)));
|
||||
this.exclusions.addAll(Arrays.asList(annotation.getStringArray(MergedAnnotation.VALUE)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -282,15 +266,13 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private final ClassLoader classLoader;
|
||||
|
||||
ModifiedClassPathTestClass(ClassLoader classLoader, String testClassName)
|
||||
throws ClassNotFoundException {
|
||||
ModifiedClassPathTestClass(ClassLoader classLoader, String testClassName) throws ClassNotFoundException {
|
||||
super(classLoader.loadClass(testClassName));
|
||||
this.classLoader = classLoader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<FrameworkMethod> getAnnotatedMethods(
|
||||
Class<? extends Annotation> annotationClass) {
|
||||
public List<FrameworkMethod> getAnnotatedMethods(Class<? extends Annotation> annotationClass) {
|
||||
try {
|
||||
return getAnnotatedMethods(annotationClass.getName());
|
||||
}
|
||||
@@ -300,28 +282,24 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private List<FrameworkMethod> getAnnotatedMethods(String annotationClassName)
|
||||
throws ClassNotFoundException {
|
||||
private List<FrameworkMethod> getAnnotatedMethods(String annotationClassName) throws ClassNotFoundException {
|
||||
Class<? extends Annotation> annotationClass = (Class<? extends Annotation>) this.classLoader
|
||||
.loadClass(annotationClassName);
|
||||
List<FrameworkMethod> methods = super.getAnnotatedMethods(annotationClass);
|
||||
return wrapFrameworkMethods(methods);
|
||||
}
|
||||
|
||||
private List<FrameworkMethod> wrapFrameworkMethods(
|
||||
List<FrameworkMethod> methods) {
|
||||
private List<FrameworkMethod> wrapFrameworkMethods(List<FrameworkMethod> methods) {
|
||||
List<FrameworkMethod> wrapped = new ArrayList<>(methods.size());
|
||||
for (FrameworkMethod frameworkMethod : methods) {
|
||||
wrapped.add(new ModifiedClassPathFrameworkMethod(
|
||||
frameworkMethod.getMethod()));
|
||||
wrapped.add(new ModifiedClassPathFrameworkMethod(frameworkMethod.getMethod()));
|
||||
}
|
||||
return wrapped;
|
||||
}
|
||||
|
||||
private <T, E extends Throwable> T doWithModifiedClassPathThreadContextClassLoader(
|
||||
ModifiedClassPathTcclAction<T, E> action) throws E {
|
||||
ClassLoader originalClassLoader = Thread.currentThread()
|
||||
.getContextClassLoader();
|
||||
ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
|
||||
Thread.currentThread().setContextClassLoader(this.classLoader);
|
||||
try {
|
||||
return action.perform();
|
||||
@@ -352,11 +330,9 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object invokeExplosively(Object target, Object... params)
|
||||
throws Throwable {
|
||||
public Object invokeExplosively(Object target, Object... params) throws Throwable {
|
||||
return doWithModifiedClassPathThreadContextClassLoader(
|
||||
() -> ModifiedClassPathFrameworkMethod.super.invokeExplosively(
|
||||
target, params));
|
||||
() -> ModifiedClassPathFrameworkMethod.super.invokeExplosively(target, params));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -370,8 +346,7 @@ public class ModifiedClassPathRunner extends BlockJUnit4ClassRunner {
|
||||
|
||||
private final ClassLoader junitLoader;
|
||||
|
||||
ModifiedClassPathClassLoader(URL[] urls, ClassLoader parent,
|
||||
ClassLoader junitLoader) {
|
||||
ModifiedClassPathClassLoader(URL[] urls, ClassLoader parent, ClassLoader junitLoader) {
|
||||
super(urls, parent);
|
||||
this.junitLoader = junitLoader;
|
||||
}
|
||||
|
||||
@@ -45,12 +45,10 @@ class Container implements Startable {
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "resource" })
|
||||
<T extends GenericContainer<T>> Container(String dockerImageName, int port,
|
||||
Consumer<T> customizer) {
|
||||
<T extends GenericContainer<T>> Container(String dockerImageName, int port, Consumer<T> customizer) {
|
||||
this.port = port;
|
||||
this.containerFactory = () -> {
|
||||
T container = (T) new GenericContainer<>(dockerImageName)
|
||||
.withExposedPorts(port);
|
||||
T container = (T) new GenericContainer<>(dockerImageName).withExposedPorts(port);
|
||||
if (customizer != null) {
|
||||
customizer.accept(container);
|
||||
}
|
||||
@@ -68,8 +66,7 @@ class Container implements Startable {
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Assumptions.assumeTrue(isDockerRunning(),
|
||||
"Could not find valid docker environment.");
|
||||
Assumptions.assumeTrue(isDockerRunning(), "Could not find valid docker environment.");
|
||||
this.container = this.containerFactory.get();
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
@@ -26,10 +26,8 @@ import java.time.Duration;
|
||||
public class ElasticsearchContainer extends Container {
|
||||
|
||||
public ElasticsearchContainer() {
|
||||
super("elasticsearch:6.7.2", 9200,
|
||||
(container) -> container.withStartupTimeout(Duration.ofSeconds(120))
|
||||
.withStartupAttempts(5).withEnv("discovery.type", "single-node")
|
||||
.addExposedPorts(9200, 9300));
|
||||
super("elasticsearch:6.7.2", 9200, (container) -> container.withStartupTimeout(Duration.ofSeconds(120))
|
||||
.withStartupAttempts(5).withEnv("discovery.type", "single-node").addExposedPorts(9200, 9300));
|
||||
}
|
||||
|
||||
public int getMappedTransportPort() {
|
||||
|
||||
@@ -43,16 +43,14 @@ public class SkippableContainer<T extends GenericContainer<?>> implements Starta
|
||||
|
||||
public T getContainer() {
|
||||
if (this.container == null) {
|
||||
throw new IllegalStateException(
|
||||
"Container cannot be accessed prior to test invocation");
|
||||
throw new IllegalStateException("Container cannot be accessed prior to test invocation");
|
||||
}
|
||||
return this.container;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void start() {
|
||||
Assumptions.assumeTrue(isDockerRunning(),
|
||||
"Could not find valid docker environment.");
|
||||
Assumptions.assumeTrue(isDockerRunning(), "Could not find valid docker environment.");
|
||||
this.container = this.containerFactory.get();
|
||||
this.container.start();
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -41,8 +41,8 @@ public class ExampleFilter implements Filter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest request, ServletResponse response,
|
||||
FilterChain chain) throws IOException, ServletException {
|
||||
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
|
||||
throws IOException, ServletException {
|
||||
response.getWriter().write("[");
|
||||
chain.doFilter(request, response);
|
||||
response.getWriter().write("]");
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -48,8 +48,7 @@ public class ExampleServlet extends GenericServlet {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void service(ServletRequest request, ServletResponse response)
|
||||
throws ServletException, IOException {
|
||||
public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
|
||||
String content = "Hello World";
|
||||
if (this.echoRequestInfo) {
|
||||
content += " scheme=" + request.getScheme();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2018 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -65,36 +65,27 @@ public abstract class MockServletWebServer {
|
||||
private void initialize() {
|
||||
try {
|
||||
this.servletContext = mock(ServletContext.class);
|
||||
given(this.servletContext.addServlet(anyString(), any(Servlet.class)))
|
||||
.willAnswer((invocation) -> {
|
||||
RegisteredServlet registeredServlet = new RegisteredServlet(
|
||||
invocation.getArgument(1));
|
||||
MockServletWebServer.this.registeredServlets
|
||||
.add(registeredServlet);
|
||||
return registeredServlet.getRegistration();
|
||||
});
|
||||
given(this.servletContext.addFilter(anyString(), any(Filter.class)))
|
||||
.willAnswer((invocation) -> {
|
||||
RegisteredFilter registeredFilter = new RegisteredFilter(
|
||||
invocation.getArgument(1));
|
||||
MockServletWebServer.this.registeredFilters.add(registeredFilter);
|
||||
return registeredFilter.getRegistration();
|
||||
});
|
||||
given(this.servletContext.addServlet(anyString(), any(Servlet.class))).willAnswer((invocation) -> {
|
||||
RegisteredServlet registeredServlet = new RegisteredServlet(invocation.getArgument(1));
|
||||
MockServletWebServer.this.registeredServlets.add(registeredServlet);
|
||||
return registeredServlet.getRegistration();
|
||||
});
|
||||
given(this.servletContext.addFilter(anyString(), any(Filter.class))).willAnswer((invocation) -> {
|
||||
RegisteredFilter registeredFilter = new RegisteredFilter(invocation.getArgument(1));
|
||||
MockServletWebServer.this.registeredFilters.add(registeredFilter);
|
||||
return registeredFilter.getRegistration();
|
||||
});
|
||||
final Map<String, String> initParameters = new HashMap<>();
|
||||
given(this.servletContext.setInitParameter(anyString(), anyString()))
|
||||
.will((invocation) -> {
|
||||
initParameters.put(invocation.getArgument(0),
|
||||
invocation.getArgument(1));
|
||||
return null;
|
||||
});
|
||||
given(this.servletContext.setInitParameter(anyString(), anyString())).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(
|
||||
(invocation) -> initParameters.get(invocation.getArgument(0)));
|
||||
given(this.servletContext.getAttributeNames())
|
||||
.willReturn(Collections.emptyEnumeration());
|
||||
given(this.servletContext.getNamedDispatcher("default"))
|
||||
.willReturn(mock(RequestDispatcher.class));
|
||||
given(this.servletContext.getInitParameter(anyString()))
|
||||
.willAnswer((invocation) -> initParameters.get(invocation.getArgument(0)));
|
||||
given(this.servletContext.getAttributeNames()).willReturn(Collections.emptyEnumeration());
|
||||
given(this.servletContext.getNamedDispatcher("default")).willReturn(mock(RequestDispatcher.class));
|
||||
for (Initializer initializer : this.initializers) {
|
||||
initializer.onStartup(this.servletContext);
|
||||
}
|
||||
|
||||
@@ -32,8 +32,7 @@ import static org.hamcrest.Matchers.isA;
|
||||
@ClassPathExclusions("hibernate-validator-*.jar")
|
||||
public class ModifiedClassPathRunnerExclusionsTests {
|
||||
|
||||
private static final String EXCLUDED_RESOURCE = "META-INF/services/"
|
||||
+ "javax.validation.spi.ValidationProvider";
|
||||
private static final String EXCLUDED_RESOURCE = "META-INF/services/" + "javax.validation.spi.ValidationProvider";
|
||||
|
||||
@Test
|
||||
public void entriesAreFilteredFromTestClassClassLoader() {
|
||||
@@ -42,8 +41,7 @@ public class ModifiedClassPathRunnerExclusionsTests {
|
||||
|
||||
@Test
|
||||
public void entriesAreFilteredFromThreadContextClassLoader() {
|
||||
assertThat(Thread.currentThread().getContextClassLoader()
|
||||
.getResource(EXCLUDED_RESOURCE)).isNull();
|
||||
assertThat(Thread.currentThread().getContextClassLoader().getResource(EXCLUDED_RESOURCE)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2012-2017 the original author or authors.
|
||||
* Copyright 2012-2019 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.
|
||||
@@ -35,14 +35,14 @@ public class ModifiedClassPathRunnerOverridesTests {
|
||||
|
||||
@Test
|
||||
public void classesAreLoadedFromOverride() {
|
||||
assertThat(ApplicationContext.class.getProtectionDomain().getCodeSource()
|
||||
.getLocation().toString()).endsWith("spring-context-4.1.0.RELEASE.jar");
|
||||
assertThat(ApplicationContext.class.getProtectionDomain().getCodeSource().getLocation().toString())
|
||||
.endsWith("spring-context-4.1.0.RELEASE.jar");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void classesAreLoadedFromTransitiveDependencyOfOverride() {
|
||||
assertThat(StringUtils.class.getProtectionDomain().getCodeSource().getLocation()
|
||||
.toString()).endsWith("spring-core-4.1.0.RELEASE.jar");
|
||||
assertThat(StringUtils.class.getProtectionDomain().getCodeSource().getLocation().toString())
|
||||
.endsWith("spring-core-4.1.0.RELEASE.jar");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user