mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| d51d8aeaf6 |
+1
-1
@@ -72,7 +72,7 @@ to start a discussion first or have already created an issue, once a pull reques
|
||||
created, we will close the issue as superseded by the pull request, and the discussion
|
||||
about the issue will continue under the pull request.
|
||||
|
||||
1. Always check out the `main` branch and submit pull requests against it
|
||||
1. Always check out the `master` branch and submit pull requests against it
|
||||
(for target version see [settings.gradle](settings.gradle)).
|
||||
Backports to prior versions will be considered on a case-by-case basis and reflected as
|
||||
the fix version in the issue tracker.
|
||||
|
||||
+54
-62
@@ -1,16 +1,16 @@
|
||||
plugins {
|
||||
id 'io.spring.dependency-management' version '1.0.11.RELEASE' apply false
|
||||
id 'io.spring.nohttp' version '0.0.10'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.30' apply false
|
||||
id 'org.jetbrains.dokka' version '1.5.0' apply false
|
||||
id 'org.asciidoctor.jvm.convert' version '3.3.2'
|
||||
id 'org.asciidoctor.jvm.pdf' version '3.3.2'
|
||||
id 'de.undercouch.download' version '4.1.2'
|
||||
id "io.freefair.aspectj" version '6.1.0' apply false
|
||||
id "com.github.ben-manes.versions" version '0.39.0'
|
||||
id "com.github.johnrengelman.shadow" version '7.0.0' apply false
|
||||
id "me.champeau.jmh" version "0.6.6" apply false
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.30" apply false
|
||||
id 'io.spring.dependency-management' version '1.0.9.RELEASE' apply false
|
||||
id 'io.spring.nohttp' version '0.0.5.RELEASE'
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.10' apply false
|
||||
id 'org.jetbrains.dokka' version '0.10.1' apply false
|
||||
id 'org.asciidoctor.jvm.convert' version '3.1.0'
|
||||
id 'org.asciidoctor.jvm.pdf' version '3.1.0'
|
||||
id 'de.undercouch.download' version '4.1.1'
|
||||
id "io.freefair.aspectj" version '5.1.1' apply false
|
||||
id "com.github.ben-manes.versions" version '0.28.0'
|
||||
id "com.github.johnrengelman.shadow" version "6.1.0" apply false
|
||||
id "me.champeau.jmh" version "0.6.4" apply false
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.10" apply false
|
||||
id "org.unbroken-dome.xjc" version '2.0.0' apply false
|
||||
}
|
||||
|
||||
@@ -27,16 +27,16 @@ configure(allprojects) { project ->
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.5"
|
||||
mavenBom "io.netty:netty-bom:4.1.68.Final"
|
||||
mavenBom "io.projectreactor:reactor-bom:2020.0.11"
|
||||
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.3"
|
||||
mavenBom "io.netty:netty-bom:4.1.65.Final"
|
||||
mavenBom "io.projectreactor:reactor-bom:2020.0.7"
|
||||
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR10"
|
||||
mavenBom "io.rsocket:rsocket-bom:1.1.1"
|
||||
mavenBom "org.eclipse.jetty:jetty-bom:9.4.43.v20210629"
|
||||
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.30"
|
||||
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.5.2"
|
||||
mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.2.2"
|
||||
mavenBom "org.junit:junit-bom:5.8.0"
|
||||
mavenBom "io.rsocket:rsocket-bom:1.1.0"
|
||||
mavenBom "org.eclipse.jetty:jetty-bom:9.4.41.v20210516"
|
||||
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.10"
|
||||
mavenBom "org.jetbrains.kotlinx:kotlinx-coroutines-bom:1.5.0"
|
||||
mavenBom "org.jetbrains.kotlinx:kotlinx-serialization-bom:1.2.1"
|
||||
mavenBom "org.junit:junit-bom:5.7.2"
|
||||
}
|
||||
dependencies {
|
||||
dependencySet(group: 'org.apache.logging.log4j', version: '2.14.1') {
|
||||
@@ -51,7 +51,7 @@ configure(allprojects) { project ->
|
||||
}
|
||||
dependency "com.google.code.findbugs:jsr305:3.0.2"
|
||||
|
||||
dependencySet(group: 'org.aspectj', version: '1.9.7') {
|
||||
dependencySet(group: 'org.aspectj', version: '1.9.6') {
|
||||
entry 'aspectjrt'
|
||||
entry 'aspectjtools'
|
||||
entry 'aspectjweaver'
|
||||
@@ -67,8 +67,7 @@ configure(allprojects) { project ->
|
||||
dependency "io.reactivex:rxjava:1.3.8"
|
||||
dependency "io.reactivex:rxjava-reactive-streams:1.2.1"
|
||||
dependency "io.reactivex.rxjava2:rxjava:2.2.21"
|
||||
dependency "io.reactivex.rxjava3:rxjava:3.1.1"
|
||||
dependency "io.smallrye.reactive:mutiny:1.0.0"
|
||||
dependency "io.reactivex.rxjava3:rxjava:3.0.13"
|
||||
dependency "io.projectreactor.tools:blockhound:1.0.4.RELEASE"
|
||||
|
||||
dependency "com.caucho:hessian:4.0.63"
|
||||
@@ -76,10 +75,10 @@ configure(allprojects) { project ->
|
||||
dependency("com.fasterxml.woodstox:woodstox-core:6.2.6") {
|
||||
exclude group: "stax", name: "stax-api"
|
||||
}
|
||||
dependency "com.google.code.gson:gson:2.8.8"
|
||||
dependency "com.google.protobuf:protobuf-java-util:3.17.3"
|
||||
dependency "com.google.code.gson:gson:2.8.7"
|
||||
dependency "com.google.protobuf:protobuf-java-util:3.17.2"
|
||||
dependency "com.googlecode.protobuf-java-format:protobuf-java-format:1.4"
|
||||
dependency("com.thoughtworks.xstream:xstream:1.4.18") {
|
||||
dependency("com.thoughtworks.xstream:xstream:1.4.17") {
|
||||
exclude group: "xpp3", name: "xpp3_min"
|
||||
exclude group: "xmlpull", name: "xmlpull"
|
||||
}
|
||||
@@ -92,7 +91,7 @@ configure(allprojects) { project ->
|
||||
entry 'jibx-run'
|
||||
}
|
||||
dependency "org.ogce:xpp3:1.1.6"
|
||||
dependency "org.yaml:snakeyaml:1.29"
|
||||
dependency "org.yaml:snakeyaml:1.28"
|
||||
|
||||
dependency "com.h2database:h2:1.4.200"
|
||||
dependency "com.github.ben-manes.caffeine:caffeine:2.9.1"
|
||||
@@ -125,21 +124,21 @@ configure(allprojects) { project ->
|
||||
dependency "org.ehcache:ehcache:3.4.0"
|
||||
dependency "org.hibernate:hibernate-core:5.4.32.Final"
|
||||
dependency "org.hibernate:hibernate-validator:6.2.0.Final"
|
||||
dependency "org.webjars:webjars-locator-core:0.47"
|
||||
dependency "org.webjars:webjars-locator-core:0.46"
|
||||
dependency "org.webjars:underscorejs:1.8.3"
|
||||
|
||||
dependencySet(group: 'org.apache.tomcat', version: '9.0.52') {
|
||||
dependencySet(group: 'org.apache.tomcat', version: '9.0.45') {
|
||||
entry 'tomcat-util'
|
||||
entry('tomcat-websocket') {
|
||||
exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
|
||||
exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
|
||||
}
|
||||
}
|
||||
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.52') {
|
||||
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.45') {
|
||||
entry 'tomcat-embed-core'
|
||||
entry 'tomcat-embed-websocket'
|
||||
}
|
||||
dependencySet(group: 'io.undertow', version: '2.2.10.Final') {
|
||||
dependencySet(group: 'io.undertow', version: '2.2.8.Final') {
|
||||
entry 'undertow-core'
|
||||
entry('undertow-websockets-jsr') {
|
||||
exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
|
||||
@@ -162,9 +161,9 @@ configure(allprojects) { project ->
|
||||
}
|
||||
dependency 'org.apache.httpcomponents.client5:httpclient5:5.1'
|
||||
dependency 'org.apache.httpcomponents.core5:httpcore5-reactive:5.1.1'
|
||||
dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.9"
|
||||
dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.8"
|
||||
|
||||
dependency "org.jruby:jruby:9.2.19.0"
|
||||
dependency "org.jruby:jruby:9.2.17.0"
|
||||
dependency "org.python:jython-standalone:2.7.1"
|
||||
dependency "org.mozilla:rhino:1.7.11"
|
||||
|
||||
@@ -190,25 +189,25 @@ configure(allprojects) { project ->
|
||||
dependency "org.testng:testng:7.4.0"
|
||||
dependency "org.hamcrest:hamcrest:2.1"
|
||||
dependency "org.awaitility:awaitility:3.1.6"
|
||||
dependency "org.assertj:assertj-core:3.20.2"
|
||||
dependency "org.assertj:assertj-core:3.19.0"
|
||||
dependencySet(group: 'org.xmlunit', version: '2.8.2') {
|
||||
entry 'xmlunit-assertj'
|
||||
entry('xmlunit-matchers') {
|
||||
exclude group: "org.hamcrest", name: "hamcrest-core"
|
||||
}
|
||||
}
|
||||
dependencySet(group: 'org.mockito', version: '3.12.4') {
|
||||
dependencySet(group: 'org.mockito', version: '3.11.0') {
|
||||
entry('mockito-core') {
|
||||
exclude group: "org.hamcrest", name: "hamcrest-core"
|
||||
}
|
||||
entry 'mockito-junit-jupiter'
|
||||
}
|
||||
dependency "io.mockk:mockk:1.12.0"
|
||||
dependency "io.mockk:mockk:1.10.2"
|
||||
|
||||
dependency("net.sourceforge.htmlunit:htmlunit:2.52.0") {
|
||||
dependency("net.sourceforge.htmlunit:htmlunit:2.50.0") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.seleniumhq.selenium:htmlunit-driver:2.52.0") {
|
||||
dependency("org.seleniumhq.selenium:htmlunit-driver:2.50.0") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.seleniumhq.selenium:selenium-java:3.141.59") {
|
||||
@@ -216,7 +215,7 @@ configure(allprojects) { project ->
|
||||
exclude group: "io.netty", name: "netty"
|
||||
}
|
||||
dependency "org.skyscreamer:jsonassert:1.5.0"
|
||||
dependency "com.jayway.jsonpath:json-path:2.6.0"
|
||||
dependency "com.jayway.jsonpath:json-path:2.5.0"
|
||||
dependency "org.bouncycastle:bcpkix-jdk15on:1.66"
|
||||
|
||||
dependencySet(group: 'org.apache.tiles', version: '3.0.8') {
|
||||
@@ -237,7 +236,7 @@ configure(allprojects) { project ->
|
||||
dependency "com.ibm.websphere:uow:6.0.2.17"
|
||||
dependency "com.jamonapi:jamon:2.82"
|
||||
dependency "joda-time:joda-time:2.10.10"
|
||||
dependency "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.9"
|
||||
dependency "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.8"
|
||||
dependency "org.javamoney:moneta:1.3"
|
||||
|
||||
dependency "com.sun.activation:javax.activation:1.2.0"
|
||||
@@ -313,8 +312,6 @@ configure([rootProject] + javaProjects) { project ->
|
||||
|
||||
pluginManager.withPlugin("kotlin") {
|
||||
apply plugin: "org.jetbrains.dokka"
|
||||
apply from: "${rootDir}/gradle/docs-dokka.gradle"
|
||||
|
||||
compileKotlin {
|
||||
kotlinOptions {
|
||||
languageVersion = "1.3"
|
||||
@@ -339,25 +336,23 @@ configure([rootProject] + javaProjects) { project ->
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.45.1"
|
||||
toolVersion = "8.43"
|
||||
configDirectory.set(rootProject.file("src/checkstyle"))
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-api")
|
||||
testImplementation("org.junit.jupiter:junit-jupiter-params")
|
||||
testImplementation("org.junit.platform:junit-platform-suite-api")
|
||||
testImplementation("org.mockito:mockito-core")
|
||||
testImplementation("org.mockito:mockito-junit-jupiter")
|
||||
testImplementation("io.mockk:mockk")
|
||||
testImplementation("org.assertj:assertj-core")
|
||||
testCompile("org.junit.jupiter:junit-jupiter-api")
|
||||
testCompile("org.junit.jupiter:junit-jupiter-params")
|
||||
testCompile("org.mockito:mockito-core")
|
||||
testCompile("org.mockito:mockito-junit-jupiter")
|
||||
testCompile("io.mockk:mockk")
|
||||
testCompile("org.assertj:assertj-core")
|
||||
// Pull in the latest JUnit 5 Launcher API to ensure proper support in IDEs.
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-launcher")
|
||||
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine")
|
||||
testRuntimeOnly("org.junit.platform:junit-platform-suite-engine")
|
||||
testRuntimeOnly("org.apache.logging.log4j:log4j-core")
|
||||
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
|
||||
testRuntimeOnly("org.apache.logging.log4j:log4j-jul")
|
||||
testRuntime("org.junit.platform:junit-platform-launcher")
|
||||
testRuntime("org.junit.jupiter:junit-jupiter-engine")
|
||||
testRuntime("org.apache.logging.log4j:log4j-core")
|
||||
testRuntime("org.apache.logging.log4j:log4j-slf4j-impl")
|
||||
testRuntime("org.apache.logging.log4j:log4j-jul")
|
||||
// JSR-305 only used for non-required meta-annotations
|
||||
compileOnly("com.google.code.findbugs:jsr305")
|
||||
testCompileOnly("com.google.code.findbugs:jsr305")
|
||||
@@ -368,7 +363,7 @@ configure([rootProject] + javaProjects) { project ->
|
||||
"https://docs.oracle.com/javase/8/docs/api/",
|
||||
"https://docs.oracle.com/javaee/7/api/",
|
||||
"https://docs.oracle.com/cd/E13222_01/wls/docs90/javadocs/", // CommonJ
|
||||
"https://www.ibm.com/docs/api/v1/content/SSEQTP_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/",
|
||||
"https://www.ibm.com/support/knowledgecenter/SS7JFU_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/",
|
||||
"https://glassfish.java.net/nonav/docs/v3/api/",
|
||||
"https://docs.jboss.org/jbossas/javadoc/4.0.5/connector/",
|
||||
"https://docs.jboss.org/jbossas/javadoc/7.1.2.Final/",
|
||||
@@ -383,10 +378,7 @@ configure([rootProject] + javaProjects) { project ->
|
||||
"https://hc.apache.org/httpcomponents-client-5.1.x/current/httpclient5/apidocs/",
|
||||
"https://projectreactor.io/docs/test/release/api/",
|
||||
"https://junit.org/junit4/javadoc/4.13.2/",
|
||||
"https://junit.org/junit5/docs/5.8.0/api/",
|
||||
"https://www.reactive-streams.org/reactive-streams-1.0.3-javadoc/",
|
||||
"https://javadoc.io/static/io.rsocket/rsocket-core/1.1.1/",
|
||||
"https://r2dbc.io/spec/0.8.5.RELEASE/api/"
|
||||
"https://junit.org/junit5/docs/5.7.2/api/"
|
||||
] as String[]
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -32,7 +32,6 @@ import org.gradle.api.tasks.compile.JavaCompile;
|
||||
*
|
||||
* @author Brian Clozel
|
||||
* @author Sam Brannen
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||
|
||||
@@ -44,8 +43,7 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||
List<String> commonCompilerArgs = Arrays.asList(
|
||||
"-Xlint:serial", "-Xlint:cast", "-Xlint:classfile", "-Xlint:dep-ann",
|
||||
"-Xlint:divzero", "-Xlint:empty", "-Xlint:finally", "-Xlint:overrides",
|
||||
"-Xlint:path", "-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options",
|
||||
"-parameters"
|
||||
"-Xlint:path", "-Xlint:processing", "-Xlint:static", "-Xlint:try", "-Xlint:-options"
|
||||
);
|
||||
COMPILER_ARGS = new ArrayList<>();
|
||||
COMPILER_ARGS.addAll(commonCompilerArgs);
|
||||
@@ -56,7 +54,7 @@ public class CompilerConventionsPlugin implements Plugin<Project> {
|
||||
TEST_COMPILER_ARGS = new ArrayList<>();
|
||||
TEST_COMPILER_ARGS.addAll(commonCompilerArgs);
|
||||
TEST_COMPILER_ARGS.addAll(Arrays.asList("-Xlint:-varargs", "-Xlint:-fallthrough", "-Xlint:-rawtypes",
|
||||
"-Xlint:-deprecation", "-Xlint:-unchecked"));
|
||||
"-Xlint:-deprecation", "-Xlint:-unchecked", "-parameters"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
+14
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -19,7 +19,6 @@ package org.springframework.build.optional;
|
||||
import org.gradle.api.Plugin;
|
||||
import org.gradle.api.Project;
|
||||
import org.gradle.api.artifacts.Configuration;
|
||||
import org.gradle.api.attributes.Usage;
|
||||
import org.gradle.api.plugins.JavaPlugin;
|
||||
import org.gradle.api.plugins.JavaPluginConvention;
|
||||
import org.gradle.api.tasks.SourceSetContainer;
|
||||
@@ -29,7 +28,7 @@ import org.gradle.plugins.ide.eclipse.model.EclipseModel;
|
||||
/**
|
||||
* A {@code Plugin} that adds support for Maven-style optional dependencies. Creates a new
|
||||
* {@code optional} configuration. The {@code optional} configuration is part of the
|
||||
* project's compile and runtime classpaths but does not affect the classpath of
|
||||
* project's compile and runtime classpath's but does not affect the classpath of
|
||||
* dependent projects.
|
||||
*
|
||||
* @author Andy Wilkinson
|
||||
@@ -44,16 +43,22 @@ public class OptionalDependenciesPlugin implements Plugin<Project> {
|
||||
@Override
|
||||
public void apply(Project project) {
|
||||
Configuration optional = project.getConfigurations().create("optional");
|
||||
optional.setCanBeConsumed(false);
|
||||
optional.setCanBeResolved(false);
|
||||
project.getPlugins().withType(JavaPlugin.class, (javaPlugin) -> {
|
||||
SourceSetContainer sourceSets = project.getConvention().getPlugin(JavaPluginConvention.class)
|
||||
.getSourceSets();
|
||||
SourceSetContainer sourceSets = project.getConvention()
|
||||
.getPlugin(JavaPluginConvention.class).getSourceSets();
|
||||
sourceSets.all((sourceSet) -> {
|
||||
project.getConfigurations().getByName(sourceSet.getCompileClasspathConfigurationName()).extendsFrom(optional);
|
||||
project.getConfigurations().getByName(sourceSet.getRuntimeClasspathConfigurationName()).extendsFrom(optional);
|
||||
sourceSet.setCompileClasspath(
|
||||
sourceSet.getCompileClasspath().plus(optional));
|
||||
sourceSet.setRuntimeClasspath(
|
||||
sourceSet.getRuntimeClasspath().plus(optional));
|
||||
});
|
||||
});
|
||||
project.getPlugins().withType(EclipsePlugin.class, (eclipePlugin) -> {
|
||||
project.getExtensions().getByType(EclipseModel.class)
|
||||
.classpath((classpath) -> {
|
||||
classpath.getPlusConfigurations().add(optional);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,7 +4,7 @@ changelog:
|
||||
- title: ":star: New Features"
|
||||
labels:
|
||||
- "type: enhancement"
|
||||
- title: ":lady_beetle: Bug Fixes"
|
||||
- title: ":beetle: Bug Fixes"
|
||||
labels:
|
||||
- "type: bug"
|
||||
- "type: regression"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
FROM ubuntu:focal-20210827
|
||||
FROM ubuntu:focal-20210119
|
||||
|
||||
ADD setup.sh /setup.sh
|
||||
ADD get-jdk-url.sh /get-jdk-url.sh
|
||||
@@ -6,6 +6,6 @@ RUN ./setup.sh java8
|
||||
|
||||
ENV JAVA_HOME /opt/openjdk/java8
|
||||
ENV JDK11 /opt/openjdk/java11
|
||||
ENV JDK16 /opt/openjdk/java16
|
||||
ENV JDK15 /opt/openjdk/java15
|
||||
|
||||
ENV PATH $JAVA_HOME/bin:$PATH
|
||||
|
||||
@@ -3,13 +3,13 @@ set -e
|
||||
|
||||
case "$1" in
|
||||
java8)
|
||||
echo "https://github.com/adoptium/temurin8-binaries/releases/download/jdk8u302-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u302b08.tar.gz"
|
||||
echo "https://github.com/AdoptOpenJDK/openjdk8-binaries/releases/download/jdk8u282-b08/OpenJDK8U-jdk_x64_linux_hotspot_8u282b08.tar.gz"
|
||||
;;
|
||||
java11)
|
||||
echo "https://github.com/adoptium/temurin11-binaries/releases/download/jdk-11.0.12%2B7/OpenJDK11U-jdk_x64_linux_hotspot_11.0.12_7.tar.gz"
|
||||
echo "https://github.com/AdoptOpenJDK/openjdk11-binaries/releases/download/jdk-11.0.10%2B9/OpenJDK11U-jdk_x64_linux_hotspot_11.0.10_9.tar.gz"
|
||||
;;
|
||||
java16)
|
||||
echo "https://github.com/adoptium/temurin16-binaries/releases/download/jdk-16.0.2%2B7/OpenJDK16U-jdk_x64_linux_hotspot_16.0.2_7.tar.gz"
|
||||
java15)
|
||||
echo "https://github.com/AdoptOpenJDK/openjdk15-binaries/releases/download/jdk-15.0.2%2B7/OpenJDK15U-jdk_x64_linux_hotspot_15.0.2_7.tar.gz"
|
||||
;;
|
||||
*)
|
||||
echo $"Unknown java version"
|
||||
|
||||
+1
-1
@@ -22,7 +22,7 @@ curl --output /opt/concourse-release-scripts.jar https://repo.spring.io/release/
|
||||
|
||||
mkdir -p /opt/openjdk
|
||||
pushd /opt/openjdk > /dev/null
|
||||
for jdk in java8 java11 java16
|
||||
for jdk in java8 java11 java15
|
||||
do
|
||||
JDK_URL=$( /get-jdk-url.sh $jdk )
|
||||
mkdir $jdk
|
||||
|
||||
+10
-10
@@ -2,7 +2,7 @@ anchors:
|
||||
git-repo-resource-source: &git-repo-resource-source
|
||||
uri: ((github-repo))
|
||||
username: ((github-username))
|
||||
password: ((github-ci-release-token))
|
||||
password: ((github-password))
|
||||
branch: ((branch))
|
||||
gradle-enterprise-task-params: &gradle-enterprise-task-params
|
||||
GRADLE_ENTERPRISE_ACCESS_KEY: ((gradle_enterprise_secret_access_key))
|
||||
@@ -45,7 +45,7 @@ resource_types:
|
||||
type: registry-image
|
||||
source:
|
||||
repository: springio/artifactory-resource
|
||||
tag: 0.0.17
|
||||
tag: 0.0.13
|
||||
- name: github-status-resource
|
||||
type: registry-image
|
||||
source:
|
||||
@@ -119,14 +119,14 @@ resources:
|
||||
access_token: ((github-ci-status-token))
|
||||
branch: ((branch))
|
||||
context: jdk11-build
|
||||
- name: repo-status-jdk16-build
|
||||
- name: repo-status-jdk15-build
|
||||
type: github-status-resource
|
||||
icon: eye-check-outline
|
||||
source:
|
||||
repository: ((github-repo-name))
|
||||
access_token: ((github-ci-status-token))
|
||||
branch: ((branch))
|
||||
context: jdk16-build
|
||||
context: jdk15-build
|
||||
- name: slack-alert
|
||||
type: slack-notification
|
||||
icon: slack
|
||||
@@ -244,7 +244,7 @@ jobs:
|
||||
<<: *slack-fail-params
|
||||
- put: repo-status-jdk11-build
|
||||
params: { state: "success", commit: "git-repo" }
|
||||
- name: jdk16-build
|
||||
- name: jdk15-build
|
||||
serial: true
|
||||
public: true
|
||||
plan:
|
||||
@@ -252,7 +252,7 @@ jobs:
|
||||
- get: git-repo
|
||||
- get: every-morning
|
||||
trigger: true
|
||||
- put: repo-status-jdk16-build
|
||||
- put: repo-status-jdk15-build
|
||||
params: { state: "pending", commit: "git-repo" }
|
||||
- do:
|
||||
- task: check-project
|
||||
@@ -265,12 +265,12 @@ jobs:
|
||||
<<: *build-project-task-params
|
||||
on_failure:
|
||||
do:
|
||||
- put: repo-status-jdk16-build
|
||||
- put: repo-status-jdk15-build
|
||||
params: { state: "failure", commit: "git-repo" }
|
||||
- put: slack-alert
|
||||
params:
|
||||
<<: *slack-fail-params
|
||||
- put: repo-status-jdk16-build
|
||||
- put: repo-status-jdk15-build
|
||||
params: { state: "success", commit: "git-repo" }
|
||||
- name: build-pull-requests
|
||||
serial: true
|
||||
@@ -292,7 +292,7 @@ jobs:
|
||||
privileged: true
|
||||
timeout: ((task-timeout))
|
||||
params:
|
||||
BRANCH: ((branch))
|
||||
<<: *build-project-task-params
|
||||
on_success:
|
||||
put: git-pull-request
|
||||
params:
|
||||
@@ -453,7 +453,7 @@ jobs:
|
||||
|
||||
groups:
|
||||
- name: "builds"
|
||||
jobs: ["build", "jdk11-build", "jdk16-build"]
|
||||
jobs: ["build", "jdk11-build", "jdk15-build"]
|
||||
- name: "releases"
|
||||
jobs: ["stage-milestone", "stage-rc", "stage-release", "promote-milestone", "promote-rc", "promote-release", "create-github-release"]
|
||||
- name: "ci-images"
|
||||
|
||||
@@ -29,8 +29,8 @@ fi
|
||||
echo "Staging $stageVersion (next version will be $nextVersion)"
|
||||
sed -i "s/version=$snapshotVersion/version=$stageVersion/" gradle.properties
|
||||
|
||||
git config user.name "Spring Builds" > /dev/null
|
||||
git config user.email "spring-builds@users.noreply.github.com" > /dev/null
|
||||
git config user.name "Spring Buildmaster" > /dev/null
|
||||
git config user.email "buildmaster@springframework.org" > /dev/null
|
||||
git add gradle.properties > /dev/null
|
||||
git commit -m"Release v$stageVersion" > /dev/null
|
||||
git tag -a "v$stageVersion" -m"Release v$stageVersion" > /dev/null
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
version=5.3.10
|
||||
version=5.3.8
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
tasks.findByName("dokkaHtmlPartial")?.configure {
|
||||
outputDirectory.set(new File(buildDir, "docs/kdoc"))
|
||||
dokkaSourceSets {
|
||||
configureEach {
|
||||
sourceRoots.setFrom(file("src/main/kotlin"))
|
||||
classpath.from(sourceSets["main"].runtimeClasspath)
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://docs.spring.io/spring-framework/docs/current/javadoc-api/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://projectreactor.io/docs/core/release/api/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://www.reactive-streams.org/reactive-streams-1.0.3-javadoc/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://kotlin.github.io/kotlinx.coroutines/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://hamcrest.org/JavaHamcrest/javadoc/2.1/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://javadoc.io/doc/javax.servlet/javax.servlet-api/latest/"))
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url.set(new URL("https://javadoc.io/static/io.rsocket/rsocket-core/1.1.1/"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
+53
-17
@@ -61,13 +61,54 @@ task api(type: Javadoc) {
|
||||
/**
|
||||
* Produce KDoc for all Spring Framework modules in "build/docs/kdoc"
|
||||
*/
|
||||
pluginManager.withPlugin("kotlin") {
|
||||
tasks.dokkaHtmlMultiModule.configure {
|
||||
dependsOn {
|
||||
tasks.getByName("api")
|
||||
dokka {
|
||||
dependsOn {
|
||||
tasks.getByName("api")
|
||||
}
|
||||
|
||||
doFirst {
|
||||
configuration {
|
||||
classpath = moduleProjects.collect { project -> project.jar.outputs.files.getFiles() }.flatten()
|
||||
classpath += files(moduleProjects.collect { it.sourceSets.main.compileClasspath })
|
||||
|
||||
moduleProjects.findAll {
|
||||
it.pluginManager.hasPlugin("kotlin")
|
||||
}.each { project ->
|
||||
def kotlinDirs = project.sourceSets.main.kotlin.srcDirs.collect()
|
||||
kotlinDirs -= project.sourceSets.main.java.srcDirs
|
||||
kotlinDirs.each { dir ->
|
||||
if (dir.exists()) {
|
||||
sourceRoot {
|
||||
path = dir.path
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
outputFormat = "html"
|
||||
outputDirectory = "$buildDir/docs/kdoc"
|
||||
|
||||
configuration {
|
||||
moduleName = "spring-framework"
|
||||
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://docs.spring.io/spring-framework/docs/$version/javadoc-api/")
|
||||
packageListUrl = new File(buildDir, "docs/javadoc/package-list").toURI().toURL()
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://projectreactor.io/docs/core/release/api/")
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/")
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://r2dbc.io/spec/0.8.3.RELEASE/api/")
|
||||
}
|
||||
moduleName.set("spring-framework")
|
||||
outputDirectory.set(project.file("$buildDir/docs/kdoc"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -86,8 +127,6 @@ task extractDocResources(type: Copy, dependsOn: downloadResources) {
|
||||
}
|
||||
|
||||
asciidoctorj {
|
||||
def docRoot = 'https://docs.spring.io'
|
||||
def docsSpringFramework = "${docRoot}/spring-framework/docs/${project.version}"
|
||||
version = '2.4.1'
|
||||
fatalWarnings ".*"
|
||||
options doctype: 'book', eruby: 'erubis'
|
||||
@@ -95,7 +134,7 @@ asciidoctorj {
|
||||
icons: 'font',
|
||||
idprefix: '',
|
||||
idseparator: '-',
|
||||
docinfo: 'shared,private-header', // https://docs.asciidoctor.org/asciidoctor/latest/docinfo/
|
||||
docinfo: 'shared',
|
||||
revnumber: project.version,
|
||||
sectanchors: '',
|
||||
sectnums: '',
|
||||
@@ -105,10 +144,7 @@ asciidoctorj {
|
||||
stylesdir: 'css/',
|
||||
stylesheet: 'stylesheet.css',
|
||||
'spring-version': project.version,
|
||||
'spring-framework-main-code': 'https://github.com/spring-projects/spring-framework/tree/main',
|
||||
'doc-root': docRoot,
|
||||
'docs-spring-framework': docsSpringFramework,
|
||||
'api-spring-framework': "${docsSpringFramework}/javadoc-api/org/springframework"
|
||||
'spring-framework-main-code': 'https://github.com/spring-projects/spring-framework/tree/main'
|
||||
])
|
||||
}
|
||||
|
||||
@@ -149,7 +185,7 @@ asciidoctorPdf {
|
||||
/**
|
||||
* Zip all docs (API and reference) into a single archive
|
||||
*/
|
||||
task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'asciidoctorPdf', 'dokkaHtmlMultiModule']) {
|
||||
task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'asciidoctorPdf', 'dokka']) {
|
||||
group = "Distribution"
|
||||
description = "Builds -${archiveClassifier} archive containing api and reference " +
|
||||
"for deployment at https://docs.spring.io/spring-framework/docs."
|
||||
@@ -168,7 +204,7 @@ task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'asciidoctorPdf', 'dok
|
||||
from ("$asciidoctorPdf.outputDir") {
|
||||
into "reference/pdf"
|
||||
}
|
||||
from (dokkaHtmlMultiModule.outputDirectory) {
|
||||
from (dokka) {
|
||||
into "kdoc-api"
|
||||
}
|
||||
}
|
||||
@@ -225,11 +261,11 @@ task distZip(type: Zip, dependsOn: [docsZip, schemaZip]) {
|
||||
expand(copyright: new Date().format("yyyy"), version: project.version)
|
||||
}
|
||||
|
||||
from(zipTree(docsZip.archiveFile)) {
|
||||
from(zipTree(docsZip.archivePath)) {
|
||||
into "${baseDir}/docs"
|
||||
}
|
||||
|
||||
from(zipTree(schemaZip.archiveFile)) {
|
||||
from(zipTree(schemaZip.archivePath)) {
|
||||
into "${baseDir}/schema"
|
||||
}
|
||||
|
||||
|
||||
+42
-42
@@ -1,7 +1,7 @@
|
||||
import org.gradle.plugins.ide.eclipse.model.ProjectDependency
|
||||
import org.gradle.plugins.ide.eclipse.model.SourceFolder
|
||||
|
||||
apply plugin: 'eclipse'
|
||||
apply plugin: "eclipse"
|
||||
|
||||
eclipse.jdt {
|
||||
sourceCompatibility = 1.8
|
||||
@@ -18,45 +18,40 @@ eclipse.classpath.file.whenMerged { classpath ->
|
||||
if (matcher) {
|
||||
def projectName = matcher[0][1]
|
||||
def path = "/${projectName}"
|
||||
if (!classpath.entries.find { e -> e instanceof ProjectDependency && e.path == path }) {
|
||||
def recursiveDependency = entry.path.matches('.+/' + projectName + '/build/([^/]+/)+(?:main|test)')
|
||||
// Avoid recursive dependency on current project.
|
||||
if (!recursiveDependency) {
|
||||
classpath.entries.add(new ProjectDependency(path))
|
||||
}
|
||||
if(!classpath.entries.find { e -> e instanceof ProjectDependency && e.path == path }) {
|
||||
def dependency = new ProjectDependency(path)
|
||||
dependency.exported = true
|
||||
classpath.entries.add(dependency)
|
||||
}
|
||||
classpath.entries.remove(entry)
|
||||
}
|
||||
}
|
||||
|
||||
// Remove any remaining direct depencencies on JARs in the build/libs folder
|
||||
// except Spring's spring-cglib-repack and spring-objenesis-repack JARs.
|
||||
classpath.entries.removeAll { entry -> (entry.path =~ /(?!.*?repack.*\.jar).*?\/([^\/]+)\/build\/libs\/[^\/]+\.jar/) }
|
||||
}
|
||||
|
||||
// Use separate main/test outputs (prevents WTP from packaging test classes)
|
||||
eclipse.classpath.defaultOutputDir = file(project.name + '/bin/eclipse')
|
||||
eclipse.classpath.defaultOutputDir = file(project.name+"/bin/eclipse")
|
||||
eclipse.classpath.file.beforeMerged { classpath ->
|
||||
classpath.entries.findAll{ it instanceof SourceFolder }.each {
|
||||
if (it.output.startsWith('bin/')) {
|
||||
if (it.output.startsWith("bin/")) {
|
||||
it.output = null
|
||||
}
|
||||
}
|
||||
}
|
||||
eclipse.classpath.file.whenMerged {
|
||||
entries.findAll{ it instanceof SourceFolder }.each {
|
||||
it.output = 'bin/' + it.path.split('/')[1]
|
||||
eclipse.classpath.file.whenMerged { classpath ->
|
||||
classpath.entries.findAll{ it instanceof SourceFolder }.each {
|
||||
it.output = "bin/" + it.path.split("/")[1]
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure project dependencies come after 3rd-party libs (SPR-11836)
|
||||
// https://jira.spring.io/browse/SPR-11836
|
||||
eclipse.classpath.file.whenMerged {
|
||||
entries.findAll { it instanceof ProjectDependency }.each {
|
||||
eclipse.classpath.file.whenMerged { classpath ->
|
||||
classpath.entries.findAll { it instanceof ProjectDependency }.each {
|
||||
// delete from original position
|
||||
entries.remove(it)
|
||||
classpath.entries.remove(it)
|
||||
// append to end of classpath
|
||||
entries.add(it)
|
||||
classpath.entries.add(it)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,41 +65,46 @@ eclipse.classpath.file.whenMerged {
|
||||
}
|
||||
|
||||
// Allow projects to be used as WTP modules
|
||||
eclipse.project.natures 'org.eclipse.wst.common.project.facet.core.nature'
|
||||
eclipse.project.natures "org.eclipse.wst.common.project.facet.core.nature"
|
||||
|
||||
// Include project specific settings
|
||||
task eclipseSettings(type: Copy) {
|
||||
from rootProject.files(
|
||||
'src/eclipse/org.eclipse.jdt.ui.prefs',
|
||||
'src/eclipse/org.eclipse.wst.common.project.facet.core.xml')
|
||||
"src/eclipse/org.eclipse.jdt.ui.prefs",
|
||||
"src/eclipse/org.eclipse.wst.common.project.facet.core.xml")
|
||||
into project.file('.settings/')
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
task eclipseJdtSettings(type: Copy) {
|
||||
from rootProject.file('src/eclipse/org.eclipse.jdt.core.prefs')
|
||||
into project.file('.settings/')
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
task eclipseBuildship {
|
||||
dependsOn eclipseSettings, eclipseJdtSettings
|
||||
}
|
||||
|
||||
task eclipseWstComponentSettings(type: Copy) {
|
||||
from rootProject.files('src/eclipse/org.eclipse.wst.common.component')
|
||||
task eclipseWstComponent(type: Copy) {
|
||||
from rootProject.files(
|
||||
"src/eclipse/org.eclipse.wst.common.component")
|
||||
into project.file('.settings/')
|
||||
expand(deployname: project.name)
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
task cleanEclipseSettings(type: Delete) {
|
||||
delete project.file('.settings/org.eclipse.jdt.core.prefs')
|
||||
delete project.file('.settings/org.eclipse.jdt.ui.prefs')
|
||||
delete project.file('.settings/org.eclipse.wst.common.component')
|
||||
delete project.file('.settings/org.eclipse.wst.common.project.facet.core.xml')
|
||||
task eclipseJdtPrepare(type: Copy) {
|
||||
from rootProject.file("src/eclipse/org.eclipse.jdt.core.prefs")
|
||||
into project.file(".settings/")
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
tasks['eclipse'].dependsOn(eclipseSettings, eclipseJdtSettings, eclipseWstComponentSettings)
|
||||
tasks['eclipseJdt'].dependsOn(eclipseJdtSettings)
|
||||
tasks['cleanEclipse'].dependsOn(cleanEclipseSettings)
|
||||
task cleanEclipseJdtUi(type: Delete) {
|
||||
delete project.file(".settings/org.eclipse.jdt.core.prefs")
|
||||
delete project.file(".settings/org.eclipse.jdt.ui.prefs")
|
||||
delete project.file(".settings/org.eclipse.wst.common.component")
|
||||
delete project.file(".settings/org.eclipse.wst.common.project.facet.core.xml")
|
||||
}
|
||||
|
||||
task eclipseBuildship(type: Copy) {
|
||||
from rootProject.files(
|
||||
"src/eclipse/org.eclipse.jdt.ui.prefs",
|
||||
"src/eclipse/org.eclipse.jdt.core.prefs")
|
||||
into project.file('.settings/')
|
||||
outputs.upToDateWhen { false }
|
||||
}
|
||||
|
||||
tasks["eclipseJdt"].dependsOn(eclipseJdtPrepare)
|
||||
tasks["cleanEclipse"].dependsOn(cleanEclipseJdtUi)
|
||||
tasks["eclipse"].dependsOn(eclipseSettings, eclipseWstComponent)
|
||||
|
||||
@@ -8,19 +8,15 @@ apply plugin: 'me.champeau.jmh'
|
||||
apply from: "$rootDir/gradle/publications.gradle"
|
||||
|
||||
dependencies {
|
||||
jmh 'org.openjdk.jmh:jmh-core:1.32'
|
||||
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.32'
|
||||
jmh 'net.sf.jopt-simple:jopt-simple'
|
||||
jmh 'org.openjdk.jmh:jmh-core:1.28'
|
||||
jmh 'org.openjdk.jmh:jmh-generator-annprocess:1.28'
|
||||
jmh 'net.sf.jopt-simple:jopt-simple:4.6'
|
||||
}
|
||||
|
||||
jmh {
|
||||
duplicateClassesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
tasks.findByName("processJmhResources").configure {
|
||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||
}
|
||||
|
||||
jmhJar {
|
||||
// Uncomment the following for Shadow's Transformer support.
|
||||
// mergeServiceFiles()
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#!/bin/sh
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
# Copyright 2015 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,101 +17,67 @@
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
##
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
PRG="$0"
|
||||
# Need this for relative symlinks.
|
||||
while [ -h "$PRG" ] ; do
|
||||
ls=`ls -ld "$PRG"`
|
||||
link=`expr "$ls" : '.*-> \(.*\)$'`
|
||||
if expr "$link" : '/.*' > /dev/null; then
|
||||
PRG="$link"
|
||||
else
|
||||
PRG=`dirname "$PRG"`"/$link"
|
||||
fi
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
SAVED="`pwd`"
|
||||
cd "`dirname \"$PRG\"`/" >/dev/null
|
||||
APP_HOME="`pwd -P`"
|
||||
cd "$SAVED" >/dev/null
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
MAX_FD="maximum"
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
}
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
}
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
case "`uname`" in
|
||||
CYGWIN* )
|
||||
cygwin=true
|
||||
;;
|
||||
Darwin* )
|
||||
darwin=true
|
||||
;;
|
||||
MINGW* )
|
||||
msys=true
|
||||
;;
|
||||
NONSTOP* )
|
||||
nonstop=true
|
||||
;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
@@ -121,9 +87,9 @@ CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
JAVACMD="$JAVA_HOME/jre/sh/java"
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
JAVACMD="$JAVA_HOME/bin/java"
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
@@ -132,7 +98,7 @@ Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
JAVACMD="java"
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
@@ -140,95 +106,80 @@ location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
if [ "$cygwin" = "false" -a "$darwin" = "false" -a "$nonstop" = "false" ] ; then
|
||||
MAX_FD_LIMIT=`ulimit -H -n`
|
||||
if [ $? -eq 0 ] ; then
|
||||
if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then
|
||||
MAX_FD="$MAX_FD_LIMIT"
|
||||
fi
|
||||
ulimit -n $MAX_FD
|
||||
if [ $? -ne 0 ] ; then
|
||||
warn "Could not set maximum file descriptor limit: $MAX_FD"
|
||||
fi
|
||||
else
|
||||
warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT"
|
||||
fi
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
# For Darwin, add options to specify how the application appears in the dock
|
||||
if $darwin; then
|
||||
GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\""
|
||||
fi
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
|
||||
APP_HOME=`cygpath --path --mixed "$APP_HOME"`
|
||||
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
JAVACMD=`cygpath --unix "$JAVACMD"`
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
# We build the pattern for arguments to be converted via cygpath
|
||||
ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null`
|
||||
SEP=""
|
||||
for dir in $ROOTDIRSRAW ; do
|
||||
ROOTDIRS="$ROOTDIRS$SEP$dir"
|
||||
SEP="|"
|
||||
done
|
||||
OURCYGPATTERN="(^($ROOTDIRS))"
|
||||
# Add a user-defined pattern to the cygpath arguments
|
||||
if [ "$GRADLE_CYGPATTERN" != "" ] ; then
|
||||
OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)"
|
||||
fi
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
i=0
|
||||
for arg in "$@" ; do
|
||||
CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -`
|
||||
CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option
|
||||
|
||||
if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition
|
||||
eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"`
|
||||
else
|
||||
eval `echo args$i`="\"$arg\""
|
||||
fi
|
||||
i=`expr $i + 1`
|
||||
done
|
||||
case $i in
|
||||
0) set -- ;;
|
||||
1) set -- "$args0" ;;
|
||||
2) set -- "$args0" "$args1" ;;
|
||||
3) set -- "$args0" "$args1" "$args2" ;;
|
||||
4) set -- "$args0" "$args1" "$args2" "$args3" ;;
|
||||
5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;;
|
||||
6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;;
|
||||
7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;;
|
||||
8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;;
|
||||
9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;;
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
# Escape application args
|
||||
save () {
|
||||
for i do printf %s\\n "$i" | sed "s/'/'\\\\''/g;1s/^/'/;\$s/\$/' \\\\/" ; done
|
||||
echo " "
|
||||
}
|
||||
APP_ARGS=`save "$@"`
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
# Collect all arguments for the java command, following the shell quoting and substitution rules
|
||||
eval set -- $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS "\"-Dorg.gradle.appname=$APP_BASE_NAME\"" -classpath "\"$CLASSPATH\"" org.gradle.wrapper.GradleWrapperMain "$APP_ARGS"
|
||||
|
||||
exec "$JAVACMD" "$@"
|
||||
|
||||
@@ -1,26 +1,26 @@
|
||||
description = "Spring Integration Tests"
|
||||
|
||||
dependencies {
|
||||
testImplementation(project(":spring-aop"))
|
||||
testImplementation(project(":spring-beans"))
|
||||
testImplementation(project(":spring-context"))
|
||||
testImplementation(project(":spring-core"))
|
||||
testImplementation(testFixtures(project(":spring-aop")))
|
||||
testImplementation(testFixtures(project(":spring-beans")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation(testFixtures(project(":spring-tx")))
|
||||
testImplementation(project(":spring-expression"))
|
||||
testImplementation(project(":spring-jdbc"))
|
||||
testImplementation(project(":spring-orm"))
|
||||
testImplementation(project(":spring-test"))
|
||||
testImplementation(project(":spring-tx"))
|
||||
testImplementation(project(":spring-web"))
|
||||
testImplementation("javax.inject:javax.inject")
|
||||
testImplementation("javax.resource:javax.resource-api")
|
||||
testImplementation("javax.servlet:javax.servlet-api")
|
||||
testImplementation("org.aspectj:aspectjweaver")
|
||||
testImplementation("org.hsqldb:hsqldb")
|
||||
testImplementation("org.hibernate:hibernate-core")
|
||||
testCompile(project(":spring-aop"))
|
||||
testCompile(project(":spring-beans"))
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile(project(":spring-core"))
|
||||
testCompile(testFixtures(project(":spring-aop")))
|
||||
testCompile(testFixtures(project(":spring-beans")))
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testCompile(testFixtures(project(":spring-tx")))
|
||||
testCompile(project(":spring-expression"))
|
||||
testCompile(project(":spring-jdbc"))
|
||||
testCompile(project(":spring-orm"))
|
||||
testCompile(project(":spring-test"))
|
||||
testCompile(project(":spring-tx"))
|
||||
testCompile(project(":spring-web"))
|
||||
testCompile("javax.inject:javax.inject")
|
||||
testCompile("javax.resource:javax.resource-api")
|
||||
testCompile("javax.servlet:javax.servlet-api")
|
||||
testCompile("org.aspectj:aspectjweaver")
|
||||
testCompile("org.hsqldb:hsqldb")
|
||||
testCompile("org.hibernate:hibernate-core")
|
||||
}
|
||||
|
||||
normalization {
|
||||
|
||||
+4
-2
@@ -1,7 +1,7 @@
|
||||
pluginManagement {
|
||||
repositories {
|
||||
gradlePluginPortal()
|
||||
maven { url "https://repo.spring.io/plugins-release" }
|
||||
maven { url 'https://repo.spring.io/plugins-release' }
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ include "spring-context"
|
||||
include "spring-context-indexer"
|
||||
include "spring-context-support"
|
||||
include "spring-core"
|
||||
include "kotlin-coroutines"
|
||||
project(':kotlin-coroutines').projectDir = file('spring-core/kotlin-coroutines')
|
||||
include "spring-expression"
|
||||
include "spring-instrument"
|
||||
include "spring-jcl"
|
||||
@@ -49,7 +51,7 @@ settings.gradle.projectsLoaded {
|
||||
buildScanPublished { scan ->
|
||||
if (buildDir.exists()) {
|
||||
new File(buildDir, "build-scan-uri.txt").text = "${scan.buildScanUri}\n"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
description = "Spring AOP"
|
||||
|
||||
dependencies {
|
||||
api(project(":spring-beans"))
|
||||
api(project(":spring-core"))
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-core"))
|
||||
optional("org.aspectj:aspectjweaver")
|
||||
optional("org.apache.commons:commons-pool2")
|
||||
optional("com.jamonapi:jamon")
|
||||
testImplementation(testFixtures(project(":spring-beans")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testFixturesImplementation(testFixtures(project(":spring-beans")))
|
||||
testCompile(testFixtures(project(":spring-beans")))
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testFixturesImplementation(testFixtures(project(":spring-core")))
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2016 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.
|
||||
@@ -26,7 +26,7 @@ import javax.annotation.Nullable;
|
||||
* terminology).
|
||||
*
|
||||
* <p>A runtime joinpoint is an <i>event</i> that occurs on a static
|
||||
* joinpoint (i.e. a location in a program). For instance, an
|
||||
* joinpoint (i.e. a location in a the program). For instance, an
|
||||
* invocation is the runtime joinpoint on a method (static joinpoint).
|
||||
* The static part of a given joinpoint can be generically retrieved
|
||||
* using the {@link #getStaticPart()} method.
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -625,7 +625,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (bodyStart >= 0 && bodyStart != (currentToken.length() - 1)) {
|
||||
sb.append(currentToken.substring(bodyStart + 1));
|
||||
sb.append(' ');
|
||||
sb.append(" ");
|
||||
}
|
||||
numTokensConsumed++;
|
||||
int currentIndex = startIndex + numTokensConsumed;
|
||||
@@ -645,7 +645,7 @@ public class AspectJAdviceParameterNameDiscoverer implements ParameterNameDiscov
|
||||
toAppend = toAppend.substring(1);
|
||||
}
|
||||
sb.append(toAppend);
|
||||
sb.append(' ');
|
||||
sb.append(" ");
|
||||
currentIndex++;
|
||||
numTokensConsumed++;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -547,7 +547,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
StringBuilder sb = new StringBuilder("AspectJExpressionPointcut: (");
|
||||
for (int i = 0; i < this.pointcutParameterTypes.length; i++) {
|
||||
sb.append(this.pointcutParameterTypes[i].getName());
|
||||
sb.append(' ');
|
||||
sb.append(" ");
|
||||
sb.append(this.pointcutParameterNames[i]);
|
||||
if ((i+1) < this.pointcutParameterTypes.length) {
|
||||
sb.append(", ");
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -255,19 +255,19 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (includeModifier) {
|
||||
sb.append(Modifier.toString(getModifiers()));
|
||||
sb.append(' ');
|
||||
sb.append(" ");
|
||||
}
|
||||
if (includeReturnTypeAndArgs) {
|
||||
appendType(sb, getReturnType(), useLongReturnAndArgumentTypeName);
|
||||
sb.append(' ');
|
||||
sb.append(" ");
|
||||
}
|
||||
appendType(sb, getDeclaringType(), useLongTypeName);
|
||||
sb.append('.');
|
||||
sb.append(".");
|
||||
sb.append(getMethod().getName());
|
||||
sb.append('(');
|
||||
sb.append("(");
|
||||
Class<?>[] parametersTypes = getParameterTypes();
|
||||
appendTypes(sb, parametersTypes, includeReturnTypeAndArgs, useLongReturnAndArgumentTypeName);
|
||||
sb.append(')');
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
@@ -278,7 +278,7 @@ public class MethodInvocationProceedingJoinPoint implements ProceedingJoinPoint,
|
||||
for (int size = types.length, i = 0; i < size; i++) {
|
||||
appendType(sb, types[i], useLongReturnAndArgumentTypeName);
|
||||
if (i < size - 1) {
|
||||
sb.append(',');
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -103,11 +103,10 @@ public abstract class AbstractAspectJAdvisorFactory implements AspectJAdvisorFac
|
||||
@Override
|
||||
public void validate(Class<?> aspectClass) throws AopConfigException {
|
||||
// If the parent has the annotation and isn't abstract it's an error
|
||||
Class<?> superclass = aspectClass.getSuperclass();
|
||||
if (superclass.getAnnotation(Aspect.class) != null &&
|
||||
!Modifier.isAbstract(superclass.getModifiers())) {
|
||||
if (aspectClass.getSuperclass().getAnnotation(Aspect.class) != null &&
|
||||
!Modifier.isAbstract(aspectClass.getSuperclass().getModifiers())) {
|
||||
throw new AopConfigException("[" + aspectClass.getName() + "] cannot extend concrete aspect [" +
|
||||
superclass.getName() + "]");
|
||||
aspectClass.getSuperclass().getName() + "]");
|
||||
}
|
||||
|
||||
AjType<?> ajType = AjTypeSystem.getAjType(aspectClass);
|
||||
|
||||
@@ -521,8 +521,8 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
copy.copyFrom(this);
|
||||
copy.targetSource = EmptyTargetSource.forClass(getTargetClass(), getTargetSource().isStatic());
|
||||
copy.advisorChainFactory = this.advisorChainFactory;
|
||||
copy.interfaces = new ArrayList<>(this.interfaces);
|
||||
copy.advisors = new ArrayList<>(this.advisors);
|
||||
copy.interfaces = this.interfaces;
|
||||
copy.advisors = this.advisors;
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -19,9 +19,7 @@ package org.springframework.aop.framework;
|
||||
import java.lang.reflect.Array;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.aop.TargetClassAware;
|
||||
@@ -31,9 +29,7 @@ import org.springframework.aop.target.SingletonTargetSource;
|
||||
import org.springframework.core.DecoratingProxy;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for AOP proxy factories.
|
||||
@@ -48,11 +44,6 @@ import org.springframework.util.ReflectionUtils;
|
||||
*/
|
||||
public abstract class AopProxyUtils {
|
||||
|
||||
// JDK 17 Class.isSealed() method available?
|
||||
@Nullable
|
||||
private static final Method isSealedMethod = ClassUtils.getMethodIfAvailable(Class.class, "isSealed");
|
||||
|
||||
|
||||
/**
|
||||
* Obtain the singleton target object behind the given proxy, if any.
|
||||
* @param candidate the (potential) proxy to check
|
||||
@@ -139,23 +130,34 @@ public abstract class AopProxyUtils {
|
||||
specifiedInterfaces = advised.getProxiedInterfaces();
|
||||
}
|
||||
}
|
||||
List<Class<?>> proxiedInterfaces = new ArrayList<>(specifiedInterfaces.length + 3);
|
||||
for (Class<?> ifc : specifiedInterfaces) {
|
||||
// Only non-sealed interfaces are actually eligible for JDK proxying (on JDK 17)
|
||||
if (isSealedMethod == null || Boolean.FALSE.equals(ReflectionUtils.invokeMethod(isSealedMethod, ifc))) {
|
||||
proxiedInterfaces.add(ifc);
|
||||
}
|
||||
boolean addSpringProxy = !advised.isInterfaceProxied(SpringProxy.class);
|
||||
boolean addAdvised = !advised.isOpaque() && !advised.isInterfaceProxied(Advised.class);
|
||||
boolean addDecoratingProxy = (decoratingProxy && !advised.isInterfaceProxied(DecoratingProxy.class));
|
||||
int nonUserIfcCount = 0;
|
||||
if (addSpringProxy) {
|
||||
nonUserIfcCount++;
|
||||
}
|
||||
if (!advised.isInterfaceProxied(SpringProxy.class)) {
|
||||
proxiedInterfaces.add(SpringProxy.class);
|
||||
if (addAdvised) {
|
||||
nonUserIfcCount++;
|
||||
}
|
||||
if (!advised.isOpaque() && !advised.isInterfaceProxied(Advised.class)) {
|
||||
proxiedInterfaces.add(Advised.class);
|
||||
if (addDecoratingProxy) {
|
||||
nonUserIfcCount++;
|
||||
}
|
||||
if (decoratingProxy && !advised.isInterfaceProxied(DecoratingProxy.class)) {
|
||||
proxiedInterfaces.add(DecoratingProxy.class);
|
||||
Class<?>[] proxiedInterfaces = new Class<?>[specifiedInterfaces.length + nonUserIfcCount];
|
||||
System.arraycopy(specifiedInterfaces, 0, proxiedInterfaces, 0, specifiedInterfaces.length);
|
||||
int index = specifiedInterfaces.length;
|
||||
if (addSpringProxy) {
|
||||
proxiedInterfaces[index] = SpringProxy.class;
|
||||
index++;
|
||||
}
|
||||
return ClassUtils.toClassArray(proxiedInterfaces);
|
||||
if (addAdvised) {
|
||||
proxiedInterfaces[index] = Advised.class;
|
||||
index++;
|
||||
}
|
||||
if (addDecoratingProxy) {
|
||||
proxiedInterfaces[index] = DecoratingProxy.class;
|
||||
}
|
||||
return proxiedInterfaces;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-12
@@ -17,7 +17,6 @@
|
||||
package org.springframework.aop.framework.autoproxy;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -441,17 +440,7 @@ public abstract class AbstractAutoProxyCreator extends ProxyProcessorSupport
|
||||
ProxyFactory proxyFactory = new ProxyFactory();
|
||||
proxyFactory.copyFrom(this);
|
||||
|
||||
if (proxyFactory.isProxyTargetClass()) {
|
||||
// Explicit handling of JDK proxy targets (for introduction advice scenarios)
|
||||
if (Proxy.isProxyClass(beanClass)) {
|
||||
// Must allow for introductions; can't just set interfaces to the proxy's interfaces only.
|
||||
for (Class<?> ifc : beanClass.getInterfaces()) {
|
||||
proxyFactory.addInterface(ifc);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
// No proxyTargetClass flag enforced, let's apply our default checks...
|
||||
if (!proxyFactory.isProxyTargetClass()) {
|
||||
if (shouldProxyTargetClass(beanClass, beanName)) {
|
||||
proxyFactory.setProxyTargetClass(true);
|
||||
}
|
||||
|
||||
+7
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -125,8 +125,12 @@ public abstract class AbstractBeanFactoryBasedTargetSourceCreator
|
||||
*/
|
||||
protected DefaultListableBeanFactory getInternalBeanFactoryForBean(String beanName) {
|
||||
synchronized (this.internalBeanFactories) {
|
||||
return this.internalBeanFactories.computeIfAbsent(beanName,
|
||||
name -> buildInternalBeanFactory(this.beanFactory));
|
||||
DefaultListableBeanFactory internalBeanFactory = this.internalBeanFactories.get(beanName);
|
||||
if (internalBeanFactory == null) {
|
||||
internalBeanFactory = buildInternalBeanFactory(this.beanFactory);
|
||||
this.internalBeanFactories.put(beanName, internalBeanFactory);
|
||||
}
|
||||
return internalBeanFactory;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -137,7 +137,7 @@ public abstract class AbstractBeanFactoryPointcutAdvisor extends AbstractPointcu
|
||||
StringBuilder sb = new StringBuilder(getClass().getName());
|
||||
sb.append(": advice ");
|
||||
if (this.adviceBeanName != null) {
|
||||
sb.append("bean '").append(this.adviceBeanName).append('\'');
|
||||
sb.append("bean '").append(this.adviceBeanName).append("'");
|
||||
}
|
||||
else {
|
||||
sb.append(this.advice);
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -71,8 +71,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
|
||||
if (introductionInfo != null) {
|
||||
Class<?>[] introducedInterfaces = introductionInfo.getInterfaces();
|
||||
if (introducedInterfaces.length == 0) {
|
||||
throw new IllegalArgumentException(
|
||||
"IntroductionInfo defines no interfaces to introduce: " + introductionInfo);
|
||||
throw new IllegalArgumentException("IntroductionAdviceSupport implements no interfaces");
|
||||
}
|
||||
for (Class<?> ifc : introducedInterfaces) {
|
||||
addInterface(ifc);
|
||||
|
||||
+2
-2
@@ -191,9 +191,9 @@ public abstract class AbstractBeanFactoryBasedTargetSource implements TargetSour
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
|
||||
sb.append(" for target bean '").append(this.targetBeanName).append('\'');
|
||||
sb.append(" for target bean '").append(this.targetBeanName).append("'");
|
||||
if (this.targetClass != null) {
|
||||
sb.append(" of type [").append(this.targetClass.getName()).append(']');
|
||||
sb.append(" of type [").append(this.targetClass.getName()).append("]");
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
+3
-3
@@ -276,14 +276,14 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
|
||||
private static String format(String[] names) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append('(');
|
||||
sb.append("(");
|
||||
for (int i = 0; i < names.length; i++) {
|
||||
sb.append(names[i]);
|
||||
if ((i + 1) < names.length) {
|
||||
sb.append(',');
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(')');
|
||||
sb.append(")");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -183,7 +183,7 @@ public class ProxyFactoryTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetsAllInterfaces() {
|
||||
public void testGetsAllInterfaces() throws Exception {
|
||||
// Extend to get new interface
|
||||
class TestBeanSubclass extends TestBean implements Comparable<Object> {
|
||||
@Override
|
||||
@@ -240,16 +240,6 @@ public class ProxyFactoryTests {
|
||||
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 2).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSealedInterfaceExclusion() {
|
||||
// String implements ConstantDesc on JDK 12+, sealed as of JDK 17
|
||||
ProxyFactory factory = new ProxyFactory(new String());
|
||||
NopInterceptor di = new NopInterceptor();
|
||||
factory.addAdvice(0, di);
|
||||
Object proxy = factory.getProxy();
|
||||
assertThat(proxy).isInstanceOf(CharSequence.class);
|
||||
}
|
||||
|
||||
/**
|
||||
* Should see effect immediately on behavior.
|
||||
*/
|
||||
|
||||
@@ -11,7 +11,7 @@ sourceSets.test.java.srcDirs = files()
|
||||
aspectj.version = dependencyManagement.managedVersions['org.aspectj:aspectjweaver']
|
||||
|
||||
dependencies {
|
||||
api("org.aspectj:aspectjweaver")
|
||||
compile("org.aspectj:aspectjweaver")
|
||||
compileOnly("org.aspectj:aspectjrt")
|
||||
optional(project(":spring-aop")) // for @Async support
|
||||
optional(project(":spring-beans")) // for @Configurable support
|
||||
@@ -21,13 +21,13 @@ dependencies {
|
||||
optional(project(":spring-tx")) // for JPA, @Transactional support
|
||||
optional("javax.cache:cache-api") // for JCache aspect
|
||||
optional("javax.transaction:javax.transaction-api") // for @javax.transaction.Transactional support
|
||||
testImplementation(project(":spring-core")) // for CodeStyleAspect
|
||||
testImplementation(project(":spring-test"))
|
||||
testImplementation(testFixtures(project(":spring-context")))
|
||||
testImplementation(testFixtures(project(":spring-context-support")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation(testFixtures(project(":spring-tx")))
|
||||
testImplementation("javax.mail:javax.mail-api")
|
||||
testCompile(project(":spring-core")) // for CodeStyleAspect
|
||||
testCompile(project(":spring-test"))
|
||||
testCompile(testFixtures(project(":spring-context")))
|
||||
testCompile(testFixtures(project(":spring-context-support")))
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testCompile(testFixtures(project(":spring-tx")))
|
||||
testCompile("javax.mail:javax.mail-api")
|
||||
testCompileOnly("org.aspectj:aspectjrt")
|
||||
}
|
||||
|
||||
|
||||
@@ -4,14 +4,14 @@ apply plugin: "groovy"
|
||||
apply plugin: "kotlin"
|
||||
|
||||
dependencies {
|
||||
api(project(":spring-core"))
|
||||
compile(project(":spring-core"))
|
||||
optional("javax.inject:javax.inject")
|
||||
optional("org.yaml:snakeyaml")
|
||||
optional("org.codehaus.groovy:groovy-xml")
|
||||
optional("org.jetbrains.kotlin:kotlin-reflect")
|
||||
optional("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation("javax.annotation:javax.annotation-api")
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testCompile("javax.annotation:javax.annotation-api")
|
||||
testFixturesApi("org.junit.jupiter:junit-jupiter-api")
|
||||
testFixturesImplementation("org.assertj:assertj-core")
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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,6 +41,8 @@ import kotlin.reflect.KParameter;
|
||||
import kotlin.reflect.full.KClasses;
|
||||
import kotlin.reflect.jvm.KCallablesJvm;
|
||||
import kotlin.reflect.jvm.ReflectJvmMapping;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.DefaultParameterNameDiscoverer;
|
||||
import org.springframework.core.KotlinDetector;
|
||||
@@ -73,6 +75,8 @@ import org.springframework.util.StringUtils;
|
||||
*/
|
||||
public abstract class BeanUtils {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(BeanUtils.class);
|
||||
|
||||
private static final ParameterNameDiscoverer parameterNameDiscoverer =
|
||||
new DefaultParameterNameDiscoverer();
|
||||
|
||||
@@ -87,10 +91,7 @@ public abstract class BeanUtils {
|
||||
values.put(byte.class, (byte) 0);
|
||||
values.put(short.class, (short) 0);
|
||||
values.put(int.class, 0);
|
||||
values.put(long.class, 0L);
|
||||
values.put(float.class, 0F);
|
||||
values.put(double.class, 0D);
|
||||
values.put(char.class, '\0');
|
||||
values.put(long.class, (long) 0);
|
||||
DEFAULT_TYPE_VALUES = Collections.unmodifiableMap(values);
|
||||
}
|
||||
|
||||
@@ -550,6 +551,9 @@ public abstract class BeanUtils {
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
// e.g. AccessControlException on Google App Engine
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug("Could not access system ClassLoader: " + ex);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -560,6 +564,10 @@ public abstract class BeanUtils {
|
||||
Class<?> editorClass = cl.loadClass(editorName);
|
||||
if (editorClass != null) {
|
||||
if (!PropertyEditor.class.isAssignableFrom(editorClass)) {
|
||||
if (logger.isInfoEnabled()) {
|
||||
logger.info("Editor class [" + editorName +
|
||||
"] does not implement [java.beans.PropertyEditor] interface");
|
||||
}
|
||||
unknownEditorTypes.add(targetType);
|
||||
return null;
|
||||
}
|
||||
@@ -571,6 +579,10 @@ public abstract class BeanUtils {
|
||||
catch (ClassNotFoundException ex) {
|
||||
// Ignore - fall back to unknown editor type registration below
|
||||
}
|
||||
if (logger.isTraceEnabled()) {
|
||||
logger.trace("No property editor [" + editorName + "] found for type " +
|
||||
targetTypeName + " according to 'Editor' suffix convention");
|
||||
}
|
||||
unknownEditorTypes.add(targetType);
|
||||
return null;
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -138,7 +138,7 @@ final class GenericTypeAwarePropertyDescriptor extends PropertyDescriptor {
|
||||
Set<Method> ambiguousCandidates = this.ambiguousWriteMethods;
|
||||
if (ambiguousCandidates != null) {
|
||||
this.ambiguousWriteMethods = null;
|
||||
LogFactory.getLog(GenericTypeAwarePropertyDescriptor.class).debug("Non-unique JavaBean property '" +
|
||||
LogFactory.getLog(GenericTypeAwarePropertyDescriptor.class).warn("Invalid JavaBean property '" +
|
||||
getName() + "' being accessed! Ambiguous write methods found next to actually used [" +
|
||||
this.writeMethod + "]: " + ambiguousCandidates);
|
||||
}
|
||||
|
||||
@@ -247,14 +247,14 @@ class TypeConverterDelegate {
|
||||
// Definitely doesn't match: throw IllegalArgumentException/IllegalStateException
|
||||
StringBuilder msg = new StringBuilder();
|
||||
msg.append("Cannot convert value of type '").append(ClassUtils.getDescriptiveType(newValue));
|
||||
msg.append("' to required type '").append(ClassUtils.getQualifiedName(requiredType)).append('\'');
|
||||
msg.append("' to required type '").append(ClassUtils.getQualifiedName(requiredType)).append("'");
|
||||
if (propertyName != null) {
|
||||
msg.append(" for property '").append(propertyName).append('\'');
|
||||
msg.append(" for property '").append(propertyName).append("'");
|
||||
}
|
||||
if (editor != null) {
|
||||
msg.append(": PropertyEditor [").append(editor.getClass().getName()).append(
|
||||
"] returned inappropriate value of type '").append(
|
||||
ClassUtils.getDescriptiveType(convertedValue)).append('\'');
|
||||
ClassUtils.getDescriptiveType(convertedValue)).append("'");
|
||||
throw new IllegalArgumentException(msg.toString());
|
||||
}
|
||||
else {
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -217,13 +217,13 @@ public class RequiredAnnotationBeanPostProcessor implements SmartInstantiationAw
|
||||
sb.append(" and");
|
||||
}
|
||||
else {
|
||||
sb.append(',');
|
||||
sb.append(",");
|
||||
}
|
||||
}
|
||||
sb.append(" '").append(propertyName).append('\'');
|
||||
sb.append(" '").append(propertyName).append("'");
|
||||
}
|
||||
sb.append(size == 1 ? " is" : " are");
|
||||
sb.append(" required for bean '").append(beanName).append('\'');
|
||||
sb.append(" required for bean '").append(beanName).append("'");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
+2
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -351,9 +351,7 @@ public class ConstructorArgumentValues {
|
||||
* @return the ValueHolder for the argument, or {@code null} if none set
|
||||
*/
|
||||
@Nullable
|
||||
public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType,
|
||||
@Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) {
|
||||
|
||||
public ValueHolder getArgumentValue(int index, @Nullable Class<?> requiredType, @Nullable String requiredName, @Nullable Set<ValueHolder> usedValueHolders) {
|
||||
Assert.isTrue(index >= 0, "Index must not be negative");
|
||||
ValueHolder valueHolder = getIndexedArgumentValue(index, requiredType, requiredName);
|
||||
if (valueHolder == null) {
|
||||
|
||||
+3
-3
@@ -489,9 +489,9 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
||||
resolveConstructorArguments(args, 2, hasClosureArgument ? args.length - 1 : args.length);
|
||||
this.currentBeanDefinition = new GroovyBeanDefinitionWrapper(beanName, (Class<?>) args[1], constructorArgs);
|
||||
Map<?, ?> namedArgs = (Map<?, ?>) args[0];
|
||||
for (Map.Entry<?, ?> entity : namedArgs.entrySet()) {
|
||||
String propName = (String) entity.getKey();
|
||||
setProperty(propName, entity.getValue());
|
||||
for (Object key : namedArgs.keySet()) {
|
||||
String propName = (String) key;
|
||||
setProperty(propName, namedArgs.get(propName));
|
||||
}
|
||||
}
|
||||
// factory method syntax
|
||||
|
||||
-18
@@ -246,15 +246,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
this.allowCircularReferences = allowCircularReferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to allow circular references between beans.
|
||||
* @since 5.3.10
|
||||
* @see #setAllowCircularReferences
|
||||
*/
|
||||
public boolean isAllowCircularReferences() {
|
||||
return this.allowCircularReferences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to allow the raw injection of a bean instance into some other
|
||||
* bean's property, despite the injected bean eventually getting wrapped
|
||||
@@ -273,15 +264,6 @@ public abstract class AbstractAutowireCapableBeanFactory extends AbstractBeanFac
|
||||
this.allowRawInjectionDespiteWrapping = allowRawInjectionDespiteWrapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether to allow the raw injection of a bean instance.
|
||||
* @since 5.3.10
|
||||
* @see #setAllowRawInjectionDespiteWrapping
|
||||
*/
|
||||
public boolean isAllowRawInjectionDespiteWrapping() {
|
||||
return this.allowRawInjectionDespiteWrapping;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ignore the given dependency type for autowiring:
|
||||
* for example, String. Default is none.
|
||||
|
||||
+1
-1
@@ -1241,7 +1241,7 @@ public abstract class AbstractBeanDefinition extends BeanMetadataAttributeAccess
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("class [");
|
||||
sb.append(getBeanClassName()).append(']');
|
||||
sb.append(getBeanClassName()).append("]");
|
||||
sb.append("; scope=").append(this.scope);
|
||||
sb.append("; abstract=").append(this.abstractFlag);
|
||||
sb.append("; lazyInit=").append(this.lazyInit);
|
||||
|
||||
+2
-37
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -21,7 +21,6 @@ import java.util.function.Supplier;
|
||||
import org.springframework.beans.factory.config.AutowiredPropertyMarker;
|
||||
import org.springframework.beans.factory.config.BeanDefinitionCustomizer;
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -103,7 +102,7 @@ public final class BeanDefinitionBuilder {
|
||||
* @param beanClass the {@code Class} of the bean that the definition is being created for
|
||||
*/
|
||||
public static BeanDefinitionBuilder rootBeanDefinition(Class<?> beanClass) {
|
||||
return rootBeanDefinition(beanClass, (String) null);
|
||||
return rootBeanDefinition(beanClass, null);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -118,30 +117,6 @@ public final class BeanDefinitionBuilder {
|
||||
return builder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link RootBeanDefinition}.
|
||||
* @param beanType the {@link ResolvableType type} of the bean that the definition is being created for
|
||||
* @param instanceSupplier a callback for creating an instance of the bean
|
||||
* @since 5.3.9
|
||||
*/
|
||||
public static <T> BeanDefinitionBuilder rootBeanDefinition(ResolvableType beanType, Supplier<T> instanceSupplier) {
|
||||
RootBeanDefinition beanDefinition = new RootBeanDefinition();
|
||||
beanDefinition.setTargetType(beanType);
|
||||
beanDefinition.setInstanceSupplier(instanceSupplier);
|
||||
return new BeanDefinitionBuilder(beanDefinition);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link RootBeanDefinition}.
|
||||
* @param beanClass the {@code Class} of the bean that the definition is being created for
|
||||
* @param instanceSupplier a callback for creating an instance of the bean
|
||||
* @since 5.3.9
|
||||
* @see #rootBeanDefinition(ResolvableType, Supplier)
|
||||
*/
|
||||
public static <T> BeanDefinitionBuilder rootBeanDefinition(Class<T> beanClass, Supplier<T> instanceSupplier) {
|
||||
return rootBeanDefinition(ResolvableType.forClass(beanClass), instanceSupplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@code BeanDefinitionBuilder} used to construct a {@link ChildBeanDefinition}.
|
||||
* @param parentName the name of the parent bean
|
||||
@@ -356,16 +331,6 @@ public final class BeanDefinitionBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether this bean is 'synthetic', that is, not defined by
|
||||
* the application itself.
|
||||
* @since 5.3.9
|
||||
*/
|
||||
public BeanDefinitionBuilder setSynthetic(boolean synthetic) {
|
||||
this.beanDefinition.setSynthetic(synthetic);
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Apply the given customizers to the underlying bean definition.
|
||||
* @since 5.0
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -277,12 +277,12 @@ class ConstructorResolver {
|
||||
throw ex;
|
||||
}
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Could not resolve matching constructor on bean class [" + mbd.getBeanClassName() + "] " +
|
||||
"Could not resolve matching constructor " +
|
||||
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities)");
|
||||
}
|
||||
else if (ambiguousConstructors != null && !mbd.isLenientConstructorResolution()) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Ambiguous constructor matches found on bean class [" + mbd.getBeanClassName() + "] " +
|
||||
"Ambiguous constructor matches found in bean '" + beanName + "' " +
|
||||
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities): " +
|
||||
ambiguousConstructors);
|
||||
}
|
||||
@@ -608,7 +608,7 @@ class ConstructorResolver {
|
||||
}
|
||||
String argDesc = StringUtils.collectionToCommaDelimitedString(argTypes);
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"No matching factory method found on class [" + factoryClass.getName() + "]: " +
|
||||
"No matching factory method found: " +
|
||||
(mbd.getFactoryBeanName() != null ?
|
||||
"factory bean '" + mbd.getFactoryBeanName() + "'; " : "") +
|
||||
"factory method '" + mbd.getFactoryMethodName() + "(" + argDesc + ")'. " +
|
||||
@@ -619,12 +619,12 @@ class ConstructorResolver {
|
||||
}
|
||||
else if (void.class == factoryMethodToUse.getReturnType()) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Invalid factory method '" + mbd.getFactoryMethodName() + "' on class [" +
|
||||
factoryClass.getName() + "]: needs to have a non-void return type!");
|
||||
"Invalid factory method '" + mbd.getFactoryMethodName() +
|
||||
"': needs to have a non-void return type!");
|
||||
}
|
||||
else if (ambiguousFactoryMethods != null) {
|
||||
throw new BeanCreationException(mbd.getResourceDescription(), beanName,
|
||||
"Ambiguous factory method matches found on class [" + factoryClass.getName() + "] " +
|
||||
"Ambiguous factory method matches found in bean '" + beanName + "' " +
|
||||
"(hint: specify index/type/name arguments for simple parameters to avoid type ambiguities): " +
|
||||
ambiguousFactoryMethods);
|
||||
}
|
||||
|
||||
+269
-200
File diff suppressed because it is too large
Load Diff
@@ -49,7 +49,6 @@ import org.springframework.lang.Nullable;
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.SoftAssertions.assertSoftly;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link BeanUtils}.
|
||||
@@ -86,43 +85,19 @@ class BeanUtilsTests {
|
||||
}
|
||||
|
||||
@Test // gh-22531
|
||||
void instantiateClassWithFewerArgsThanParameters() throws NoSuchMethodException {
|
||||
Constructor<BeanWithPrimitiveTypes> constructor = getBeanWithPrimitiveTypesConstructor();
|
||||
|
||||
assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() ->
|
||||
BeanUtils.instantiateClass(constructor, null, null, "foo"));
|
||||
void instantiateClassWithOptionalPrimitiveType() throws NoSuchMethodException {
|
||||
Constructor<BeanWithPrimitiveTypes> ctor = BeanWithPrimitiveTypes.class.getDeclaredConstructor(int.class, boolean.class, String.class);
|
||||
BeanWithPrimitiveTypes bean = BeanUtils.instantiateClass(ctor, null, null, "foo");
|
||||
assertThat(bean.getCounter()).isEqualTo(0);
|
||||
assertThat(bean.isFlag()).isEqualTo(false);
|
||||
assertThat(bean.getValue()).isEqualTo("foo");
|
||||
}
|
||||
|
||||
@Test // gh-22531
|
||||
void instantiateClassWithMoreArgsThanParameters() throws NoSuchMethodException {
|
||||
Constructor<BeanWithPrimitiveTypes> constructor = getBeanWithPrimitiveTypesConstructor();
|
||||
|
||||
Constructor<BeanWithPrimitiveTypes> ctor = BeanWithPrimitiveTypes.class.getDeclaredConstructor(int.class, boolean.class, String.class);
|
||||
assertThatExceptionOfType(BeanInstantiationException.class).isThrownBy(() ->
|
||||
BeanUtils.instantiateClass(constructor, null, null, null, null, null, null, null, null, "foo", null));
|
||||
}
|
||||
|
||||
@Test // gh-22531, gh-27390
|
||||
void instantiateClassWithOptionalPrimitiveTypes() throws NoSuchMethodException {
|
||||
Constructor<BeanWithPrimitiveTypes> constructor = getBeanWithPrimitiveTypesConstructor();
|
||||
|
||||
BeanWithPrimitiveTypes bean = BeanUtils.instantiateClass(constructor, null, null, null, null, null, null, null, null, "foo");
|
||||
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(bean.isFlag()).isFalse();
|
||||
softly.assertThat(bean.getByteCount()).isEqualTo((byte) 0);
|
||||
softly.assertThat(bean.getShortCount()).isEqualTo((short) 0);
|
||||
softly.assertThat(bean.getIntCount()).isEqualTo(0);
|
||||
softly.assertThat(bean.getLongCount()).isEqualTo(0L);
|
||||
softly.assertThat(bean.getFloatCount()).isEqualTo(0F);
|
||||
softly.assertThat(bean.getDoubleCount()).isEqualTo(0D);
|
||||
softly.assertThat(bean.getCharacter()).isEqualTo('\0');
|
||||
softly.assertThat(bean.getText()).isEqualTo("foo");
|
||||
});
|
||||
}
|
||||
|
||||
private Constructor<BeanWithPrimitiveTypes> getBeanWithPrimitiveTypesConstructor() throws NoSuchMethodException {
|
||||
return BeanWithPrimitiveTypes.class.getConstructor(boolean.class, byte.class, short.class, int.class,
|
||||
long.class, float.class, double.class, char.class, String.class);
|
||||
BeanUtils.instantiateClass(ctor, null, null, "foo", null));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -653,68 +628,30 @@ class BeanUtilsTests {
|
||||
|
||||
private static class BeanWithPrimitiveTypes {
|
||||
|
||||
private boolean flag;
|
||||
private byte byteCount;
|
||||
private short shortCount;
|
||||
private int intCount;
|
||||
private long longCount;
|
||||
private float floatCount;
|
||||
private double doubleCount;
|
||||
private char character;
|
||||
private String text;
|
||||
private int counter;
|
||||
|
||||
private boolean flag;
|
||||
|
||||
private String value;
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
public BeanWithPrimitiveTypes(boolean flag, byte byteCount, short shortCount, int intCount, long longCount,
|
||||
float floatCount, double doubleCount, char character, String text) {
|
||||
|
||||
public BeanWithPrimitiveTypes(int counter, boolean flag, String value) {
|
||||
this.counter = counter;
|
||||
this.flag = flag;
|
||||
this.byteCount = byteCount;
|
||||
this.shortCount = shortCount;
|
||||
this.intCount = intCount;
|
||||
this.longCount = longCount;
|
||||
this.floatCount = floatCount;
|
||||
this.doubleCount = doubleCount;
|
||||
this.character = character;
|
||||
this.text = text;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public int getCounter() {
|
||||
return counter;
|
||||
}
|
||||
|
||||
public boolean isFlag() {
|
||||
return flag;
|
||||
}
|
||||
|
||||
public byte getByteCount() {
|
||||
return byteCount;
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public short getShortCount() {
|
||||
return shortCount;
|
||||
}
|
||||
|
||||
public int getIntCount() {
|
||||
return intCount;
|
||||
}
|
||||
|
||||
public long getLongCount() {
|
||||
return longCount;
|
||||
}
|
||||
|
||||
public float getFloatCount() {
|
||||
return floatCount;
|
||||
}
|
||||
|
||||
public double getDoubleCount() {
|
||||
return doubleCount;
|
||||
}
|
||||
|
||||
public char getCharacter() {
|
||||
return character;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private static class PrivateBeanWithPrivateConstructor {
|
||||
|
||||
+1
-1
@@ -38,7 +38,7 @@ public class BeanWrapperAutoGrowingTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
public void setUp() {
|
||||
wrapper.setAutoGrowNestedPaths(true);
|
||||
}
|
||||
|
||||
|
||||
+80
-72
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.beans;
|
||||
|
||||
import java.net.MalformedURLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
@@ -45,10 +46,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Chris Beams
|
||||
* @since 18.01.2006
|
||||
*/
|
||||
class BeanWrapperGenericsTests {
|
||||
public class BeanWrapperGenericsTests {
|
||||
|
||||
@Test
|
||||
void testGenericSet() {
|
||||
public void testGenericSet() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
Set<String> input = new HashSet<>();
|
||||
@@ -60,7 +61,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericLowerBoundedSet() {
|
||||
public void testGenericLowerBoundedSet() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, true));
|
||||
@@ -73,7 +74,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetWithConversionFailure() {
|
||||
public void testGenericSetWithConversionFailure() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
Set<TestBean> input = new HashSet<>();
|
||||
@@ -84,7 +85,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericList() throws Exception {
|
||||
public void testGenericList() throws MalformedURLException {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
List<String> input = new ArrayList<>();
|
||||
@@ -96,7 +97,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListElement() throws Exception {
|
||||
public void testGenericListElement() throws MalformedURLException {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
gb.setResourceList(new ArrayList<>());
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
@@ -105,29 +106,29 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMap() {
|
||||
public void testGenericMap() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
Map<String, String> input = new HashMap<>();
|
||||
input.put("4", "5");
|
||||
input.put("6", "7");
|
||||
bw.setPropertyValue("shortMap", input);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapElement() {
|
||||
public void testGenericMapElement() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
gb.setShortMap(new HashMap<>());
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("shortMap[4]", "5");
|
||||
assertThat(bw.getPropertyValue("shortMap[4]")).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithKeyType() {
|
||||
public void testGenericMapWithKeyType() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
Map<String, String> input = new HashMap<>();
|
||||
@@ -139,17 +140,17 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapElementWithKeyType() {
|
||||
public void testGenericMapElementWithKeyType() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
gb.setLongMap(new HashMap<Long, Integer>());
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("longMap[4]", "5");
|
||||
assertThat(gb.getLongMap().get(Long.valueOf("4"))).isEqualTo("5");
|
||||
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
|
||||
assertThat(bw.getPropertyValue("longMap[4]")).isEqualTo("5");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithCollectionValue() {
|
||||
public void testGenericMapWithCollectionValue() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.registerCustomEditor(Number.class, new CustomNumberEditor(Integer.class, false));
|
||||
@@ -161,12 +162,14 @@ class BeanWrapperGenericsTests {
|
||||
value2.add(Boolean.TRUE);
|
||||
input.put("2", value2);
|
||||
bw.setPropertyValue("collectionMap", input);
|
||||
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
|
||||
assertThat(gb.getCollectionMap().get(2) instanceof ArrayList).isTrue();
|
||||
boolean condition1 = gb.getCollectionMap().get(1) instanceof HashSet;
|
||||
assertThat(condition1).isTrue();
|
||||
boolean condition = gb.getCollectionMap().get(2) instanceof ArrayList;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapElementWithCollectionValue() {
|
||||
public void testGenericMapElementWithCollectionValue() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
gb.setCollectionMap(new HashMap<>());
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
@@ -174,23 +177,24 @@ class BeanWrapperGenericsTests {
|
||||
HashSet<Integer> value1 = new HashSet<>();
|
||||
value1.add(1);
|
||||
bw.setPropertyValue("collectionMap[1]", value1);
|
||||
assertThat(gb.getCollectionMap().get(1) instanceof HashSet).isTrue();
|
||||
boolean condition = gb.getCollectionMap().get(1) instanceof HashSet;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapFromProperties() {
|
||||
public void testGenericMapFromProperties() {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
Properties input = new Properties();
|
||||
input.setProperty("4", "5");
|
||||
input.setProperty("6", "7");
|
||||
bw.setPropertyValue("shortMap", input);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfLists() {
|
||||
public void testGenericListOfLists() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
List<List<Integer>> list = new ArrayList<>();
|
||||
list.add(new ArrayList<>());
|
||||
@@ -202,7 +206,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfListsWithElementConversion() {
|
||||
public void testGenericListOfListsWithElementConversion() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
List<List<Integer>> list = new ArrayList<>();
|
||||
list.add(new ArrayList<>());
|
||||
@@ -214,7 +218,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfArrays() {
|
||||
public void testGenericListOfArrays() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
ArrayList<String[]> list = new ArrayList<>();
|
||||
list.add(new String[] {"str1", "str2"});
|
||||
@@ -226,7 +230,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfArraysWithElementConversion() {
|
||||
public void testGenericListOfArraysWithElementConversion() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
ArrayList<String[]> list = new ArrayList<>();
|
||||
list.add(new String[] {"str1", "str2"});
|
||||
@@ -239,55 +243,55 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfMaps() {
|
||||
public void testGenericListOfMaps() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
List<Map<Integer, Long>> list = new ArrayList<>();
|
||||
list.add(new HashMap<>());
|
||||
gb.setListOfMaps(list);
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("listOfMaps[0][10]", 5L);
|
||||
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(5L);
|
||||
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(Long.valueOf(5));
|
||||
bw.setPropertyValue("listOfMaps[0][10]", new Long(5));
|
||||
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
|
||||
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfMapsWithElementConversion() {
|
||||
public void testGenericListOfMapsWithElementConversion() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
List<Map<Integer, Long>> list = new ArrayList<>();
|
||||
list.add(new HashMap<>());
|
||||
gb.setListOfMaps(list);
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("listOfMaps[0][10]", "5");
|
||||
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(5L);
|
||||
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(Long.valueOf(5));
|
||||
assertThat(bw.getPropertyValue("listOfMaps[0][10]")).isEqualTo(new Long(5));
|
||||
assertThat(gb.getListOfMaps().get(0).get(10)).isEqualTo(new Long(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapOfMaps() {
|
||||
public void testGenericMapOfMaps() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
Map<String, Map<Integer, Long>> map = new HashMap<>();
|
||||
map.put("mykey", new HashMap<>());
|
||||
gb.setMapOfMaps(map);
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("mapOfMaps[mykey][10]", 5L);
|
||||
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(5L);
|
||||
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(Long.valueOf(5));
|
||||
bw.setPropertyValue("mapOfMaps[mykey][10]", new Long(5));
|
||||
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
|
||||
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapOfMapsWithElementConversion() {
|
||||
public void testGenericMapOfMapsWithElementConversion() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
Map<String, Map<Integer, Long>> map = new HashMap<>();
|
||||
map.put("mykey", new HashMap<>());
|
||||
gb.setMapOfMaps(map);
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("mapOfMaps[mykey][10]", "5");
|
||||
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(Long.valueOf(5));
|
||||
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(Long.valueOf(5));
|
||||
assertThat(bw.getPropertyValue("mapOfMaps[mykey][10]")).isEqualTo(new Long(5));
|
||||
assertThat(gb.getMapOfMaps().get("mykey").get(10)).isEqualTo(new Long(5));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapOfLists() {
|
||||
public void testGenericMapOfLists() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
Map<Integer, List<Integer>> map = new HashMap<>();
|
||||
map.put(1, new ArrayList<>());
|
||||
@@ -299,7 +303,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapOfListsWithElementConversion() {
|
||||
public void testGenericMapOfListsWithElementConversion() throws MalformedURLException {
|
||||
GenericBean<String> gb = new GenericBean<>();
|
||||
Map<Integer, List<Integer>> map = new HashMap<>();
|
||||
map.put(1, new ArrayList<>());
|
||||
@@ -311,7 +315,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericTypeNestingMapOfInteger() {
|
||||
public void testGenericTypeNestingMapOfInteger() throws Exception {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("testKey", "100");
|
||||
|
||||
@@ -320,13 +324,14 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("mapOfInteger", map);
|
||||
|
||||
Object obj = gb.getMapOfInteger().get("testKey");
|
||||
assertThat(obj instanceof Integer).isTrue();
|
||||
boolean condition = obj instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericTypeNestingMapOfListOfInteger() {
|
||||
public void testGenericTypeNestingMapOfListOfInteger() throws Exception {
|
||||
Map<String, List<String>> map = new HashMap<>();
|
||||
List<String> list = Arrays.asList("1", "2", "3");
|
||||
List<String> list = Arrays.asList(new String[] {"1", "2", "3"});
|
||||
map.put("testKey", list);
|
||||
|
||||
NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
|
||||
@@ -334,12 +339,13 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("mapOfListOfInteger", map);
|
||||
|
||||
Object obj = gb.getMapOfListOfInteger().get("testKey").get(0);
|
||||
assertThat(obj instanceof Integer).isTrue();
|
||||
boolean condition = obj instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((Integer) obj).intValue()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericTypeNestingListOfMapOfInteger() {
|
||||
public void testGenericTypeNestingListOfMapOfInteger() throws Exception {
|
||||
List<Map<String, String>> list = new ArrayList<>();
|
||||
Map<String, String> map = new HashMap<>();
|
||||
map.put("testKey", "5");
|
||||
@@ -350,14 +356,15 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("listOfMapOfInteger", list);
|
||||
|
||||
Object obj = gb.getListOfMapOfInteger().get(0).get("testKey");
|
||||
assertThat(obj instanceof Integer).isTrue();
|
||||
boolean condition = obj instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((Integer) obj).intValue()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericTypeNestingMapOfListOfListOfInteger() {
|
||||
public void testGenericTypeNestingMapOfListOfListOfInteger() throws Exception {
|
||||
Map<String, List<List<String>>> map = new HashMap<>();
|
||||
List<String> list = Arrays.asList("1", "2", "3");
|
||||
List<String> list = Arrays.asList(new String[] {"1", "2", "3"});
|
||||
map.put("testKey", Collections.singletonList(list));
|
||||
|
||||
NestedGenericCollectionBean gb = new NestedGenericCollectionBean();
|
||||
@@ -365,12 +372,13 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("mapOfListOfListOfInteger", map);
|
||||
|
||||
Object obj = gb.getMapOfListOfListOfInteger().get("testKey").get(0).get(0);
|
||||
assertThat(obj instanceof Integer).isTrue();
|
||||
boolean condition = obj instanceof Integer;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(((Integer) obj).intValue()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexGenericMap() {
|
||||
public void testComplexGenericMap() {
|
||||
Map<List<String>, List<String>> inputMap = new HashMap<>();
|
||||
List<String> inputKey = new ArrayList<>();
|
||||
inputKey.add("1");
|
||||
@@ -383,11 +391,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("genericMap", inputMap);
|
||||
|
||||
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(1);
|
||||
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexGenericMapWithCollectionConversion() {
|
||||
public void testComplexGenericMapWithCollectionConversion() {
|
||||
Map<Set<String>, Set<String>> inputMap = new HashMap<>();
|
||||
Set<String> inputKey = new HashSet<>();
|
||||
inputKey.add("1");
|
||||
@@ -400,11 +408,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("genericMap", inputMap);
|
||||
|
||||
assertThat(holder.getGenericMap().keySet().iterator().next().get(0)).isEqualTo(1);
|
||||
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getGenericMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexGenericIndexedMapEntry() {
|
||||
public void testComplexGenericIndexedMapEntry() {
|
||||
List<String> inputValue = new ArrayList<>();
|
||||
inputValue.add("10");
|
||||
|
||||
@@ -413,11 +421,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
|
||||
|
||||
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(1);
|
||||
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexGenericIndexedMapEntryWithCollectionConversion() {
|
||||
public void testComplexGenericIndexedMapEntryWithCollectionConversion() {
|
||||
Set<String> inputValue = new HashSet<>();
|
||||
inputValue.add("10");
|
||||
|
||||
@@ -426,11 +434,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("genericIndexedMap[1]", inputValue);
|
||||
|
||||
assertThat(holder.getGenericIndexedMap().keySet().iterator().next()).isEqualTo(1);
|
||||
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getGenericIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexDerivedIndexedMapEntry() {
|
||||
public void testComplexDerivedIndexedMapEntry() {
|
||||
List<String> inputValue = new ArrayList<>();
|
||||
inputValue.add("10");
|
||||
|
||||
@@ -439,11 +447,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
|
||||
|
||||
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(1);
|
||||
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexDerivedIndexedMapEntryWithCollectionConversion() {
|
||||
public void testComplexDerivedIndexedMapEntryWithCollectionConversion() {
|
||||
Set<String> inputValue = new HashSet<>();
|
||||
inputValue.add("10");
|
||||
|
||||
@@ -452,11 +460,11 @@ class BeanWrapperGenericsTests {
|
||||
bw.setPropertyValue("derivedIndexedMap[1]", inputValue);
|
||||
|
||||
assertThat(holder.getDerivedIndexedMap().keySet().iterator().next()).isEqualTo(1);
|
||||
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(Long.valueOf(10));
|
||||
assertThat(holder.getDerivedIndexedMap().values().iterator().next().get(0)).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericallyTypedIntegerBean() {
|
||||
public void testGenericallyTypedIntegerBean() throws Exception {
|
||||
GenericIntegerBean gb = new GenericIntegerBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("genericProperty", "10");
|
||||
@@ -467,7 +475,7 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericallyTypedSetOfIntegerBean() {
|
||||
public void testGenericallyTypedSetOfIntegerBean() throws Exception {
|
||||
GenericSetOfIntegerBean gb = new GenericSetOfIntegerBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("genericProperty", "10");
|
||||
@@ -478,23 +486,23 @@ class BeanWrapperGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSettingGenericPropertyWithReadOnlyInterface() {
|
||||
public void testSettingGenericPropertyWithReadOnlyInterface() {
|
||||
Bar bar = new Bar();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bar);
|
||||
bw.setPropertyValue("version", "10");
|
||||
assertThat(bar.getVersion()).isEqualTo(Double.valueOf(10.0));
|
||||
assertThat(bar.getVersion()).isEqualTo(new Double(10.0));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSettingLongPropertyWithGenericInterface() {
|
||||
public void testSettingLongPropertyWithGenericInterface() {
|
||||
Promotion bean = new Promotion();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.setPropertyValue("id", "10");
|
||||
assertThat(bean.getId()).isEqualTo(Long.valueOf(10));
|
||||
assertThat(bean.getId()).isEqualTo(new Long(10));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUntypedPropertyWithMapAtRuntime() {
|
||||
public void testUntypedPropertyWithMapAtRuntime() {
|
||||
class Holder<D> {
|
||||
private final D data;
|
||||
public Holder(D data) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -26,7 +26,6 @@ import org.springframework.beans.testfixture.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||
|
||||
/**
|
||||
* Specific {@link BeanWrapperImpl} tests.
|
||||
@@ -38,7 +37,7 @@ import static org.assertj.core.api.Assertions.assertThatNoException;
|
||||
* @author Chris Beams
|
||||
* @author Dave Syer
|
||||
*/
|
||||
class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
public class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
|
||||
@Override
|
||||
protected BeanWrapperImpl createAccessor(Object target) {
|
||||
@@ -47,7 +46,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
|
||||
|
||||
@Test
|
||||
void setterDoesNotCallGetter() {
|
||||
public void setterDoesNotCallGetter() {
|
||||
GetterBean target = new GetterBean();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
accessor.setPropertyValue("name", "tom");
|
||||
@@ -56,7 +55,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getterSilentlyFailWithOldValueExtraction() {
|
||||
public void getterSilentlyFailWithOldValueExtraction() {
|
||||
GetterBean target = new GetterBean();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
accessor.setExtractOldValueForEditor(true); // This will call the getter
|
||||
@@ -66,7 +65,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void aliasedSetterThroughDefaultMethod() {
|
||||
public void aliasedSetterThroughDefaultMethod() {
|
||||
GetterBean target = new GetterBean();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
accessor.setPropertyValue("aliasedName", "tom");
|
||||
@@ -75,7 +74,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
|
||||
public void setValidAndInvalidPropertyValuesShouldContainExceptionDetails() {
|
||||
TestBean target = new TestBean();
|
||||
String newName = "tony";
|
||||
String invalidTouchy = ".valid";
|
||||
@@ -92,12 +91,12 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
.getNewValue()).isEqualTo(invalidTouchy);
|
||||
});
|
||||
// Test validly set property matches
|
||||
assertThat(target.getName()).as("Valid set property must stick").isEqualTo(newName);
|
||||
assertThat(target.getAge()).as("Invalid set property must retain old value").isEqualTo(0);
|
||||
assertThat(target.getName().equals(newName)).as("Valid set property must stick").isTrue();
|
||||
assertThat(target.getAge() == 0).as("Invalid set property must retain old value").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void checkNotWritablePropertyHoldPossibleMatches() {
|
||||
public void checkNotWritablePropertyHoldPossibleMatches() {
|
||||
TestBean target = new TestBean();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
|
||||
@@ -106,15 +105,15 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test // Can't be shared; there is no such thing as a read-only field
|
||||
void setReadOnlyMapProperty() {
|
||||
public void setReadOnlyMapProperty() {
|
||||
TypedReadOnlyMap map = new TypedReadOnlyMap(Collections.singletonMap("key", new TestBean()));
|
||||
TypedReadOnlyMapClient target = new TypedReadOnlyMapClient();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
assertThatNoException().isThrownBy(() -> accessor.setPropertyValue("map", map));
|
||||
accessor.setPropertyValue("map", map);
|
||||
}
|
||||
|
||||
@Test
|
||||
void notWritablePropertyExceptionContainsAlternativeMatch() {
|
||||
public void notWritablePropertyExceptionContainsAlternativeMatch() {
|
||||
IntelliBean target = new IntelliBean();
|
||||
BeanWrapper bw = createAccessor(target);
|
||||
try {
|
||||
@@ -122,12 +121,12 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
catch (NotWritablePropertyException ex) {
|
||||
assertThat(ex.getPossibleMatches()).as("Possible matches not determined").isNotNull();
|
||||
assertThat(ex.getPossibleMatches()).as("Invalid amount of alternatives").hasSize(1);
|
||||
assertThat(ex.getPossibleMatches().length).as("Invalid amount of alternatives").isEqualTo(1);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void notWritablePropertyExceptionContainsAlternativeMatches() {
|
||||
public void notWritablePropertyExceptionContainsAlternativeMatches() {
|
||||
IntelliBean target = new IntelliBean();
|
||||
BeanWrapper bw = createAccessor(target);
|
||||
try {
|
||||
@@ -135,23 +134,23 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
catch (NotWritablePropertyException ex) {
|
||||
assertThat(ex.getPossibleMatches()).as("Possible matches not determined").isNotNull();
|
||||
assertThat(ex.getPossibleMatches()).as("Invalid amount of alternatives").hasSize(3);
|
||||
assertThat(ex.getPossibleMatches().length).as("Invalid amount of alternatives").isEqualTo(3);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@Test // Can't be shared: no type mismatch with a field
|
||||
void setPropertyTypeMismatch() {
|
||||
public void setPropertyTypeMismatch() {
|
||||
PropertyTypeMismatch target = new PropertyTypeMismatch();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
accessor.setPropertyValue("object", "a String");
|
||||
assertThat(target.value).isEqualTo("a String");
|
||||
assertThat(target.getObject()).isEqualTo(8);
|
||||
assertThat(target.getObject() == 8).isTrue();
|
||||
assertThat(accessor.getPropertyValue("object")).isEqualTo(8);
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyDescriptors() {
|
||||
public void propertyDescriptors() {
|
||||
TestBean target = new TestBean();
|
||||
target.setSpouse(new TestBean());
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
@@ -167,7 +166,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
void getPropertyWithOptional() {
|
||||
public void getPropertyWithOptional() {
|
||||
GetterWithOptional target = new GetterWithOptional();
|
||||
TestBean tb = new TestBean("x");
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
@@ -190,7 +189,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void getPropertyWithOptionalAndAutoGrow() {
|
||||
public void getPropertyWithOptionalAndAutoGrow() {
|
||||
GetterWithOptional target = new GetterWithOptional();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
accessor.setAutoGrowNestedPaths(true);
|
||||
@@ -202,7 +201,7 @@ class BeanWrapperTests extends AbstractPropertyAccessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void incompletelyQuotedKeyLeadsToPropertyException() {
|
||||
public void incompletelyQuotedKeyLeadsToPropertyException() {
|
||||
TestBean target = new TestBean();
|
||||
BeanWrapper accessor = createAccessor(target);
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* @author Chris Beams
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class DirectFieldAccessorTests extends AbstractPropertyAccessorTests {
|
||||
public class DirectFieldAccessorTests extends AbstractPropertyAccessorTests {
|
||||
|
||||
@Override
|
||||
protected DirectFieldAccessor createAccessor(Object target) {
|
||||
@@ -38,7 +38,7 @@ class DirectFieldAccessorTests extends AbstractPropertyAccessorTests {
|
||||
|
||||
|
||||
@Test
|
||||
void withShadowedField() {
|
||||
public void withShadowedField() {
|
||||
final StringBuilder sb = new StringBuilder();
|
||||
|
||||
TestBean target = new TestBean() {
|
||||
|
||||
+17
-17
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -182,9 +182,9 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -216,9 +216,9 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -249,9 +249,9 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
beanNames = lbf.getBeanNamesForAnnotation(SuppressWarnings.class);
|
||||
assertThat(beanNames).hasSize(0);
|
||||
assertThat(beanNames.length).isEqualTo(0);
|
||||
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -283,7 +283,7 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
assertThat(!DummyFactory.wasPrototypeCreated()).as("prototype not instantiated").isTrue();
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(1);
|
||||
assertThat(beanNames.length).isEqualTo(1);
|
||||
assertThat(beanNames[0]).isEqualTo("x1");
|
||||
assertThat(lbf.containsSingleton("x1")).isTrue();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -337,7 +337,7 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
TestBeanFactory.initialized = false;
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(1);
|
||||
assertThat(beanNames.length).isEqualTo(1);
|
||||
assertThat(beanNames[0]).isEqualTo("x1");
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -349,7 +349,7 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
|
||||
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
|
||||
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
|
||||
assertThat(lbf.getType("&x1")).isNull();
|
||||
assertThat(lbf.getType("&x1")).isEqualTo(null);
|
||||
assertThat(TestBeanFactory.initialized).isFalse();
|
||||
}
|
||||
|
||||
@@ -362,7 +362,7 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
TestBeanFactory.initialized = false;
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(1);
|
||||
assertThat(beanNames.length).isEqualTo(1);
|
||||
assertThat(beanNames[0]).isEqualTo("x1");
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -374,7 +374,7 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
|
||||
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
|
||||
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
|
||||
assertThat(lbf.getType("&x1")).isNull();
|
||||
assertThat(lbf.getType("&x1")).isEqualTo(null);
|
||||
assertThat(TestBeanFactory.initialized).isFalse();
|
||||
}
|
||||
|
||||
@@ -389,7 +389,7 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
TestBeanFactory.initialized = false;
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(1);
|
||||
assertThat(beanNames.length).isEqualTo(1);
|
||||
assertThat(beanNames[0]).isEqualTo("x1");
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -401,7 +401,7 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(lbf.isTypeMatch("x1", TestBean.class)).isTrue();
|
||||
assertThat(lbf.isTypeMatch("&x1", TestBean.class)).isFalse();
|
||||
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
|
||||
assertThat(lbf.getType("&x1")).isNull();
|
||||
assertThat(lbf.getType("&x1")).isEqualTo(null);
|
||||
assertThat(TestBeanFactory.initialized).isFalse();
|
||||
}
|
||||
|
||||
@@ -417,7 +417,7 @@ class DefaultListableBeanFactoryTests {
|
||||
|
||||
TestBeanFactory.initialized = false;
|
||||
String[] beanNames = lbf.getBeanNamesForType(TestBean.class, true, false);
|
||||
assertThat(beanNames).hasSize(1);
|
||||
assertThat(beanNames.length).isEqualTo(1);
|
||||
assertThat(beanNames[0]).isEqualTo("x1");
|
||||
assertThat(lbf.containsSingleton("x1")).isFalse();
|
||||
assertThat(lbf.containsBean("x1")).isTrue();
|
||||
@@ -450,7 +450,7 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(lbf.isTypeMatch("x2", Object.class)).isTrue();
|
||||
assertThat(lbf.isTypeMatch("&x2", Object.class)).isFalse();
|
||||
assertThat(lbf.getType("x2")).isEqualTo(TestBean.class);
|
||||
assertThat(lbf.getType("&x2")).isNull();
|
||||
assertThat(lbf.getType("&x2")).isEqualTo(null);
|
||||
assertThat(lbf.getAliases("x1").length).isEqualTo(1);
|
||||
assertThat(lbf.getAliases("x1")[0]).isEqualTo("x2");
|
||||
assertThat(lbf.getAliases("&x1").length).isEqualTo(1);
|
||||
@@ -3030,7 +3030,7 @@ class DefaultListableBeanFactoryTests {
|
||||
public Object convertIfNecessary(Object value, @Nullable Class requiredType) {
|
||||
if (value instanceof String && Float.class.isAssignableFrom(requiredType)) {
|
||||
try {
|
||||
return this.numberFormat.parse((String) value).floatValue();
|
||||
return new Float(this.numberFormat.parse((String) value).floatValue());
|
||||
}
|
||||
catch (ParseException ex) {
|
||||
throw new TypeMismatchException(value, requiredType, ex);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -31,7 +31,6 @@ import static org.springframework.beans.factory.support.BeanDefinitionBuilder.ro
|
||||
* invoking a factory method is not instructive to the user and rather misleading.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class Spr5475Tests {
|
||||
|
||||
@@ -41,8 +40,7 @@ public class Spr5475Tests {
|
||||
rootBeanDefinition(Foo.class)
|
||||
.setFactoryMethod("noArgFactory")
|
||||
.addConstructorArgValue("bogusArg").getBeanDefinition(),
|
||||
"Error creating bean with name 'foo': No matching factory method found on class " +
|
||||
"[org.springframework.beans.factory.Spr5475Tests$Foo]: factory method 'noArgFactory(String)'. " +
|
||||
"Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(String)'. " +
|
||||
"Check that a method with the specified name and arguments exists and that it is static.");
|
||||
}
|
||||
|
||||
@@ -53,8 +51,7 @@ public class Spr5475Tests {
|
||||
.setFactoryMethod("noArgFactory")
|
||||
.addConstructorArgValue("bogusArg1")
|
||||
.addConstructorArgValue("bogusArg2".getBytes()).getBeanDefinition(),
|
||||
"Error creating bean with name 'foo': No matching factory method found on class " +
|
||||
"[org.springframework.beans.factory.Spr5475Tests$Foo]: factory method 'noArgFactory(String,byte[])'. " +
|
||||
"Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(String,byte[])'. " +
|
||||
"Check that a method with the specified name and arguments exists and that it is static.");
|
||||
}
|
||||
|
||||
@@ -68,8 +65,7 @@ public class Spr5475Tests {
|
||||
def.setConstructorArgumentValues(cav);
|
||||
|
||||
assertExceptionMessageForMisconfiguredFactoryMethod(def,
|
||||
"Error creating bean with name 'foo': No matching factory method found on class " +
|
||||
"[org.springframework.beans.factory.Spr5475Tests$Foo]: factory method 'noArgFactory(CharSequence,byte[])'. " +
|
||||
"Error creating bean with name 'foo': No matching factory method found: factory method 'noArgFactory(CharSequence,byte[])'. " +
|
||||
"Check that a method with the specified name and arguments exists and that it is static.");
|
||||
}
|
||||
|
||||
|
||||
+5
-82
@@ -17,25 +17,22 @@
|
||||
package org.springframework.beans.factory.support;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.function.Function;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.core.ResolvableType;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
*/
|
||||
class BeanDefinitionBuilderTests {
|
||||
public class BeanDefinitionBuilderTests {
|
||||
|
||||
@Test
|
||||
void builderWithBeanClassWithSimpleProperty() {
|
||||
public void beanClassWithSimpleProperty() {
|
||||
String[] dependsOn = new String[] { "A", "B", "C" };
|
||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class);
|
||||
bdb.setScope(BeanDefinition.SCOPE_PROTOTYPE);
|
||||
@@ -52,7 +49,7 @@ class BeanDefinitionBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithBeanClassAndFactoryMethod() {
|
||||
public void beanClassWithFactoryMethod() {
|
||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class, "create");
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||
assertThat(rbd.hasBeanClass()).isTrue();
|
||||
@@ -61,7 +58,7 @@ class BeanDefinitionBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithBeanClassName() {
|
||||
public void beanClassName() {
|
||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName());
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||
assertThat(rbd.hasBeanClass()).isFalse();
|
||||
@@ -69,7 +66,7 @@ class BeanDefinitionBuilderTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithBeanClassNameAndFactoryMethod() {
|
||||
public void beanClassNameWithFactoryMethod() {
|
||||
BeanDefinitionBuilder bdb = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class.getName(), "create");
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) bdb.getBeanDefinition();
|
||||
assertThat(rbd.hasBeanClass()).isFalse();
|
||||
@@ -77,78 +74,4 @@ class BeanDefinitionBuilderTests {
|
||||
assertThat(rbd.getFactoryMethodName()).isEqualTo("create");
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithResolvableTypeAndInstanceSupplier() {
|
||||
ResolvableType type = ResolvableType.forClassWithGenerics(Function.class, Integer.class, String.class);
|
||||
Function<Integer, String> function = i -> "value " + i;
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) BeanDefinitionBuilder
|
||||
.rootBeanDefinition(type, () -> function).getBeanDefinition();
|
||||
assertThat(rbd.getResolvableType()).isEqualTo(type);
|
||||
assertThat(rbd.getInstanceSupplier()).isNotNull();
|
||||
assertThat(rbd.getInstanceSupplier().get()).isInstanceOf(Function.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithBeanClassAndInstanceSupplier() {
|
||||
RootBeanDefinition rbd = (RootBeanDefinition) BeanDefinitionBuilder
|
||||
.rootBeanDefinition(String.class, () -> "test").getBeanDefinition();
|
||||
assertThat(rbd.getResolvableType().resolve()).isEqualTo(String.class);
|
||||
assertThat(rbd.getInstanceSupplier()).isNotNull();
|
||||
assertThat(rbd.getInstanceSupplier().get()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithAutowireMode() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE).getBeanDefinition().getAutowireMode())
|
||||
.isEqualTo(RootBeanDefinition.AUTOWIRE_BY_TYPE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithDependencyCheck() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.setDependencyCheck(RootBeanDefinition.DEPENDENCY_CHECK_ALL)
|
||||
.getBeanDefinition().getDependencyCheck())
|
||||
.isEqualTo(RootBeanDefinition.DEPENDENCY_CHECK_ALL);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithDependsOn() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class).addDependsOn("test")
|
||||
.addDependsOn("test2").getBeanDefinition().getDependsOn())
|
||||
.containsExactly("test", "test2");
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithPrimary() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.setPrimary(true).getBeanDefinition().isPrimary()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithRole() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.setRole(BeanDefinition.ROLE_INFRASTRUCTURE).getBeanDefinition().getRole())
|
||||
.isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithSynthetic() {
|
||||
assertThat(BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.setSynthetic(true).getBeanDefinition().isSynthetic()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void builderWithCustomizers() {
|
||||
BeanDefinition beanDefinition = BeanDefinitionBuilder.rootBeanDefinition(TestBean.class)
|
||||
.applyCustomizers(builder -> {
|
||||
builder.setFactoryMethodName("create");
|
||||
builder.setRole(BeanDefinition.ROLE_SUPPORT);
|
||||
})
|
||||
.applyCustomizers(builder -> builder.setRole(BeanDefinition.ROLE_INFRASTRUCTURE))
|
||||
.getBeanDefinition();
|
||||
assertThat(beanDefinition.getFactoryMethodName()).isEqualTo("create");
|
||||
assertThat(beanDefinition.getRole()).isEqualTo(BeanDefinition.ROLE_INFRASTRUCTURE);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+85
-85
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -64,10 +64,10 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||
* @author Sam Brannen
|
||||
* @since 20.01.2006
|
||||
*/
|
||||
class BeanFactoryGenericsTests {
|
||||
public class BeanFactoryGenericsTests {
|
||||
|
||||
@Test
|
||||
void testGenericSetProperty() {
|
||||
public void testGenericSetProperty() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -84,7 +84,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListProperty() throws Exception {
|
||||
public void testGenericListProperty() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -101,7 +101,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListPropertyWithAutowiring() throws Exception {
|
||||
public void testGenericListPropertyWithAutowiring() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
|
||||
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
|
||||
@@ -116,7 +116,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListPropertyWithInvalidElementType() {
|
||||
public void testGenericListPropertyWithInvalidElementType() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericIntegerBean.class);
|
||||
|
||||
@@ -134,7 +134,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListPropertyWithOptionalAutowiring() {
|
||||
public void testGenericListPropertyWithOptionalAutowiring() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
@@ -146,7 +146,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapProperty() {
|
||||
public void testGenericMapProperty() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -158,12 +158,12 @@ class BeanFactoryGenericsTests {
|
||||
bf.registerBeanDefinition("genericBean", rbd);
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListOfArraysProperty() {
|
||||
public void testGenericListOfArraysProperty() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -171,14 +171,14 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
assertThat(gb.getListOfArrays().size()).isEqualTo(1);
|
||||
String[] array = gb.getListOfArrays().get(0);
|
||||
assertThat(array).hasSize(2);
|
||||
assertThat(array.length).isEqualTo(2);
|
||||
assertThat(array[0]).isEqualTo("value1");
|
||||
assertThat(array[1]).isEqualTo("value2");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void testGenericSetConstructor() {
|
||||
public void testGenericSetConstructor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -195,7 +195,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetConstructorWithAutowiring() {
|
||||
public void testGenericSetConstructorWithAutowiring() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("integer1", 4);
|
||||
bf.registerSingleton("integer2", 5);
|
||||
@@ -210,7 +210,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetConstructorWithOptionalAutowiring() {
|
||||
public void testGenericSetConstructorWithOptionalAutowiring() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
@@ -222,7 +222,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetListConstructor() throws Exception {
|
||||
public void testGenericSetListConstructor() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -245,7 +245,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetListConstructorWithAutowiring() throws Exception {
|
||||
public void testGenericSetListConstructorWithAutowiring() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("integer1", 4);
|
||||
bf.registerSingleton("integer2", 5);
|
||||
@@ -264,7 +264,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetListConstructorWithOptionalAutowiring() throws Exception {
|
||||
public void testGenericSetListConstructorWithOptionalAutowiring() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("resource1", new UrlResource("http://localhost:8080"));
|
||||
bf.registerSingleton("resource2", new UrlResource("http://localhost:9090"));
|
||||
@@ -279,7 +279,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetMapConstructor() {
|
||||
public void testGenericSetMapConstructor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -297,12 +297,12 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
assertThat(gb.getIntegerSet().contains(4)).isTrue();
|
||||
assertThat(gb.getIntegerSet().contains(5)).isTrue();
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapResourceConstructor() throws Exception {
|
||||
public void testGenericMapResourceConstructor() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -315,13 +315,13 @@ class BeanFactoryGenericsTests {
|
||||
bf.registerBeanDefinition("genericBean", rbd);
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapMapConstructor() {
|
||||
public void testGenericMapMapConstructor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -338,16 +338,16 @@ class BeanFactoryGenericsTests {
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap()).isNotSameAs(gb.getPlainMap());
|
||||
assertThat(gb.getPlainMap()).hasSize(2);
|
||||
assertThat(gb.getPlainMap().size()).isEqualTo(2);
|
||||
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
|
||||
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
|
||||
assertThat(gb.getShortMap().size()).isEqualTo(2);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapMapConstructorWithSameRefAndConversion() {
|
||||
public void testGenericMapMapConstructorWithSameRefAndConversion() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -361,22 +361,22 @@ class BeanFactoryGenericsTests {
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap()).isNotSameAs(gb.getPlainMap());
|
||||
assertThat(gb.getPlainMap()).hasSize(2);
|
||||
assertThat(gb.getPlainMap().size()).isEqualTo(2);
|
||||
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
|
||||
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
|
||||
assertThat(gb.getShortMap().size()).isEqualTo(2);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("1"))).isEqualTo(0);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("2"))).isEqualTo(3);
|
||||
assertThat(gb.getShortMap().get(new Short("1"))).isEqualTo(0);
|
||||
assertThat(gb.getShortMap().get(new Short("2"))).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapMapConstructorWithSameRefAndNoConversion() {
|
||||
public void testGenericMapMapConstructorWithSameRefAndNoConversion() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
Map<Short, Integer> input = new HashMap<>();
|
||||
input.put((short) 1, 0);
|
||||
input.put((short) 2, 3);
|
||||
input.put(new Short((short) 1), 0);
|
||||
input.put(new Short((short) 2), 3);
|
||||
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
|
||||
rbd.getConstructorArgumentValues().addGenericArgumentValue(input);
|
||||
|
||||
@@ -384,13 +384,13 @@ class BeanFactoryGenericsTests {
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap()).isSameAs(gb.getPlainMap());
|
||||
assertThat(gb.getShortMap()).hasSize(2);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("1"))).isEqualTo(0);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("2"))).isEqualTo(3);
|
||||
assertThat(gb.getShortMap().size()).isEqualTo(2);
|
||||
assertThat(gb.getShortMap().get(new Short("1"))).isEqualTo(0);
|
||||
assertThat(gb.getShortMap().get(new Short("2"))).isEqualTo(3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithKeyTypeConstructor() {
|
||||
public void testGenericMapWithKeyTypeConstructor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
|
||||
@@ -407,7 +407,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithCollectionValueConstructor() {
|
||||
public void testGenericMapWithCollectionValueConstructor() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
@Override
|
||||
@@ -438,7 +438,7 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testGenericSetFactoryMethod() {
|
||||
public void testGenericSetFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -456,7 +456,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetListFactoryMethod() throws Exception {
|
||||
public void testGenericSetListFactoryMethod() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -480,7 +480,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetMapFactoryMethod() {
|
||||
public void testGenericSetMapFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -499,12 +499,12 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
assertThat(gb.getIntegerSet().contains(4)).isTrue();
|
||||
assertThat(gb.getIntegerSet().contains(5)).isTrue();
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapResourceFactoryMethod() throws Exception {
|
||||
public void testGenericMapResourceFactoryMethod() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -518,13 +518,13 @@ class BeanFactoryGenericsTests {
|
||||
bf.registerBeanDefinition("genericBean", rbd);
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
assertThat(gb.getResourceList().get(0)).isEqualTo(new UrlResource("http://localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapMapFactoryMethod() {
|
||||
public void testGenericMapMapFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -543,12 +543,12 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
assertThat(gb.getPlainMap().get("1")).isEqualTo("0");
|
||||
assertThat(gb.getPlainMap().get("2")).isEqualTo("3");
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(Short.valueOf("6"))).isEqualTo(7);
|
||||
assertThat(gb.getShortMap().get(new Short("4"))).isEqualTo(5);
|
||||
assertThat(gb.getShortMap().get(new Short("6"))).isEqualTo(7);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithKeyTypeFactoryMethod() {
|
||||
public void testGenericMapWithKeyTypeFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(GenericBean.class);
|
||||
rbd.setFactoryMethodName("createInstance");
|
||||
@@ -561,12 +561,12 @@ class BeanFactoryGenericsTests {
|
||||
bf.registerBeanDefinition("genericBean", rbd);
|
||||
GenericBean<?> gb = (GenericBean<?>) bf.getBean("genericBean");
|
||||
|
||||
assertThat(gb.getLongMap().get(Long.valueOf("4"))).isEqualTo("5");
|
||||
assertThat(gb.getLongMap().get(Long.valueOf("6"))).isEqualTo("7");
|
||||
assertThat(gb.getLongMap().get(new Long("4"))).isEqualTo("5");
|
||||
assertThat(gb.getLongMap().get(new Long("6"))).isEqualTo("7");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapWithCollectionValueFactoryMethod() {
|
||||
public void testGenericMapWithCollectionValueFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.addPropertyEditorRegistrar(new PropertyEditorRegistrar() {
|
||||
@Override
|
||||
@@ -597,7 +597,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericListBean() throws Exception {
|
||||
public void testGenericListBean() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -607,7 +607,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericSetBean() throws Exception {
|
||||
public void testGenericSetBean() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -617,18 +617,18 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMapBean() throws Exception {
|
||||
public void testGenericMapBean() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
Map<?, ?> map = (Map<?, ?>) bf.getBean("map");
|
||||
assertThat(map).hasSize(1);
|
||||
assertThat(map.size()).isEqualTo(1);
|
||||
assertThat(map.keySet().iterator().next()).isEqualTo(10);
|
||||
assertThat(map.values().iterator().next()).isEqualTo(new URL("http://localhost:8080"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericallyTypedIntegerBean() {
|
||||
public void testGenericallyTypedIntegerBean() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -639,7 +639,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericallyTypedSetOfIntegerBean() {
|
||||
public void testGenericallyTypedSetOfIntegerBean() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -651,7 +651,7 @@ class BeanFactoryGenericsTests {
|
||||
|
||||
@Test
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
void testSetBean() throws Exception {
|
||||
public void testSetBean() throws Exception {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
new ClassPathResource("genericBeanTests.xml", getClass()));
|
||||
@@ -671,7 +671,7 @@ class BeanFactoryGenericsTests {
|
||||
* <p>See SPR-9493
|
||||
*/
|
||||
@Test
|
||||
void parameterizedStaticFactoryMethod() {
|
||||
public void parameterizedStaticFactoryMethod() {
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(Mockito.class);
|
||||
rbd.setFactoryMethodName("mock");
|
||||
rbd.getConstructorArgumentValues().addGenericArgumentValue(Runnable.class);
|
||||
@@ -682,7 +682,7 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -697,7 +697,7 @@ class BeanFactoryGenericsTests {
|
||||
* <p>See SPR-10411
|
||||
*/
|
||||
@Test
|
||||
void parameterizedInstanceFactoryMethod() {
|
||||
public void parameterizedInstanceFactoryMethod() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
|
||||
@@ -714,11 +714,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void parameterizedInstanceFactoryMethodWithNonResolvedClassName() {
|
||||
public void parameterizedInstanceFactoryMethodWithNonResolvedClassName() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
|
||||
@@ -735,11 +735,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void parameterizedInstanceFactoryMethodWithWrappedClassName() {
|
||||
public void parameterizedInstanceFactoryMethodWithWrappedClassName() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition();
|
||||
@@ -754,11 +754,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void parameterizedInstanceFactoryMethodWithInvalidClassName() {
|
||||
public void parameterizedInstanceFactoryMethodWithInvalidClassName() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
|
||||
@@ -775,11 +775,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isNull();
|
||||
assertThat(bf.getType("mock")).isNull();
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(0);
|
||||
assertThat(beans.size()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void parameterizedInstanceFactoryMethodWithIndexedArgument() {
|
||||
public void parameterizedInstanceFactoryMethodWithIndexedArgument() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
|
||||
RootBeanDefinition rbd = new RootBeanDefinition(MocksControl.class);
|
||||
@@ -796,11 +796,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test // SPR-16720
|
||||
void parameterizedInstanceFactoryMethodWithTempClassLoader() {
|
||||
public void parameterizedInstanceFactoryMethodWithTempClassLoader() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setTempClassLoader(new OverridingClassLoader(getClass().getClassLoader()));
|
||||
|
||||
@@ -818,11 +818,11 @@ class BeanFactoryGenericsTests {
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
assertThat(bf.getType("mock")).isEqualTo(Runnable.class);
|
||||
Map<String, Runnable> beans = bf.getBeansOfType(Runnable.class);
|
||||
assertThat(beans).hasSize(1);
|
||||
assertThat(beans.size()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMatchingWithBeanNameDifferentiation() {
|
||||
public void testGenericMatchingWithBeanNameDifferentiation() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());
|
||||
|
||||
@@ -838,15 +838,15 @@ class BeanFactoryGenericsTests {
|
||||
String[] numberStoreNames = bf.getBeanNamesForType(ResolvableType.forClass(NumberStore.class));
|
||||
String[] doubleStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Double.class));
|
||||
String[] floatStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Float.class));
|
||||
assertThat(numberStoreNames).hasSize(2);
|
||||
assertThat(numberStoreNames.length).isEqualTo(2);
|
||||
assertThat(numberStoreNames[0]).isEqualTo("doubleStore");
|
||||
assertThat(numberStoreNames[1]).isEqualTo("floatStore");
|
||||
assertThat(doubleStoreNames).hasSize(0);
|
||||
assertThat(floatStoreNames).hasSize(0);
|
||||
assertThat(doubleStoreNames.length).isEqualTo(0);
|
||||
assertThat(floatStoreNames.length).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMatchingWithFullTypeDifferentiation() {
|
||||
public void testGenericMatchingWithFullTypeDifferentiation() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
|
||||
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());
|
||||
@@ -867,12 +867,12 @@ class BeanFactoryGenericsTests {
|
||||
String[] numberStoreNames = bf.getBeanNamesForType(ResolvableType.forClass(NumberStore.class));
|
||||
String[] doubleStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Double.class));
|
||||
String[] floatStoreNames = bf.getBeanNamesForType(ResolvableType.forClassWithGenerics(NumberStore.class, Float.class));
|
||||
assertThat(numberStoreNames).hasSize(2);
|
||||
assertThat(numberStoreNames.length).isEqualTo(2);
|
||||
assertThat(numberStoreNames[0]).isEqualTo("store1");
|
||||
assertThat(numberStoreNames[1]).isEqualTo("store2");
|
||||
assertThat(doubleStoreNames).hasSize(1);
|
||||
assertThat(doubleStoreNames.length).isEqualTo(1);
|
||||
assertThat(doubleStoreNames[0]).isEqualTo("store1");
|
||||
assertThat(floatStoreNames).hasSize(1);
|
||||
assertThat(floatStoreNames.length).isEqualTo(1);
|
||||
assertThat(floatStoreNames[0]).isEqualTo("store2");
|
||||
|
||||
ObjectProvider<NumberStore<?>> numberStoreProvider = bf.getBeanProvider(ResolvableType.forClass(NumberStore.class));
|
||||
@@ -938,7 +938,7 @@ class BeanFactoryGenericsTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testGenericMatchingWithUnresolvedOrderedStream() {
|
||||
public void testGenericMatchingWithUnresolvedOrderedStream() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.setDependencyComparator(AnnotationAwareOrderComparator.INSTANCE);
|
||||
bf.setAutowireCandidateResolver(new GenericTypeAwareAutowireCandidateResolver());
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -244,7 +244,7 @@ public class QualifierAnnotationAutowireBeanFactoryTests {
|
||||
@Target({ElementType.FIELD, ElementType.PARAMETER})
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Qualifier
|
||||
private @interface TestQualifier {
|
||||
private static @interface TestQualifier {
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -26,18 +26,18 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*
|
||||
* @author Rick Evans
|
||||
*/
|
||||
class ClassNameBeanWiringInfoResolverTests {
|
||||
public class ClassNameBeanWiringInfoResolverTests {
|
||||
|
||||
@Test
|
||||
void resolveWiringInfoWithNullBeanInstance() throws Exception {
|
||||
public void resolveWiringInfoWithNullBeanInstance() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new ClassNameBeanWiringInfoResolver().resolveWiringInfo(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void resolveWiringInfo() {
|
||||
public void resolveWiringInfo() {
|
||||
ClassNameBeanWiringInfoResolver resolver = new ClassNameBeanWiringInfoResolver();
|
||||
Long beanInstance = 1L;
|
||||
Long beanInstance = new Long(1);
|
||||
BeanWiringInfo info = resolver.resolveWiringInfo(beanInstance);
|
||||
assertThat(info).isNotNull();
|
||||
assertThat(info.getBeanName()).as("Not resolving bean name to the class name of the supplied bean instance as per class contract.").isEqualTo(beanInstance.getClass().getName());
|
||||
|
||||
+158
-158
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -64,10 +64,10 @@ import static org.assertj.core.api.Assertions.within;
|
||||
* @author Chris Beams
|
||||
* @since 10.06.2003
|
||||
*/
|
||||
class CustomEditorTests {
|
||||
public class CustomEditorTests {
|
||||
|
||||
@Test
|
||||
void testComplexObject() {
|
||||
public void testComplexObject() {
|
||||
TestBean tb = new TestBean();
|
||||
String newName = "Rod";
|
||||
String tbString = "Kerry_34";
|
||||
@@ -80,12 +80,12 @@ class CustomEditorTests {
|
||||
pvs.addPropertyValue(new PropertyValue("touchy", "valid"));
|
||||
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
|
||||
bw.setPropertyValues(pvs);
|
||||
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
|
||||
assertThat(tb.getSpouse() != null).as("spouse is non-null").isTrue();
|
||||
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testComplexObjectWithOldValueAccess() {
|
||||
public void testComplexObjectWithOldValueAccess() {
|
||||
TestBean tb = new TestBean();
|
||||
String newName = "Rod";
|
||||
String tbString = "Kerry_34";
|
||||
@@ -100,7 +100,7 @@ class CustomEditorTests {
|
||||
pvs.addPropertyValue(new PropertyValue("spouse", tbString));
|
||||
|
||||
bw.setPropertyValues(pvs);
|
||||
assertThat(tb.getSpouse()).as("spouse is non-null").isNotNull();
|
||||
assertThat(tb.getSpouse() != null).as("spouse is non-null").isTrue();
|
||||
assertThat(tb.getSpouse().getName().equals("Kerry") && tb.getSpouse().getAge() == 34).as("spouse name is Kerry and age is 34").isTrue();
|
||||
ITestBean spouse = tb.getSpouse();
|
||||
|
||||
@@ -109,7 +109,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomEditorForSingleProperty() {
|
||||
public void testCustomEditorForSingleProperty() {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(String.class, "name", new PropertyEditorSupport() {
|
||||
@@ -127,7 +127,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomEditorForAllStringProperties() {
|
||||
public void testCustomEditorForAllStringProperties() {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
||||
@@ -145,7 +145,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomEditorForSingleNestedProperty() {
|
||||
public void testCustomEditorForSingleNestedProperty() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setSpouse(new TestBean());
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
@@ -164,7 +164,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomEditorForAllNestedStringProperties() {
|
||||
public void testCustomEditorForAllNestedStringProperties() {
|
||||
TestBean tb = new TestBean();
|
||||
tb.setSpouse(new TestBean());
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
@@ -183,7 +183,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultBooleanEditorForPrimitiveType() {
|
||||
public void testDefaultBooleanEditorForPrimitiveType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -229,7 +229,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultBooleanEditorForWrapperType() {
|
||||
public void testDefaultBooleanEditorForWrapperType() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -239,28 +239,28 @@ class CustomEditorTests {
|
||||
|
||||
bw.setPropertyValue("bool2", "false");
|
||||
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
|
||||
boolean condition3 = !tb.getBool2();
|
||||
boolean condition3 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition3).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "on");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "off");
|
||||
boolean condition2 = !tb.getBool2();
|
||||
boolean condition2 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition2).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "yes");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "no");
|
||||
boolean condition1 = !tb.getBool2();
|
||||
boolean condition1 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition1).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "1");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "0");
|
||||
boolean condition = !tb.getBool2();
|
||||
boolean condition = !tb.getBool2().booleanValue();
|
||||
assertThat(condition).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "");
|
||||
@@ -268,7 +268,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomBooleanEditorWithAllowEmpty() {
|
||||
public void testCustomBooleanEditorWithAllowEmpty() {
|
||||
BooleanTestBean tb = new BooleanTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(Boolean.class, new CustomBooleanEditor(true));
|
||||
@@ -279,37 +279,37 @@ class CustomEditorTests {
|
||||
|
||||
bw.setPropertyValue("bool2", "false");
|
||||
assertThat(Boolean.FALSE.equals(bw.getPropertyValue("bool2"))).as("Correct bool2 value").isTrue();
|
||||
boolean condition3 = !tb.getBool2();
|
||||
boolean condition3 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition3).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "on");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "off");
|
||||
boolean condition2 = !tb.getBool2();
|
||||
boolean condition2 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition2).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "yes");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "no");
|
||||
boolean condition1 = !tb.getBool2();
|
||||
boolean condition1 = !tb.getBool2().booleanValue();
|
||||
assertThat(condition1).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "1");
|
||||
assertThat(tb.getBool2().booleanValue()).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "0");
|
||||
boolean condition = !tb.getBool2();
|
||||
boolean condition = !tb.getBool2().booleanValue();
|
||||
assertThat(condition).as("Correct bool2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("bool2", "");
|
||||
assertThat(bw.getPropertyValue("bool2")).as("Correct bool2 value").isNull();
|
||||
assertThat(tb.getBool2()).as("Correct bool2 value").isNull();
|
||||
assertThat(bw.getPropertyValue("bool2") == null).as("Correct bool2 value").isTrue();
|
||||
assertThat(tb.getBool2() == null).as("Correct bool2 value").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception {
|
||||
public void testCustomBooleanEditorWithSpecialTrueAndFalseStrings() throws Exception {
|
||||
String trueString = "pechorin";
|
||||
String falseString = "nash";
|
||||
|
||||
@@ -333,7 +333,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testDefaultNumberEditor() {
|
||||
public void testDefaultNumberEditor() {
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
|
||||
@@ -350,34 +350,34 @@ class CustomEditorTests {
|
||||
bw.setPropertyValue("double2", "6.1");
|
||||
bw.setPropertyValue("bigDecimal", "4.5");
|
||||
|
||||
assertThat(Short.valueOf("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
|
||||
assertThat(new Short("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
|
||||
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
|
||||
assertThat(Short.valueOf("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
|
||||
assertThat(Short.valueOf("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
|
||||
assertThat(Integer.valueOf("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
|
||||
assertThat(new Short("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
|
||||
assertThat(new Short("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
|
||||
assertThat(new Integer("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
|
||||
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
|
||||
assertThat(Integer.valueOf("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
|
||||
assertThat(Integer.valueOf("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
|
||||
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
|
||||
assertThat(new Integer("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
|
||||
assertThat(new Integer("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
|
||||
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
|
||||
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
|
||||
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
|
||||
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
|
||||
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
|
||||
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
|
||||
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
|
||||
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
|
||||
assertThat(Float.valueOf("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
|
||||
assertThat(Float.valueOf("7.1").equals(tb.getFloat1())).as("Correct float1 value").isTrue();
|
||||
assertThat(Float.valueOf("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
|
||||
assertThat(Float.valueOf("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
|
||||
assertThat(Double.valueOf("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
|
||||
assertThat(new Float("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
|
||||
assertThat(new Float("7.1").equals(new Float(tb.getFloat1()))).as("Correct float1 value").isTrue();
|
||||
assertThat(new Float("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
|
||||
assertThat(new Float("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
|
||||
assertThat(new Double("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
|
||||
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
|
||||
assertThat(Double.valueOf("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
|
||||
assertThat(Double.valueOf("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
|
||||
assertThat(new Double("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
|
||||
assertThat(new Double("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
|
||||
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
|
||||
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditorWithoutAllowEmpty() {
|
||||
public void testCustomNumberEditorWithoutAllowEmpty() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
@@ -407,34 +407,34 @@ class CustomEditorTests {
|
||||
bw.setPropertyValue("double2", "6,1");
|
||||
bw.setPropertyValue("bigDecimal", "4,5");
|
||||
|
||||
assertThat(bw.getPropertyValue("short1")).as("Correct short1 value").isEqualTo(Short.valueOf("1"));
|
||||
assertThat(new Short("1").equals(bw.getPropertyValue("short1"))).as("Correct short1 value").isTrue();
|
||||
assertThat(tb.getShort1() == 1).as("Correct short1 value").isTrue();
|
||||
assertThat(bw.getPropertyValue("short2")).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
|
||||
assertThat(tb.getShort2()).as("Correct short2 value").isEqualTo(Short.valueOf("2"));
|
||||
assertThat(bw.getPropertyValue("int1")).as("Correct int1 value").isEqualTo(Integer.valueOf("7"));
|
||||
assertThat(new Short("2").equals(bw.getPropertyValue("short2"))).as("Correct short2 value").isTrue();
|
||||
assertThat(new Short("2").equals(tb.getShort2())).as("Correct short2 value").isTrue();
|
||||
assertThat(new Integer("7").equals(bw.getPropertyValue("int1"))).as("Correct int1 value").isTrue();
|
||||
assertThat(tb.getInt1() == 7).as("Correct int1 value").isTrue();
|
||||
assertThat(bw.getPropertyValue("int2")).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
|
||||
assertThat(tb.getInt2()).as("Correct int2 value").isEqualTo(Integer.valueOf("8"));
|
||||
assertThat(bw.getPropertyValue("long1")).as("Correct long1 value").isEqualTo(Long.valueOf("5"));
|
||||
assertThat(new Integer("8").equals(bw.getPropertyValue("int2"))).as("Correct int2 value").isTrue();
|
||||
assertThat(new Integer("8").equals(tb.getInt2())).as("Correct int2 value").isTrue();
|
||||
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
|
||||
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
|
||||
assertThat(bw.getPropertyValue("long2")).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
|
||||
assertThat(tb.getLong2()).as("Correct long2 value").isEqualTo(Long.valueOf("6"));
|
||||
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
|
||||
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
|
||||
assertThat(new BigInteger("3").equals(bw.getPropertyValue("bigInteger"))).as("Correct bigInteger value").isTrue();
|
||||
assertThat(new BigInteger("3").equals(tb.getBigInteger())).as("Correct bigInteger value").isTrue();
|
||||
assertThat(bw.getPropertyValue("float1")).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
|
||||
assertThat(Float.valueOf(tb.getFloat1())).as("Correct float1 value").isEqualTo(Float.valueOf("7.1"));
|
||||
assertThat(bw.getPropertyValue("float2")).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
|
||||
assertThat(tb.getFloat2()).as("Correct float2 value").isEqualTo(Float.valueOf("8.1"));
|
||||
assertThat(bw.getPropertyValue("double1")).as("Correct double1 value").isEqualTo(Double.valueOf("5.1"));
|
||||
assertThat(new Float("7.1").equals(bw.getPropertyValue("float1"))).as("Correct float1 value").isTrue();
|
||||
assertThat(new Float("7.1").equals(new Float(tb.getFloat1()))).as("Correct float1 value").isTrue();
|
||||
assertThat(new Float("8.1").equals(bw.getPropertyValue("float2"))).as("Correct float2 value").isTrue();
|
||||
assertThat(new Float("8.1").equals(tb.getFloat2())).as("Correct float2 value").isTrue();
|
||||
assertThat(new Double("5.1").equals(bw.getPropertyValue("double1"))).as("Correct double1 value").isTrue();
|
||||
assertThat(tb.getDouble1() == 5.1).as("Correct double1 value").isTrue();
|
||||
assertThat(bw.getPropertyValue("double2")).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
|
||||
assertThat(tb.getDouble2()).as("Correct double2 value").isEqualTo(Double.valueOf("6.1"));
|
||||
assertThat(new Double("6.1").equals(bw.getPropertyValue("double2"))).as("Correct double2 value").isTrue();
|
||||
assertThat(new Double("6.1").equals(tb.getDouble2())).as("Correct double2 value").isTrue();
|
||||
assertThat(new BigDecimal("4.5").equals(bw.getPropertyValue("bigDecimal"))).as("Correct bigDecimal value").isTrue();
|
||||
assertThat(new BigDecimal("4.5").equals(tb.getBigDecimal())).as("Correct bigDecimal value").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditorWithAllowEmpty() {
|
||||
public void testCustomNumberEditorWithAllowEmpty() {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.GERMAN);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
@@ -443,10 +443,10 @@ class CustomEditorTests {
|
||||
|
||||
bw.setPropertyValue("long1", "5");
|
||||
bw.setPropertyValue("long2", "6");
|
||||
assertThat(Long.valueOf("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
|
||||
assertThat(new Long("5").equals(bw.getPropertyValue("long1"))).as("Correct long1 value").isTrue();
|
||||
assertThat(tb.getLong1() == 5).as("Correct long1 value").isTrue();
|
||||
assertThat(Long.valueOf("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
|
||||
assertThat(Long.valueOf("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
|
||||
assertThat(new Long("6").equals(bw.getPropertyValue("long2"))).as("Correct long2 value").isTrue();
|
||||
assertThat(new Long("6").equals(tb.getLong2())).as("Correct long2 value").isTrue();
|
||||
|
||||
bw.setPropertyValue("long2", "");
|
||||
assertThat(bw.getPropertyValue("long2") == null).as("Correct long2 value").isTrue();
|
||||
@@ -458,7 +458,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
|
||||
public void testCustomNumberEditorWithFrenchBigDecimal() throws Exception {
|
||||
NumberFormat nf = NumberFormat.getNumberInstance(Locale.FRENCH);
|
||||
NumberTestBean tb = new NumberTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
@@ -475,14 +475,14 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
|
||||
public void testParseShortGreaterThanMaxValueWithoutNumberFormat() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Short.class, true);
|
||||
assertThatExceptionOfType(NumberFormatException.class).as("greater than Short.MAX_VALUE + 1").isThrownBy(() ->
|
||||
editor.setAsText(String.valueOf(Short.MAX_VALUE + 1)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testByteArrayPropertyEditor() {
|
||||
public void testByteArrayPropertyEditor() {
|
||||
PrimitiveArrayBean bean = new PrimitiveArrayBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.setPropertyValue("byteArray", "myvalue");
|
||||
@@ -490,7 +490,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharArrayPropertyEditor() {
|
||||
public void testCharArrayPropertyEditor() {
|
||||
PrimitiveArrayBean bean = new PrimitiveArrayBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.setPropertyValue("charArray", "myvalue");
|
||||
@@ -498,7 +498,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharacterEditor() {
|
||||
public void testCharacterEditor() {
|
||||
CharBean cb = new CharBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(cb);
|
||||
|
||||
@@ -520,78 +520,78 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharacterEditorWithAllowEmpty() {
|
||||
public void testCharacterEditorWithAllowEmpty() {
|
||||
CharBean cb = new CharBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(cb);
|
||||
bw.registerCustomEditor(Character.class, new CharacterEditor(true));
|
||||
|
||||
bw.setPropertyValue("myCharacter", 'c');
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
|
||||
bw.setPropertyValue("myCharacter", new Character('c'));
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(new Character('c'));
|
||||
|
||||
bw.setPropertyValue("myCharacter", "c");
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('c'));
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(new Character('c'));
|
||||
|
||||
bw.setPropertyValue("myCharacter", "\u0041");
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf('A'));
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(new Character('A'));
|
||||
|
||||
bw.setPropertyValue("myCharacter", " ");
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(Character.valueOf(' '));
|
||||
assertThat(cb.getMyCharacter()).isEqualTo(new Character(' '));
|
||||
|
||||
bw.setPropertyValue("myCharacter", "");
|
||||
assertThat(cb.getMyCharacter()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception {
|
||||
public void testCharacterEditorSetAsTextWithStringLongerThanOneCharacter() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
charEditor.setAsText("ColdWaterCanyon"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
||||
public void testCharacterEditorGetAsTextReturnsEmptyStringIfValueIsNull() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
assertThat(charEditor.getAsText()).isEmpty();
|
||||
assertThat(charEditor.getAsText()).isEqualTo("");
|
||||
charEditor = new CharacterEditor(true);
|
||||
charEditor.setAsText(null);
|
||||
assertThat(charEditor.getAsText()).isEmpty();
|
||||
assertThat(charEditor.getAsText()).isEqualTo("");
|
||||
charEditor.setAsText("");
|
||||
assertThat(charEditor.getAsText()).isEmpty();
|
||||
assertThat(charEditor.getAsText()).isEqualTo("");
|
||||
charEditor.setAsText(" ");
|
||||
assertThat(charEditor.getAsText()).isEqualTo(" ");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception {
|
||||
public void testCharacterEditorSetAsTextWithNullNotAllowingEmptyAsNull() throws Exception {
|
||||
PropertyEditor charEditor = new CharacterEditor(false);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
charEditor.setAsText(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassEditor() {
|
||||
public void testClassEditor() {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText(TestBean.class.getName());
|
||||
assertThat(classEditor.getValue()).isEqualTo(TestBean.class);
|
||||
assertThat(classEditor.getAsText()).isEqualTo(TestBean.class.getName());
|
||||
|
||||
classEditor.setAsText(null);
|
||||
assertThat(classEditor.getAsText()).isEmpty();
|
||||
assertThat(classEditor.getAsText()).isEqualTo("");
|
||||
classEditor.setAsText("");
|
||||
assertThat(classEditor.getAsText()).isEmpty();
|
||||
assertThat(classEditor.getAsText()).isEqualTo("");
|
||||
classEditor.setAsText("\t ");
|
||||
assertThat(classEditor.getAsText()).isEmpty();
|
||||
assertThat(classEditor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassEditorWithNonExistentClass() throws Exception {
|
||||
public void testClassEditorWithNonExistentClass() throws Exception {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
classEditor.setAsText("hairdresser.on.Fire"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassEditorWithArray() {
|
||||
public void testClassEditorWithArray() {
|
||||
PropertyEditor classEditor = new ClassEditor();
|
||||
classEditor.setAsText("org.springframework.beans.testfixture.beans.TestBean[]");
|
||||
assertThat(classEditor.getValue()).isEqualTo(TestBean[].class);
|
||||
@@ -602,7 +602,7 @@ class CustomEditorTests {
|
||||
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
|
||||
*/
|
||||
@Test
|
||||
void testGetAsTextWithTwoDimensionalArray() throws Exception {
|
||||
public void testGetAsTextWithTwoDimensionalArray() throws Exception {
|
||||
String[][] chessboard = new String[8][8];
|
||||
ClassEditor editor = new ClassEditor();
|
||||
editor.setValue(chessboard.getClass());
|
||||
@@ -613,7 +613,7 @@ class CustomEditorTests {
|
||||
* SPR_2165 - ClassEditor is inconsistent with multidimensional arrays
|
||||
*/
|
||||
@Test
|
||||
void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception {
|
||||
public void testGetAsTextWithRidiculousMultiDimensionalArray() throws Exception {
|
||||
String[][][][][] ridiculousChessboard = new String[8][4][0][1][3];
|
||||
ClassEditor editor = new ClassEditor();
|
||||
editor.setValue(ridiculousChessboard.getClass());
|
||||
@@ -621,7 +621,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFileEditor() {
|
||||
public void testFileEditor() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
fileEditor.setAsText("file:myfile.txt");
|
||||
assertThat(fileEditor.getValue()).isEqualTo(new File("myfile.txt"));
|
||||
@@ -629,7 +629,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFileEditorWithRelativePath() {
|
||||
public void testFileEditorWithRelativePath() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
try {
|
||||
fileEditor.setAsText("myfile.txt");
|
||||
@@ -641,7 +641,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFileEditorWithAbsolutePath() {
|
||||
public void testFileEditorWithAbsolutePath() {
|
||||
PropertyEditor fileEditor = new FileEditor();
|
||||
// testing on Windows
|
||||
if (new File("C:/myfile.txt").isAbsolute()) {
|
||||
@@ -656,18 +656,18 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testLocaleEditor() {
|
||||
public void testLocaleEditor() {
|
||||
PropertyEditor localeEditor = new LocaleEditor();
|
||||
localeEditor.setAsText("en_CA");
|
||||
assertThat(localeEditor.getValue()).isEqualTo(Locale.CANADA);
|
||||
assertThat(localeEditor.getAsText()).isEqualTo("en_CA");
|
||||
|
||||
localeEditor = new LocaleEditor();
|
||||
assertThat(localeEditor.getAsText()).isEmpty();
|
||||
assertThat(localeEditor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPatternEditor() {
|
||||
public void testPatternEditor() {
|
||||
final String REGEX = "a.*";
|
||||
|
||||
PropertyEditor patternEditor = new PatternEditor();
|
||||
@@ -676,15 +676,15 @@ class CustomEditorTests {
|
||||
assertThat(patternEditor.getAsText()).isEqualTo(REGEX);
|
||||
|
||||
patternEditor = new PatternEditor();
|
||||
assertThat(patternEditor.getAsText()).isEmpty();
|
||||
assertThat(patternEditor.getAsText()).isEqualTo("");
|
||||
|
||||
patternEditor = new PatternEditor();
|
||||
patternEditor.setAsText(null);
|
||||
assertThat(patternEditor.getAsText()).isEmpty();
|
||||
assertThat(patternEditor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomBooleanEditor() {
|
||||
public void testCustomBooleanEditor() {
|
||||
CustomBooleanEditor editor = new CustomBooleanEditor(false);
|
||||
|
||||
editor.setAsText("true");
|
||||
@@ -696,15 +696,15 @@ class CustomEditorTests {
|
||||
assertThat(editor.getAsText()).isEqualTo("false");
|
||||
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
editor.setAsText(null));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomBooleanEditorWithEmptyAsNull() {
|
||||
public void testCustomBooleanEditorWithEmptyAsNull() {
|
||||
CustomBooleanEditor editor = new CustomBooleanEditor(true);
|
||||
|
||||
editor.setAsText("true");
|
||||
@@ -716,34 +716,34 @@ class CustomEditorTests {
|
||||
assertThat(editor.getAsText()).isEqualTo("false");
|
||||
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomDateEditor() {
|
||||
public void testCustomDateEditor() {
|
||||
CustomDateEditor editor = new CustomDateEditor(null, false);
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomDateEditorWithEmptyAsNull() {
|
||||
public void testCustomDateEditorWithEmptyAsNull() {
|
||||
CustomDateEditor editor = new CustomDateEditor(null, true);
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomDateEditorWithExactDateLength() {
|
||||
public void testCustomDateEditorWithExactDateLength() {
|
||||
int maxLength = 10;
|
||||
String validDate = "01/01/2005";
|
||||
String invalidDate = "01/01/05";
|
||||
|
||||
assertThat(validDate).hasSize(maxLength);
|
||||
assertThat(invalidDate.length()).isNotEqualTo(maxLength);
|
||||
assertThat(validDate.length() == maxLength).isTrue();
|
||||
assertThat(invalidDate.length() == maxLength).isFalse();
|
||||
|
||||
CustomDateEditor editor = new CustomDateEditor(new SimpleDateFormat("MM/dd/yyyy"), true, maxLength);
|
||||
editor.setAsText(validDate);
|
||||
@@ -753,39 +753,39 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditor() {
|
||||
public void testCustomNumberEditor() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
|
||||
editor.setAsText("5");
|
||||
assertThat(editor.getValue()).isEqualTo(5);
|
||||
assertThat(editor.getAsText()).isEqualTo("5");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditorWithHex() {
|
||||
public void testCustomNumberEditorWithHex() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, false);
|
||||
editor.setAsText("0x" + Integer.toHexString(64));
|
||||
assertThat(editor.getValue()).isEqualTo(64);
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCustomNumberEditorWithEmptyAsNull() {
|
||||
public void testCustomNumberEditorWithEmptyAsNull() {
|
||||
CustomNumberEditor editor = new CustomNumberEditor(Integer.class, true);
|
||||
editor.setAsText("5");
|
||||
assertThat(editor.getValue()).isEqualTo(5);
|
||||
assertThat(editor.getAsText()).isEqualTo("5");
|
||||
editor.setAsText("");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringTrimmerEditor() {
|
||||
public void testStringTrimmerEditor() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor(false);
|
||||
editor.setAsText("test");
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
@@ -795,15 +795,15 @@ class CustomEditorTests {
|
||||
assertThat(editor.getAsText()).isEqualTo("test");
|
||||
editor.setAsText("");
|
||||
assertThat(editor.getValue()).isEqualTo("");
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setAsText(null);
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringTrimmerEditorWithEmptyAsNull() {
|
||||
public void testStringTrimmerEditorWithEmptyAsNull() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor(true);
|
||||
editor.setAsText("test");
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
@@ -812,14 +812,14 @@ class CustomEditorTests {
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
assertThat(editor.getAsText()).isEqualTo("test");
|
||||
editor.setAsText(" ");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringTrimmerEditorWithCharsToDelete() {
|
||||
public void testStringTrimmerEditorWithCharsToDelete() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", false);
|
||||
editor.setAsText("te\ns\ft");
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
@@ -829,13 +829,13 @@ class CustomEditorTests {
|
||||
assertThat(editor.getAsText()).isEqualTo("test");
|
||||
editor.setAsText("");
|
||||
assertThat(editor.getValue()).isEqualTo("");
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testStringTrimmerEditorWithCharsToDeleteAndEmptyAsNull() {
|
||||
public void testStringTrimmerEditorWithCharsToDeleteAndEmptyAsNull() {
|
||||
StringTrimmerEditor editor = new StringTrimmerEditor("\r\n\f", true);
|
||||
editor.setAsText("te\ns\ft");
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
@@ -844,14 +844,14 @@ class CustomEditorTests {
|
||||
assertThat(editor.getValue()).isEqualTo("test");
|
||||
assertThat(editor.getAsText()).isEqualTo("test");
|
||||
editor.setAsText(" \n\f ");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getValue()).isEqualTo(null);
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
editor.setValue(null);
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithCustomEditorForType() {
|
||||
public void testIndexedPropertiesWithCustomEditorForType() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
||||
@@ -904,7 +904,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithCustomEditorForProperty() {
|
||||
public void testIndexedPropertiesWithCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(String.class, "array.name", new PropertyEditorSupport() {
|
||||
@@ -971,7 +971,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
|
||||
public void testIndexedPropertiesWithIndividualCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(String.class, "array[0].name", new PropertyEditorSupport() {
|
||||
@@ -1056,7 +1056,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNestedIndexedPropertiesWithCustomEditorForProperty() {
|
||||
public void testNestedIndexedPropertiesWithCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
TestBean tb0 = bean.getArray()[0];
|
||||
TestBean tb1 = bean.getArray()[1];
|
||||
@@ -1140,7 +1140,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
|
||||
public void testNestedIndexedPropertiesWithIndexedCustomEditorForProperty() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
TestBean tb0 = bean.getArray()[0];
|
||||
TestBean tb1 = bean.getArray()[1];
|
||||
@@ -1191,7 +1191,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
|
||||
public void testIndexedPropertiesWithDirectAccessAndPropertyEditors() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(TestBean.class, "array", new PropertyEditorSupport() {
|
||||
@@ -1245,7 +1245,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
|
||||
public void testIndexedPropertiesWithDirectAccessAndSpecificPropertyEditors() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(TestBean.class, "array[0]", new PropertyEditorSupport() {
|
||||
@@ -1332,7 +1332,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testIndexedPropertiesWithListPropertyEditor() {
|
||||
public void testIndexedPropertiesWithListPropertyEditor() {
|
||||
IndexedTestBean bean = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
bw.registerCustomEditor(List.class, "list", new PropertyEditorSupport() {
|
||||
@@ -1350,7 +1350,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testConversionToOldCollections() throws PropertyVetoException {
|
||||
public void testConversionToOldCollections() throws PropertyVetoException {
|
||||
OldCollectionsBean tb = new OldCollectionsBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(Vector.class, new CustomCollectionEditor(Vector.class));
|
||||
@@ -1367,7 +1367,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testUninitializedArrayPropertyWithCustomEditor() {
|
||||
public void testUninitializedArrayPropertyWithCustomEditor() {
|
||||
IndexedTestBean bean = new IndexedTestBean(false);
|
||||
BeanWrapper bw = new BeanWrapperImpl(bean);
|
||||
PropertyEditor pe = new CustomNumberEditor(Integer.class, true);
|
||||
@@ -1383,7 +1383,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayToArrayConversion() throws PropertyVetoException {
|
||||
public void testArrayToArrayConversion() throws PropertyVetoException {
|
||||
IndexedTestBean tb = new IndexedTestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(TestBean.class, new PropertyEditorSupport() {
|
||||
@@ -1399,7 +1399,7 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testArrayToStringConversion() throws PropertyVetoException {
|
||||
public void testArrayToStringConversion() throws PropertyVetoException {
|
||||
TestBean tb = new TestBean();
|
||||
BeanWrapper bw = new BeanWrapperImpl(tb);
|
||||
bw.registerCustomEditor(String.class, new PropertyEditorSupport() {
|
||||
@@ -1408,16 +1408,16 @@ class CustomEditorTests {
|
||||
setValue("-" + text + "-");
|
||||
}
|
||||
});
|
||||
bw.setPropertyValue("name", new String[]{"a", "b"});
|
||||
bw.setPropertyValue("name", new String[] {"a", "b"});
|
||||
assertThat(tb.getName()).isEqualTo("-a,b-");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassArrayEditorSunnyDay() throws Exception {
|
||||
public void testClassArrayEditorSunnyDay() throws Exception {
|
||||
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
|
||||
classArrayEditor.setAsText("java.lang.String,java.util.HashMap");
|
||||
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
|
||||
assertThat(classes).hasSize(2);
|
||||
assertThat(classes.length).isEqualTo(2);
|
||||
assertThat(classes[0]).isEqualTo(String.class);
|
||||
assertThat(classes[1]).isEqualTo(HashMap.class);
|
||||
assertThat(classArrayEditor.getAsText()).isEqualTo("java.lang.String,java.util.HashMap");
|
||||
@@ -1426,11 +1426,11 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception {
|
||||
public void testClassArrayEditorSunnyDayWithArrayTypes() throws Exception {
|
||||
ClassArrayEditor classArrayEditor = new ClassArrayEditor();
|
||||
classArrayEditor.setAsText("java.lang.String[],java.util.Map[],int[],float[][][]");
|
||||
Class<?>[] classes = (Class<?>[]) classArrayEditor.getValue();
|
||||
assertThat(classes).hasSize(4);
|
||||
assertThat(classes.length).isEqualTo(4);
|
||||
assertThat(classes[0]).isEqualTo(String[].class);
|
||||
assertThat(classes[1]).isEqualTo(Map[].class);
|
||||
assertThat(classes[2]).isEqualTo(int[].class);
|
||||
@@ -1441,31 +1441,31 @@ class CustomEditorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassArrayEditorSetAsTextWithNull() throws Exception {
|
||||
public void testClassArrayEditorSetAsTextWithNull() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText(null);
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassArrayEditorSetAsTextWithEmptyString() throws Exception {
|
||||
public void testClassArrayEditorSetAsTextWithEmptyString() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText("");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception {
|
||||
public void testClassArrayEditorSetAsTextWithWhitespaceString() throws Exception {
|
||||
ClassArrayEditor editor = new ClassArrayEditor();
|
||||
editor.setAsText("\n");
|
||||
assertThat(editor.getValue()).isNull();
|
||||
assertThat(editor.getAsText()).isEmpty();
|
||||
assertThat(editor.getAsText()).isEqualTo("");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testCharsetEditor() throws Exception {
|
||||
public void testCharsetEditor() throws Exception {
|
||||
CharsetEditor editor = new CharsetEditor();
|
||||
String name = "UTF-8";
|
||||
editor.setAsText(name);
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
description = "Spring Context Indexer"
|
||||
|
||||
dependencies {
|
||||
testImplementation(project(":spring-context"))
|
||||
testImplementation("javax.inject:javax.inject")
|
||||
testImplementation("javax.annotation:javax.annotation-api")
|
||||
testImplementation("javax.transaction:javax.transaction-api")
|
||||
testImplementation("org.eclipse.persistence:javax.persistence")
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile("javax.inject:javax.inject")
|
||||
testCompile("javax.annotation:javax.annotation-api")
|
||||
testCompile("javax.transaction:javax.transaction-api")
|
||||
testCompile("org.eclipse.persistence:javax.persistence")
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
description = "Spring Context Support"
|
||||
|
||||
dependencies {
|
||||
api(project(":spring-beans"))
|
||||
api(project(":spring-context"))
|
||||
api(project(":spring-core"))
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-context"))
|
||||
compile(project(":spring-core"))
|
||||
optional(project(":spring-jdbc")) // for Quartz support
|
||||
optional(project(":spring-tx")) // for Quartz support
|
||||
optional("javax.activation:javax.activation-api")
|
||||
@@ -14,18 +14,18 @@ dependencies {
|
||||
optional("org.quartz-scheduler:quartz")
|
||||
optional("org.codehaus.fabric3.api:commonj")
|
||||
optional("org.freemarker:freemarker")
|
||||
testImplementation(project(":spring-context"))
|
||||
testImplementation(testFixtures(project(":spring-beans")))
|
||||
testImplementation(testFixtures(project(":spring-context")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation(testFixtures(project(":spring-tx")))
|
||||
testImplementation("org.hsqldb:hsqldb")
|
||||
testImplementation("org.hibernate:hibernate-validator")
|
||||
testImplementation("javax.annotation:javax.annotation-api")
|
||||
testRuntimeOnly("org.ehcache:jcache")
|
||||
testRuntimeOnly("org.ehcache:ehcache")
|
||||
testRuntimeOnly("org.glassfish:javax.el")
|
||||
testRuntimeOnly("com.sun.mail:javax.mail")
|
||||
testCompile(project(":spring-context"))
|
||||
testCompile(testFixtures(project(":spring-beans")))
|
||||
testCompile(testFixtures(project(":spring-context")))
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testCompile(testFixtures(project(":spring-tx")))
|
||||
testCompile("org.hsqldb:hsqldb")
|
||||
testCompile("org.hibernate:hibernate-validator")
|
||||
testCompile("javax.annotation:javax.annotation-api")
|
||||
testRuntime("org.ehcache:jcache")
|
||||
testRuntime("org.ehcache:ehcache")
|
||||
testRuntime("org.glassfish:javax.el")
|
||||
testRuntime("com.sun.mail:javax.mail")
|
||||
testFixturesApi("org.junit.jupiter:junit-jupiter-api")
|
||||
testFixturesImplementation("org.assertj:assertj-core")
|
||||
testFixturesImplementation("org.mockito:mockito-core")
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -138,7 +138,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getOperationDescription().append(']').toString();
|
||||
return getOperationDescription().append("]").toString();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -148,7 +148,7 @@ abstract class AbstractJCacheOperation<A extends Annotation> implements JCacheOp
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
result.append(getClass().getSimpleName());
|
||||
result.append('[');
|
||||
result.append("[");
|
||||
result.append(this.methodDetails);
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@ apply plugin: "groovy"
|
||||
apply plugin: "kotlin"
|
||||
|
||||
dependencies {
|
||||
api(project(":spring-aop"))
|
||||
api(project(":spring-beans"))
|
||||
api(project(":spring-core"))
|
||||
api(project(":spring-expression"))
|
||||
compile(project(":spring-aop"))
|
||||
compile(project(":spring-beans"))
|
||||
compile(project(":spring-core"))
|
||||
compile(project(":spring-expression"))
|
||||
optional(project(":spring-instrument"))
|
||||
optional("javax.annotation:javax.annotation-api")
|
||||
optional("javax.ejb:javax.ejb-api")
|
||||
@@ -26,22 +26,22 @@ dependencies {
|
||||
optional("org.jetbrains.kotlin:kotlin-reflect")
|
||||
optional("org.jetbrains.kotlin:kotlin-stdlib")
|
||||
optional("org.reactivestreams:reactive-streams")
|
||||
testImplementation(testFixtures(project(":spring-aop")))
|
||||
testImplementation(testFixtures(project(":spring-beans")))
|
||||
testImplementation(testFixtures(project(":spring-core")))
|
||||
testImplementation("io.projectreactor:reactor-core")
|
||||
testImplementation("org.codehaus.groovy:groovy-jsr223")
|
||||
testImplementation("org.codehaus.groovy:groovy-test")
|
||||
testImplementation("org.codehaus.groovy:groovy-xml")
|
||||
testImplementation("org.apache.commons:commons-pool2")
|
||||
testImplementation("javax.inject:javax.inject-tck")
|
||||
testImplementation("org.awaitility:awaitility")
|
||||
testRuntimeOnly("javax.xml.bind:jaxb-api")
|
||||
testRuntimeOnly("org.glassfish:javax.el")
|
||||
testCompile(testFixtures(project(":spring-aop")))
|
||||
testCompile(testFixtures(project(":spring-beans")))
|
||||
testCompile(testFixtures(project(":spring-core")))
|
||||
testCompile("io.projectreactor:reactor-core")
|
||||
testCompile("org.codehaus.groovy:groovy-jsr223")
|
||||
testCompile("org.codehaus.groovy:groovy-test")
|
||||
testCompile("org.codehaus.groovy:groovy-xml")
|
||||
testCompile("org.apache.commons:commons-pool2")
|
||||
testCompile("javax.inject:javax.inject-tck")
|
||||
testCompile("org.awaitility:awaitility")
|
||||
testRuntime("javax.xml.bind:jaxb-api")
|
||||
testRuntime("org.glassfish:javax.el")
|
||||
// Substitute for javax.management:jmxremote_optional:1.0.1_04 (not available on Maven Central)
|
||||
testRuntimeOnly("org.glassfish.external:opendmk_jmxremote_optional_jar")
|
||||
testRuntimeOnly("org.javamoney:moneta")
|
||||
testRuntimeOnly("org.junit.vintage:junit-vintage-engine") // for @Inject TCK
|
||||
testRuntime("org.glassfish.external:opendmk_jmxremote_optional_jar")
|
||||
testRuntime("org.javamoney:moneta")
|
||||
testRuntime("org.junit.vintage:junit-vintage-engine") // for @Inject TCK
|
||||
testFixturesApi("org.junit.jupiter:junit-jupiter-api")
|
||||
testFixturesImplementation(testFixtures(project(":spring-beans")))
|
||||
testFixturesImplementation("com.google.code.findbugs:jsr305")
|
||||
|
||||
+4
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2016 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,11 +38,9 @@ import org.springframework.core.annotation.AliasFor;
|
||||
* replace the default one (see {@link #keyGenerator}).
|
||||
*
|
||||
* <p>If no value is found in the cache for the computed key, the target method
|
||||
* will be invoked and the returned value will be stored in the associated cache.
|
||||
* Note that {@link java.util.Optional} return types are unwrapped automatically.
|
||||
* If an {@code Optional} value is {@linkplain java.util.Optional#isPresent()
|
||||
* present}, it will be stored in the associated cache. If an {@code Optional}
|
||||
* value is not present, {@code null} will be stored in the associated cache.
|
||||
* will be invoked and the returned value stored in the associated cache. Note
|
||||
* that Java8's {@code Optional} return types are automatically handled and its
|
||||
* content is stored in the cache if present.
|
||||
*
|
||||
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
|
||||
* <em>composed annotations</em> with attribute overrides.
|
||||
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -71,9 +71,9 @@ public class CacheEvictOperation extends CacheOperation {
|
||||
@Override
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(',');
|
||||
sb.append(",");
|
||||
sb.append(this.cacheWide);
|
||||
sb.append(',');
|
||||
sb.append(",");
|
||||
sb.append(this.beforeInvocation);
|
||||
return sb;
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -216,13 +216,13 @@ public abstract class CacheOperation implements BasicOperation {
|
||||
*/
|
||||
protected StringBuilder getOperationDescription() {
|
||||
StringBuilder result = new StringBuilder(getClass().getSimpleName());
|
||||
result.append('[').append(this.name);
|
||||
result.append("[").append(this.name);
|
||||
result.append("] caches=").append(this.cacheNames);
|
||||
result.append(" | key='").append(this.key);
|
||||
result.append("' | keyGenerator='").append(this.keyGenerator);
|
||||
result.append("' | cacheManager='").append(this.cacheManager);
|
||||
result.append("' | cacheResolver='").append(this.cacheResolver);
|
||||
result.append("' | condition='").append(this.condition).append('\'');
|
||||
result.append("' | condition='").append(this.condition).append("'");
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -66,7 +66,7 @@ public class CachePutOperation extends CacheOperation {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append('\'');
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -79,10 +79,10 @@ public class CacheableOperation extends CacheOperation {
|
||||
StringBuilder sb = super.getOperationDescription();
|
||||
sb.append(" | unless='");
|
||||
sb.append(this.unless);
|
||||
sb.append('\'');
|
||||
sb.append("'");
|
||||
sb.append(" | sync='");
|
||||
sb.append(this.sync);
|
||||
sb.append('\'');
|
||||
sb.append("'");
|
||||
return sb;
|
||||
}
|
||||
|
||||
|
||||
+5
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -19,15 +19,13 @@ package org.springframework.context.annotation;
|
||||
import org.springframework.beans.factory.parsing.Problem;
|
||||
import org.springframework.beans.factory.parsing.ProblemReporter;
|
||||
import org.springframework.core.type.MethodMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Represents a {@link Configuration @Configuration} class method annotated with
|
||||
* {@link Bean @Bean}.
|
||||
* Represents a {@link Configuration @Configuration} class method marked with the
|
||||
* {@link Bean @Bean} annotation.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @see ConfigurationClass
|
||||
* @see ConfigurationClassParser
|
||||
@@ -35,7 +33,7 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
final class BeanMethod extends ConfigurationMethod {
|
||||
|
||||
BeanMethod(MethodMetadata metadata, ConfigurationClass configurationClass) {
|
||||
public BeanMethod(MethodMetadata metadata, ConfigurationClass configurationClass) {
|
||||
super(metadata, configurationClass);
|
||||
}
|
||||
|
||||
@@ -54,28 +52,12 @@ final class BeanMethod extends ConfigurationMethod {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
return ((this == obj) || ((obj instanceof BeanMethod) &&
|
||||
this.metadata.equals(((BeanMethod) obj).metadata)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return this.metadata.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BeanMethod: " + this.metadata;
|
||||
}
|
||||
|
||||
private class NonOverridableMethodError extends Problem {
|
||||
|
||||
NonOverridableMethodError() {
|
||||
public NonOverridableMethodError() {
|
||||
super(String.format("@Bean method '%s' must not be private or final; change the method's modifiers to continue",
|
||||
getMetadata().getMethodName()), getResourceLocation());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -36,7 +36,7 @@ import org.springframework.util.ClassUtils;
|
||||
|
||||
/**
|
||||
* Represents a user-defined {@link Configuration @Configuration} class.
|
||||
* <p>Includes a set of {@link Bean} methods, including all such methods
|
||||
* Includes a set of {@link Bean} methods, including all such methods
|
||||
* defined in the ancestry of the class, in a 'flattened-out' manner.
|
||||
*
|
||||
* @author Chris Beams
|
||||
@@ -74,7 +74,7 @@ final class ConfigurationClass {
|
||||
* @param beanName must not be {@code null}
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(MetadataReader metadataReader, String beanName) {
|
||||
public ConfigurationClass(MetadataReader metadataReader, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
this.metadata = metadataReader.getAnnotationMetadata();
|
||||
this.resource = metadataReader.getResource();
|
||||
@@ -89,7 +89,7 @@ final class ConfigurationClass {
|
||||
* @param importedBy the configuration class importing this one or {@code null}
|
||||
* @since 3.1.1
|
||||
*/
|
||||
ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) {
|
||||
public ConfigurationClass(MetadataReader metadataReader, @Nullable ConfigurationClass importedBy) {
|
||||
this.metadata = metadataReader.getAnnotationMetadata();
|
||||
this.resource = metadataReader.getResource();
|
||||
this.importedBy.add(importedBy);
|
||||
@@ -101,7 +101,7 @@ final class ConfigurationClass {
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(Class<?> clazz, String beanName) {
|
||||
public ConfigurationClass(Class<?> clazz, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
this.metadata = AnnotationMetadata.introspect(clazz);
|
||||
this.resource = new DescriptiveResource(clazz.getName());
|
||||
@@ -116,7 +116,7 @@ final class ConfigurationClass {
|
||||
* @param importedBy the configuration class importing this one (or {@code null})
|
||||
* @since 3.1.1
|
||||
*/
|
||||
ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
|
||||
public ConfigurationClass(Class<?> clazz, @Nullable ConfigurationClass importedBy) {
|
||||
this.metadata = AnnotationMetadata.introspect(clazz);
|
||||
this.resource = new DescriptiveResource(clazz.getName());
|
||||
this.importedBy.add(importedBy);
|
||||
@@ -128,7 +128,7 @@ final class ConfigurationClass {
|
||||
* @param beanName name of the {@code @Configuration} class bean
|
||||
* @see ConfigurationClass#ConfigurationClass(Class, ConfigurationClass)
|
||||
*/
|
||||
ConfigurationClass(AnnotationMetadata metadata, String beanName) {
|
||||
public ConfigurationClass(AnnotationMetadata metadata, String beanName) {
|
||||
Assert.notNull(beanName, "Bean name must not be null");
|
||||
this.metadata = metadata;
|
||||
this.resource = new DescriptiveResource(metadata.getClassName());
|
||||
@@ -136,19 +136,19 @@ final class ConfigurationClass {
|
||||
}
|
||||
|
||||
|
||||
AnnotationMetadata getMetadata() {
|
||||
public AnnotationMetadata getMetadata() {
|
||||
return this.metadata;
|
||||
}
|
||||
|
||||
Resource getResource() {
|
||||
public Resource getResource() {
|
||||
return this.resource;
|
||||
}
|
||||
|
||||
String getSimpleName() {
|
||||
public String getSimpleName() {
|
||||
return ClassUtils.getShortName(getMetadata().getClassName());
|
||||
}
|
||||
|
||||
void setBeanName(String beanName) {
|
||||
public void setBeanName(String beanName) {
|
||||
this.beanName = beanName;
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ final class ConfigurationClass {
|
||||
* Merge the imported-by declarations from the given configuration class into this one.
|
||||
* @since 4.0.5
|
||||
*/
|
||||
void mergeImportedBy(ConfigurationClass otherConfigClass) {
|
||||
public void mergeImportedBy(ConfigurationClass otherConfigClass) {
|
||||
this.importedBy.addAll(otherConfigClass.importedBy);
|
||||
}
|
||||
|
||||
@@ -181,35 +181,35 @@ final class ConfigurationClass {
|
||||
* @since 4.0.5
|
||||
* @see #isImported()
|
||||
*/
|
||||
Set<ConfigurationClass> getImportedBy() {
|
||||
public Set<ConfigurationClass> getImportedBy() {
|
||||
return this.importedBy;
|
||||
}
|
||||
|
||||
void addBeanMethod(BeanMethod method) {
|
||||
public void addBeanMethod(BeanMethod method) {
|
||||
this.beanMethods.add(method);
|
||||
}
|
||||
|
||||
Set<BeanMethod> getBeanMethods() {
|
||||
public Set<BeanMethod> getBeanMethods() {
|
||||
return this.beanMethods;
|
||||
}
|
||||
|
||||
void addImportedResource(String importedResource, Class<? extends BeanDefinitionReader> readerClass) {
|
||||
public void addImportedResource(String importedResource, Class<? extends BeanDefinitionReader> readerClass) {
|
||||
this.importedResources.put(importedResource, readerClass);
|
||||
}
|
||||
|
||||
void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) {
|
||||
public void addImportBeanDefinitionRegistrar(ImportBeanDefinitionRegistrar registrar, AnnotationMetadata importingClassMetadata) {
|
||||
this.importBeanDefinitionRegistrars.put(registrar, importingClassMetadata);
|
||||
}
|
||||
|
||||
Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> getImportBeanDefinitionRegistrars() {
|
||||
public Map<ImportBeanDefinitionRegistrar, AnnotationMetadata> getImportBeanDefinitionRegistrars() {
|
||||
return this.importBeanDefinitionRegistrars;
|
||||
}
|
||||
|
||||
Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() {
|
||||
public Map<String, Class<? extends BeanDefinitionReader>> getImportedResources() {
|
||||
return this.importedResources;
|
||||
}
|
||||
|
||||
void validate(ProblemReporter problemReporter) {
|
||||
public void validate(ProblemReporter problemReporter) {
|
||||
// A configuration class may not be final (CGLIB limitation) unless it declares proxyBeanMethods=false
|
||||
Map<String, Object> attributes = this.metadata.getAnnotationAttributes(Configuration.class.getName());
|
||||
if (attributes != null && (Boolean) attributes.get("proxyBeanMethods")) {
|
||||
@@ -244,7 +244,7 @@ final class ConfigurationClass {
|
||||
*/
|
||||
private class FinalConfigurationProblem extends Problem {
|
||||
|
||||
FinalConfigurationProblem() {
|
||||
public FinalConfigurationProblem() {
|
||||
super(String.format("@Configuration class '%s' may not be final. Remove the final modifier to continue.",
|
||||
getSimpleName()), new Location(getResource(), getMetadata()));
|
||||
}
|
||||
|
||||
+11
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -51,9 +51,18 @@ abstract class ConfigurationMethod {
|
||||
return new Location(this.configurationClass.getResource(), this.metadata);
|
||||
}
|
||||
|
||||
void validate(ProblemReporter problemReporter) {
|
||||
String getFullyQualifiedMethodName() {
|
||||
return this.metadata.getDeclaringClassName() + "#" + this.metadata.getMethodName();
|
||||
}
|
||||
|
||||
static String getShortMethodName(String fullyQualifiedMethodName) {
|
||||
return fullyQualifiedMethodName.substring(fullyQualifiedMethodName.indexOf('#') + 1);
|
||||
}
|
||||
|
||||
public void validate(ProblemReporter problemReporter) {
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("[%s:name=%s,declaringClass=%s]",
|
||||
|
||||
+2
-2
@@ -396,7 +396,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||
* @param message error message to append the HandlerMethod details to
|
||||
*/
|
||||
protected String getDetailedErrorMessage(Object bean, String message) {
|
||||
StringBuilder sb = new StringBuilder(message).append('\n');
|
||||
StringBuilder sb = new StringBuilder(message).append("\n");
|
||||
sb.append("HandlerMethod details: \n");
|
||||
sb.append("Bean [").append(bean.getClass().getName()).append("]\n");
|
||||
sb.append("Method [").append(this.method.toGenericString()).append("]\n");
|
||||
@@ -426,7 +426,7 @@ public class ApplicationListenerMethodAdapter implements GenericApplicationListe
|
||||
StringBuilder sb = new StringBuilder(getDetailedErrorMessage(bean, message));
|
||||
sb.append("Resolved arguments: \n");
|
||||
for (int i = 0; i < resolvedArgs.length; i++) {
|
||||
sb.append('[').append(i).append("] ");
|
||||
sb.append("[").append(i).append("] ");
|
||||
if (resolvedArgs[i] == null) {
|
||||
sb.append("[null] \n");
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -205,12 +205,12 @@ public class LiveBeansView implements LiveBeansViewMBean, ApplicationContextAwar
|
||||
}
|
||||
}
|
||||
result.append("]\n");
|
||||
result.append('}');
|
||||
result.append("}");
|
||||
if (it.hasNext()) {
|
||||
result.append(",\n");
|
||||
}
|
||||
}
|
||||
result.append(']');
|
||||
result.append("]");
|
||||
return result.toString();
|
||||
}
|
||||
|
||||
|
||||
+17
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -31,7 +31,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
/**
|
||||
* Enables Spring's scheduled task execution capability, similar to
|
||||
* functionality found in Spring's {@code <task:*>} XML namespace. To be used
|
||||
* on {@link Configuration @Configuration} classes as follows:
|
||||
* on @{@link Configuration} classes as follows:
|
||||
*
|
||||
* <pre class="code">
|
||||
* @Configuration
|
||||
@@ -41,8 +41,8 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* // various @Bean definitions
|
||||
* }</pre>
|
||||
*
|
||||
* <p>This enables detection of {@link Scheduled @Scheduled} annotations on any
|
||||
* Spring-managed bean in the container. For example, given a class {@code MyTask}:
|
||||
* This enables detection of @{@link Scheduled} annotations on any Spring-managed
|
||||
* bean in the container. For example, given a class {@code MyTask}
|
||||
*
|
||||
* <pre class="code">
|
||||
* package com.myco.tasks;
|
||||
@@ -55,7 +55,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>the following configuration would ensure that {@code MyTask.work()} is called
|
||||
* the following configuration would ensure that {@code MyTask.work()} is called
|
||||
* once every 1000 ms:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -69,7 +69,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Alternatively, if {@code MyTask} were annotated with {@code @Component}, the
|
||||
* Alternatively, if {@code MyTask} were annotated with {@code @Component}, the
|
||||
* following configuration would ensure that its {@code @Scheduled} method is
|
||||
* invoked at the desired interval:
|
||||
*
|
||||
@@ -80,7 +80,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* public class AppConfig {
|
||||
* }</pre>
|
||||
*
|
||||
* <p>Methods annotated with {@code @Scheduled} may even be declared directly within
|
||||
* Methods annotated with {@code @Scheduled} may even be declared directly within
|
||||
* {@code @Configuration} classes:
|
||||
*
|
||||
* <pre class="code">
|
||||
@@ -94,7 +94,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* }
|
||||
* }</pre>
|
||||
*
|
||||
* <p>By default, Spring will search for an associated scheduler definition: either
|
||||
* <p>By default, will be searching for an associated scheduler definition: either
|
||||
* a unique {@link org.springframework.scheduling.TaskScheduler} bean in the context,
|
||||
* or a {@code TaskScheduler} bean named "taskScheduler" otherwise; the same lookup
|
||||
* will also be performed for a {@link java.util.concurrent.ScheduledExecutorService}
|
||||
@@ -141,7 +141,11 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* public void configureTasks(ScheduledTaskRegistrar taskRegistrar) {
|
||||
* taskRegistrar.setScheduler(taskScheduler());
|
||||
* taskRegistrar.addTriggerTask(
|
||||
* () -> myTask().work(),
|
||||
* new Runnable() {
|
||||
* public void run() {
|
||||
* myTask().work();
|
||||
* }
|
||||
* },
|
||||
* new CustomTrigger()
|
||||
* );
|
||||
* }
|
||||
@@ -161,7 +165,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* configuration:
|
||||
*
|
||||
* <pre class="code">
|
||||
* <beans>
|
||||
* <beans>
|
||||
*
|
||||
* <task:annotation-driven scheduler="taskScheduler"/>
|
||||
*
|
||||
@@ -176,13 +180,13 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* </beans>
|
||||
* </pre>
|
||||
*
|
||||
* <p>The examples are equivalent save that in XML a <em>fixed-rate</em> period is used
|
||||
* The examples are equivalent save that in XML a <em>fixed-rate</em> period is used
|
||||
* instead of a custom <em>{@code Trigger}</em> implementation; this is because the
|
||||
* {@code task:} namespace {@code scheduled} cannot easily expose such support. This is
|
||||
* but one demonstration how the code-based approach allows for maximum configurability
|
||||
* through direct access to actual componentry.
|
||||
* through direct access to actual componentry.<p>
|
||||
*
|
||||
* <p><b>Note: {@code @EnableScheduling} applies to its local application context only,
|
||||
* <b>Note: {@code @EnableScheduling} applies to its local application context only,
|
||||
* allowing for selective scheduling of beans at different levels.</b> Please redeclare
|
||||
* {@code @EnableScheduling} in each individual context, e.g. the common root web
|
||||
* application context and any separate {@code DispatcherServlet} application contexts,
|
||||
|
||||
+17
-43
@@ -22,7 +22,6 @@ import java.lang.annotation.Repeatable;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
@@ -38,7 +37,7 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* <p>Processing of {@code @Scheduled} annotations is performed by
|
||||
* registering a {@link ScheduledAnnotationBeanPostProcessor}. This can be
|
||||
* done manually or, more conveniently, through the {@code <task:annotation-driven/>}
|
||||
* XML element or {@link EnableScheduling @EnableScheduling} annotation.
|
||||
* element or @{@link EnableScheduling} annotation.
|
||||
*
|
||||
* <p>This annotation may be used as a <em>meta-annotation</em> to create custom
|
||||
* <em>composed annotations</em> with attribute overrides.
|
||||
@@ -47,8 +46,6 @@ import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
* @author Juergen Hoeller
|
||||
* @author Dave Syer
|
||||
* @author Chris Beams
|
||||
* @author Victor Brown
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @see EnableScheduling
|
||||
* @see ScheduledAnnotationBeanPostProcessor
|
||||
@@ -104,75 +101,52 @@ public @interface Scheduled {
|
||||
String zone() default "";
|
||||
|
||||
/**
|
||||
* Execute the annotated method with a fixed period between the end of the
|
||||
* last invocation and the start of the next.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the delay
|
||||
* Execute the annotated method with a fixed period in milliseconds between the
|
||||
* end of the last invocation and the start of the next.
|
||||
* @return the delay in milliseconds
|
||||
*/
|
||||
long fixedDelay() default -1;
|
||||
|
||||
/**
|
||||
* Execute the annotated method with a fixed period between the end of the
|
||||
* last invocation and the start of the next.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the delay as a String value — for example, a placeholder
|
||||
* Execute the annotated method with a fixed period in milliseconds between the
|
||||
* end of the last invocation and the start of the next.
|
||||
* @return the delay in milliseconds as a String value, e.g. a placeholder
|
||||
* or a {@link java.time.Duration#parse java.time.Duration} compliant value
|
||||
* @since 3.2.2
|
||||
*/
|
||||
String fixedDelayString() default "";
|
||||
|
||||
/**
|
||||
* Execute the annotated method with a fixed period between invocations.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the period
|
||||
* Execute the annotated method with a fixed period in milliseconds between
|
||||
* invocations.
|
||||
* @return the period in milliseconds
|
||||
*/
|
||||
long fixedRate() default -1;
|
||||
|
||||
/**
|
||||
* Execute the annotated method with a fixed period between invocations.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the period as a String value — for example, a placeholder
|
||||
* Execute the annotated method with a fixed period in milliseconds between
|
||||
* invocations.
|
||||
* @return the period in milliseconds as a String value, e.g. a placeholder
|
||||
* or a {@link java.time.Duration#parse java.time.Duration} compliant value
|
||||
* @since 3.2.2
|
||||
*/
|
||||
String fixedRateString() default "";
|
||||
|
||||
/**
|
||||
* Number of units of time to delay before the first execution of a
|
||||
* Number of milliseconds to delay before the first execution of a
|
||||
* {@link #fixedRate} or {@link #fixedDelay} task.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the initial
|
||||
* @return the initial delay in milliseconds
|
||||
* @since 3.2
|
||||
*/
|
||||
long initialDelay() default -1;
|
||||
|
||||
/**
|
||||
* Number of units of time to delay before the first execution of a
|
||||
* Number of milliseconds to delay before the first execution of a
|
||||
* {@link #fixedRate} or {@link #fixedDelay} task.
|
||||
* <p>The time unit is milliseconds by default but can be overridden via
|
||||
* {@link #timeUnit}.
|
||||
* @return the initial delay as a String value — for example, a placeholder
|
||||
* @return the initial delay in milliseconds as a String value, e.g. a placeholder
|
||||
* or a {@link java.time.Duration#parse java.time.Duration} compliant value
|
||||
* @since 3.2.2
|
||||
*/
|
||||
String initialDelayString() default "";
|
||||
|
||||
/**
|
||||
* The {@link TimeUnit} to use for {@link #fixedDelay}, {@link #fixedDelayString},
|
||||
* {@link #fixedRate}, {@link #fixedRateString}, {@link #initialDelay}, and
|
||||
* {@link #initialDelayString}.
|
||||
* <p>Defaults to {@link TimeUnit#MILLISECONDS}.
|
||||
* <p>This attribute is ignored for {@linkplain #cron() cron expressions}
|
||||
* and for {@link java.time.Duration} values supplied via {@link #fixedDelayString},
|
||||
* {@link #fixedRateString}, or {@link #initialDelayString}.
|
||||
* @return the {@code TimeUnit} to use
|
||||
* @since 5.3.10
|
||||
*/
|
||||
TimeUnit timeUnit() default TimeUnit.MILLISECONDS;
|
||||
|
||||
}
|
||||
|
||||
+16
-31
@@ -30,7 +30,6 @@ import java.util.Set;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
@@ -78,10 +77,9 @@ import org.springframework.util.StringUtils;
|
||||
import org.springframework.util.StringValueResolver;
|
||||
|
||||
/**
|
||||
* Bean post-processor that registers methods annotated with
|
||||
* {@link Scheduled @Scheduled} to be invoked by a
|
||||
* {@link org.springframework.scheduling.TaskScheduler} according to the
|
||||
* "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
|
||||
* Bean post-processor that registers methods annotated with @{@link Scheduled}
|
||||
* to be invoked by a {@link org.springframework.scheduling.TaskScheduler} according
|
||||
* to the "fixedRate", "fixedDelay", or "cron" expression provided via the annotation.
|
||||
*
|
||||
* <p>This post-processor is automatically registered by Spring's
|
||||
* {@code <task:annotation-driven>} XML element, and also by the
|
||||
@@ -89,16 +87,13 @@ import org.springframework.util.StringValueResolver;
|
||||
*
|
||||
* <p>Autodetects any {@link SchedulingConfigurer} instances in the container,
|
||||
* allowing for customization of the scheduler to be used or for fine-grained
|
||||
* control over task registration (e.g. registration of {@link Trigger} tasks).
|
||||
* See the {@link EnableScheduling @EnableScheduling} javadocs for complete usage
|
||||
* details.
|
||||
* control over task registration (e.g. registration of {@link Trigger} tasks.
|
||||
* See the @{@link EnableScheduling} javadocs for complete usage details.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Elizabeth Chatman
|
||||
* @author Victor Brown
|
||||
* @author Sam Brannen
|
||||
* @since 3.0
|
||||
* @see Scheduled
|
||||
* @see EnableScheduling
|
||||
@@ -155,8 +150,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
/**
|
||||
* Create a {@code ScheduledAnnotationBeanPostProcessor} delegating to the
|
||||
* specified {@link ScheduledTaskRegistrar}.
|
||||
* @param registrar the ScheduledTaskRegistrar to register {@code @Scheduled}
|
||||
* tasks on
|
||||
* @param registrar the ScheduledTaskRegistrar to register @Scheduled tasks on
|
||||
* @since 5.1
|
||||
*/
|
||||
public ScheduledAnnotationBeanPostProcessor(ScheduledTaskRegistrar registrar) {
|
||||
@@ -389,7 +383,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
|
||||
/**
|
||||
* Process the given {@code @Scheduled} method declaration on the given bean.
|
||||
* @param scheduled the {@code @Scheduled} annotation
|
||||
* @param scheduled the @Scheduled annotation
|
||||
* @param method the method that the annotation has been declared on
|
||||
* @param bean the target bean instance
|
||||
* @see #createRunnable(Object, Method)
|
||||
@@ -404,7 +398,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
Set<ScheduledTask> tasks = new LinkedHashSet<>(4);
|
||||
|
||||
// Determine initial delay
|
||||
long initialDelay = convertToMillis(scheduled.initialDelay(), scheduled.timeUnit());
|
||||
long initialDelay = scheduled.initialDelay();
|
||||
String initialDelayString = scheduled.initialDelayString();
|
||||
if (StringUtils.hasText(initialDelayString)) {
|
||||
Assert.isTrue(initialDelay < 0, "Specify 'initialDelay' or 'initialDelayString', not both");
|
||||
@@ -413,7 +407,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
}
|
||||
if (StringUtils.hasLength(initialDelayString)) {
|
||||
try {
|
||||
initialDelay = convertToMillis(initialDelayString, scheduled.timeUnit());
|
||||
initialDelay = parseDelayAsLong(initialDelayString);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -452,13 +446,12 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
}
|
||||
|
||||
// Check fixed delay
|
||||
long fixedDelay = convertToMillis(scheduled.fixedDelay(), scheduled.timeUnit());
|
||||
long fixedDelay = scheduled.fixedDelay();
|
||||
if (fixedDelay >= 0) {
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
tasks.add(this.registrar.scheduleFixedDelayTask(new FixedDelayTask(runnable, fixedDelay, initialDelay)));
|
||||
}
|
||||
|
||||
String fixedDelayString = scheduled.fixedDelayString();
|
||||
if (StringUtils.hasText(fixedDelayString)) {
|
||||
if (this.embeddedValueResolver != null) {
|
||||
@@ -468,7 +461,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
try {
|
||||
fixedDelay = convertToMillis(fixedDelayString, scheduled.timeUnit());
|
||||
fixedDelay = parseDelayAsLong(fixedDelayString);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -479,7 +472,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
}
|
||||
|
||||
// Check fixed rate
|
||||
long fixedRate = convertToMillis(scheduled.fixedRate(), scheduled.timeUnit());
|
||||
long fixedRate = scheduled.fixedRate();
|
||||
if (fixedRate >= 0) {
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
@@ -494,7 +487,7 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
Assert.isTrue(!processedSchedule, errorMessage);
|
||||
processedSchedule = true;
|
||||
try {
|
||||
fixedRate = convertToMillis(fixedRateString, scheduled.timeUnit());
|
||||
fixedRate = parseDelayAsLong(fixedRateString);
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
throw new IllegalArgumentException(
|
||||
@@ -534,19 +527,11 @@ public class ScheduledAnnotationBeanPostProcessor
|
||||
return new ScheduledMethodRunnable(target, invocableMethod);
|
||||
}
|
||||
|
||||
private static long convertToMillis(long value, TimeUnit timeUnit) {
|
||||
return TimeUnit.MILLISECONDS.convert(value, timeUnit);
|
||||
}
|
||||
|
||||
private static long convertToMillis(String value, TimeUnit timeUnit) {
|
||||
if (isDurationString(value)) {
|
||||
private static long parseDelayAsLong(String value) throws RuntimeException {
|
||||
if (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1)))) {
|
||||
return Duration.parse(value).toMillis();
|
||||
}
|
||||
return convertToMillis(Long.parseLong(value), timeUnit);
|
||||
}
|
||||
|
||||
private static boolean isDurationString(String value) {
|
||||
return (value.length() > 1 && (isP(value.charAt(0)) || isP(value.charAt(1))));
|
||||
return Long.parseLong(value);
|
||||
}
|
||||
|
||||
private static boolean isP(char ch) {
|
||||
|
||||
+9
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -19,17 +19,17 @@ package org.springframework.scheduling.annotation;
|
||||
import org.springframework.scheduling.config.ScheduledTaskRegistrar;
|
||||
|
||||
/**
|
||||
* Optional interface to be implemented by {@link
|
||||
* org.springframework.context.annotation.Configuration @Configuration} classes annotated
|
||||
* with {@link EnableScheduling @EnableScheduling}. Typically used for setting a specific
|
||||
* Optional interface to be implemented by @{@link
|
||||
* org.springframework.context.annotation.Configuration Configuration} classes annotated
|
||||
* with @{@link EnableScheduling}. Typically used for setting a specific
|
||||
* {@link org.springframework.scheduling.TaskScheduler TaskScheduler} bean to be used when
|
||||
* executing scheduled tasks or for registering scheduled tasks in a <em>programmatic</em>
|
||||
* fashion as opposed to the <em>declarative</em> approach of using the
|
||||
* {@link Scheduled @Scheduled} annotation. For example, this may be necessary
|
||||
* when implementing {@link org.springframework.scheduling.Trigger Trigger}-based
|
||||
* tasks, which are not supported by the {@code @Scheduled} annotation.
|
||||
* fashion as opposed to the <em>declarative</em> approach of using the @{@link Scheduled}
|
||||
* annotation. For example, this may be necessary when implementing {@link
|
||||
* org.springframework.scheduling.Trigger Trigger}-based tasks, which are not supported by
|
||||
* the {@code @Scheduled} annotation.
|
||||
*
|
||||
* <p>See {@link EnableScheduling @EnableScheduling} for detailed usage examples.
|
||||
* <p>See @{@link EnableScheduling} for detailed usage examples.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @since 3.1
|
||||
|
||||
+3
-3
@@ -112,10 +112,10 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
*/
|
||||
public void setCorePoolSize(int corePoolSize) {
|
||||
synchronized (this.poolSizeMonitor) {
|
||||
this.corePoolSize = corePoolSize;
|
||||
if (this.threadPoolExecutor != null) {
|
||||
this.threadPoolExecutor.setCorePoolSize(corePoolSize);
|
||||
}
|
||||
this.corePoolSize = corePoolSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -135,10 +135,10 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
*/
|
||||
public void setMaxPoolSize(int maxPoolSize) {
|
||||
synchronized (this.poolSizeMonitor) {
|
||||
this.maxPoolSize = maxPoolSize;
|
||||
if (this.threadPoolExecutor != null) {
|
||||
this.threadPoolExecutor.setMaximumPoolSize(maxPoolSize);
|
||||
}
|
||||
this.maxPoolSize = maxPoolSize;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -158,10 +158,10 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
*/
|
||||
public void setKeepAliveSeconds(int keepAliveSeconds) {
|
||||
synchronized (this.poolSizeMonitor) {
|
||||
this.keepAliveSeconds = keepAliveSeconds;
|
||||
if (this.threadPoolExecutor != null) {
|
||||
this.threadPoolExecutor.setKeepAliveTime(keepAliveSeconds, TimeUnit.SECONDS);
|
||||
}
|
||||
this.keepAliveSeconds = keepAliveSeconds;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+25
-66
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -53,8 +53,6 @@ import org.springframework.util.concurrent.ListenableFutureTask;
|
||||
* @since 3.0
|
||||
* @see #setPoolSize
|
||||
* @see #setRemoveOnCancelPolicy
|
||||
* @see #setContinueExistingPeriodicTasksAfterShutdownPolicy
|
||||
* @see #setExecuteExistingDelayedTasksAfterShutdownPolicy
|
||||
* @see #setThreadFactory
|
||||
* @see #setErrorHandler
|
||||
*/
|
||||
@@ -66,10 +64,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
|
||||
private volatile boolean removeOnCancelPolicy;
|
||||
|
||||
private volatile boolean continueExistingPeriodicTasksAfterShutdownPolicy;
|
||||
|
||||
private volatile boolean executeExistingDelayedTasksAfterShutdownPolicy = true;
|
||||
|
||||
@Nullable
|
||||
private volatile ErrorHandler errorHandler;
|
||||
|
||||
@@ -90,54 +84,26 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
*/
|
||||
public void setPoolSize(int poolSize) {
|
||||
Assert.isTrue(poolSize > 0, "'poolSize' must be 1 or higher");
|
||||
this.poolSize = poolSize;
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setCorePoolSize(poolSize);
|
||||
}
|
||||
this.poolSize = poolSize;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the remove-on-cancel mode on {@link ScheduledThreadPoolExecutor}.
|
||||
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
|
||||
* switched into remove-on-cancel mode (if possible).
|
||||
* switched into remove-on-cancel mode (if possible, with a soft fallback otherwise).
|
||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||
* @see ScheduledThreadPoolExecutor#setRemoveOnCancelPolicy
|
||||
*/
|
||||
public void setRemoveOnCancelPolicy(boolean flag) {
|
||||
public void setRemoveOnCancelPolicy(boolean removeOnCancelPolicy) {
|
||||
this.removeOnCancelPolicy = removeOnCancelPolicy;
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(flag);
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(removeOnCancelPolicy);
|
||||
}
|
||||
this.removeOnCancelPolicy = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to continue existing periodic tasks even when this executor has been shutdown.
|
||||
* <p>Default is {@code false}. If set to {@code true}, the target executor will be
|
||||
* switched into continuing periodic tasks (if possible).
|
||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||
* @since 5.3.9
|
||||
* @see ScheduledThreadPoolExecutor#setContinueExistingPeriodicTasksAfterShutdownPolicy
|
||||
*/
|
||||
public void setContinueExistingPeriodicTasksAfterShutdownPolicy(boolean flag) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setContinueExistingPeriodicTasksAfterShutdownPolicy(flag);
|
||||
else if (removeOnCancelPolicy && this.scheduledExecutor != null) {
|
||||
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
|
||||
}
|
||||
this.continueExistingPeriodicTasksAfterShutdownPolicy = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set whether to execute existing delayed tasks even when this executor has been shutdown.
|
||||
* <p>Default is {@code true}. If set to {@code false}, the target executor will be
|
||||
* switched into dropping remaining tasks (if possible).
|
||||
* <p><b>This setting can be modified at runtime, for example through JMX.</b>
|
||||
* @since 5.3.9
|
||||
* @see ScheduledThreadPoolExecutor#setExecuteExistingDelayedTasksAfterShutdownPolicy
|
||||
*/
|
||||
public void setExecuteExistingDelayedTasksAfterShutdownPolicy(boolean flag) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setExecuteExistingDelayedTasksAfterShutdownPolicy(flag);
|
||||
}
|
||||
this.executeExistingDelayedTasksAfterShutdownPolicy = flag;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -169,16 +135,12 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
|
||||
this.scheduledExecutor = createExecutor(this.poolSize, threadFactory, rejectedExecutionHandler);
|
||||
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
ScheduledThreadPoolExecutor scheduledPoolExecutor = (ScheduledThreadPoolExecutor) this.scheduledExecutor;
|
||||
if (this.removeOnCancelPolicy) {
|
||||
scheduledPoolExecutor.setRemoveOnCancelPolicy(true);
|
||||
if (this.removeOnCancelPolicy) {
|
||||
if (this.scheduledExecutor instanceof ScheduledThreadPoolExecutor) {
|
||||
((ScheduledThreadPoolExecutor) this.scheduledExecutor).setRemoveOnCancelPolicy(true);
|
||||
}
|
||||
if (this.continueExistingPeriodicTasksAfterShutdownPolicy) {
|
||||
scheduledPoolExecutor.setContinueExistingPeriodicTasksAfterShutdownPolicy(true);
|
||||
}
|
||||
if (!this.executeExistingDelayedTasksAfterShutdownPolicy) {
|
||||
scheduledPoolExecutor.setExecuteExistingDelayedTasksAfterShutdownPolicy(false);
|
||||
else {
|
||||
logger.debug("Could not apply remove-on-cancel policy - not a ScheduledThreadPoolExecutor");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -239,6 +201,18 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
return getScheduledThreadPoolExecutor().getPoolSize();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current setting for the remove-on-cancel mode.
|
||||
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
|
||||
*/
|
||||
public boolean isRemoveOnCancelPolicy() {
|
||||
if (this.scheduledExecutor == null) {
|
||||
// Not initialized yet: return our setting for the time being.
|
||||
return this.removeOnCancelPolicy;
|
||||
}
|
||||
return getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of currently active threads.
|
||||
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
|
||||
@@ -253,21 +227,6 @@ public class ThreadPoolTaskScheduler extends ExecutorConfigurationSupport
|
||||
return getScheduledThreadPoolExecutor().getActiveCount();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current setting for the remove-on-cancel mode.
|
||||
* <p>Requires an underlying {@link ScheduledThreadPoolExecutor}.
|
||||
* @deprecated as of 5.3.9, in favor of direct
|
||||
* {@link #getScheduledThreadPoolExecutor()} access
|
||||
*/
|
||||
@Deprecated
|
||||
public boolean isRemoveOnCancelPolicy() {
|
||||
if (this.scheduledExecutor == null) {
|
||||
// Not initialized yet: return our setting for the time being.
|
||||
return this.removeOnCancelPolicy;
|
||||
}
|
||||
return getScheduledThreadPoolExecutor().getRemoveOnCancelPolicy();
|
||||
}
|
||||
|
||||
|
||||
// SchedulingTaskExecutor implementation
|
||||
|
||||
|
||||
+1
-2
@@ -66,9 +66,8 @@ public final class CronExpression {
|
||||
CronField daysOfWeek,
|
||||
String expression) {
|
||||
|
||||
// reverse order, to make big changes first
|
||||
// to make sure we end up at 0 nanos, we add an extra field
|
||||
this.fields = new CronField[]{daysOfWeek, months, daysOfMonth, hours, minutes, seconds, CronField.zeroNanos()};
|
||||
this.fields = new CronField[]{CronField.zeroNanos(), seconds, minutes, hours, daysOfMonth, months, daysOfWeek};
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
|
||||
@@ -230,7 +230,9 @@ abstract class CronField {
|
||||
* Elapse the given temporal for the difference between the current
|
||||
* value of this field and the goal value. Typically, the returned
|
||||
* temporal will have the given goal as the current value for this type,
|
||||
* but this is not the case for {@link #DAY_OF_MONTH}.
|
||||
* but this is not the case for {@link #DAY_OF_MONTH}. For instance,
|
||||
* if {@code goal} is 31, and {@code temporal} is April 16th,
|
||||
* this method returns May 1st, because April 31st does not exist.
|
||||
* @param temporal the temporal to elapse
|
||||
* @param goal the goal value
|
||||
* @param <T> the type of temporal
|
||||
@@ -245,9 +247,8 @@ abstract class CronField {
|
||||
return cast(temporal.with(this.field, goal));
|
||||
}
|
||||
else {
|
||||
// goal is invalid, eg. 29th Feb, so roll forward
|
||||
long amount = range.getMaximum() - current + 1;
|
||||
return this.field.getBaseUnit().addTo(temporal, amount);
|
||||
// goal is invalid, eg. 29th Feb, lets try to get as close as possible
|
||||
return this.field.getBaseUnit().addTo(temporal, goal - current);
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
-3
@@ -334,9 +334,6 @@ final class QuartzCronField extends CronField {
|
||||
// We ended up before the start, roll forward and try again
|
||||
temporal = this.rollForwardType.rollForward(temporal);
|
||||
result = adjust(temporal);
|
||||
if (result != null) {
|
||||
result = type().reset(result);
|
||||
}
|
||||
}
|
||||
}
|
||||
return result;
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -1110,7 +1110,7 @@ open class BeanDefinitionDsl internal constructor (private val init: BeanDefinit
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
|
||||
* Return an provider for the specified bean, allowing for lazy on-demand retrieval
|
||||
* of instances, including availability and uniqueness options.
|
||||
* @see org.springframework.beans.factory.BeanFactory.getBeanProvider
|
||||
*/
|
||||
|
||||
@@ -162,13 +162,13 @@ class ProceedTestingAspect implements Ordered {
|
||||
|
||||
public Object doubleOrQuits(ProceedingJoinPoint pjp) throws Throwable {
|
||||
int value = ((Integer) pjp.getArgs()[0]).intValue();
|
||||
pjp.getArgs()[0] = Integer.valueOf(value * 2);
|
||||
pjp.getArgs()[0] = new Integer(value * 2);
|
||||
return pjp.proceed();
|
||||
}
|
||||
|
||||
public Object addOne(ProceedingJoinPoint pjp, Float value) throws Throwable {
|
||||
float fv = value.floatValue();
|
||||
return pjp.proceed(new Object[] {Float.valueOf(fv + 1.0F)});
|
||||
return pjp.proceed(new Object[] {new Float(fv + 1.0F)});
|
||||
}
|
||||
|
||||
public void captureStringArgument(JoinPoint tjp, String arg) {
|
||||
|
||||
+7
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -20,6 +20,8 @@ import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.aspectj.lang.JoinPoint;
|
||||
import org.aspectj.lang.ProceedingJoinPoint;
|
||||
import org.aspectj.lang.annotation.Around;
|
||||
@@ -38,6 +40,7 @@ import org.springframework.aop.support.StaticMethodMatcherPointcutAdvisor;
|
||||
import org.springframework.beans.PropertyValue;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.config.MethodInvokingFactoryBean;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.ITestBean;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
@@ -63,6 +66,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
public class AspectJAutoProxyCreatorTests {
|
||||
|
||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||
|
||||
|
||||
@Test
|
||||
public void testAspectsAreApplied() {
|
||||
ClassPathXmlApplicationContext bf = newContext("aspects.xml");
|
||||
|
||||
+5
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -28,7 +28,6 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.DefaultIntroductionAdvisor;
|
||||
import org.springframework.aop.target.SingletonTargetSource;
|
||||
import org.springframework.beans.MutablePropertyValues;
|
||||
import org.springframework.beans.factory.BeanFactory;
|
||||
@@ -220,7 +219,7 @@ public class AutoProxyCreatorTests {
|
||||
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.add("proxyFactoryBean", "false");
|
||||
sac.registerSingleton("testAutoProxyCreator", IntroductionTestAutoProxyCreator.class, pvs);
|
||||
sac.registerSingleton("testAutoProxyCreator", TestAutoProxyCreator.class, pvs);
|
||||
|
||||
sac.registerSingleton("noInterfaces", NoInterfaces.class);
|
||||
sac.registerSingleton("containerCallbackInterfacesOnly", ContainerCallbackInterfacesOnly.class);
|
||||
@@ -249,9 +248,9 @@ public class AutoProxyCreatorTests {
|
||||
singletonNoInterceptor.getName();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(0);
|
||||
singletonToBeProxied.getAge();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(1);
|
||||
prototypeToBeProxied.getSpouse();
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(4);
|
||||
assertThat(tapc.testInterceptor.nrOfInvocations).isEqualTo(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -405,7 +404,7 @@ public class AutoProxyCreatorTests {
|
||||
else if (name.endsWith("ToBeProxied")) {
|
||||
boolean isFactoryBean = FactoryBean.class.isAssignableFrom(beanClass);
|
||||
if ((this.proxyFactoryBean && isFactoryBean) || (this.proxyObject && !isFactoryBean)) {
|
||||
return getAdvicesAndAdvisors();
|
||||
return new Object[] {this.testInterceptor};
|
||||
}
|
||||
else {
|
||||
return DO_NOT_PROXY;
|
||||
@@ -415,10 +414,6 @@ public class AutoProxyCreatorTests {
|
||||
return PROXY_WITHOUT_ADDITIONAL_INTERCEPTORS;
|
||||
}
|
||||
}
|
||||
|
||||
protected Object[] getAdvicesAndAdvisors() {
|
||||
return new Object[] {this.testInterceptor};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -431,17 +426,6 @@ public class AutoProxyCreatorTests {
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
public static class IntroductionTestAutoProxyCreator extends TestAutoProxyCreator {
|
||||
|
||||
protected Object[] getAdvicesAndAdvisors() {
|
||||
DefaultIntroductionAdvisor advisor = new DefaultIntroductionAdvisor(this.testInterceptor);
|
||||
advisor.addInterface(Serializable.class);
|
||||
return new Object[] {this.testInterceptor, advisor};
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Interceptor that counts the number of non-finalize method calls.
|
||||
*/
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -47,9 +47,8 @@ import static org.springframework.util.ClassUtils.convertClassNameToResourcePath
|
||||
public class QualifierAnnotationTests {
|
||||
|
||||
private static final String CLASSNAME = QualifierAnnotationTests.class.getName();
|
||||
|
||||
private static final String CONFIG_LOCATION =
|
||||
format("classpath:%s-context.xml", convertClassNameToResourcePath(CLASSNAME));
|
||||
format("classpath:%s-context.xml", convertClassNameToResourcePath(CLASSNAME));
|
||||
|
||||
|
||||
@Test
|
||||
|
||||
+1
-1
@@ -146,7 +146,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(emmasJenks != georgiasJenks).as("Emma and georgia think they have a different boyfriend").isTrue();
|
||||
assertThat(emmasJenks.getName().equals("Andrew")).as("Emmas jenks has right name").isTrue();
|
||||
assertThat(emmasJenks != xbf.getBean("jenks")).as("Emmas doesn't equal new ref").isTrue();
|
||||
assertThat(georgiasJenks.getName().equals("Andrew")).as("Georgias jenks has right name").isTrue();
|
||||
assertThat(emmasJenks.getName().equals("Andrew")).as("Georgias jenks has right name").isTrue();
|
||||
assertThat(emmasJenks.equals(georgiasJenks)).as("They are object equal").isTrue();
|
||||
assertThat(emmasJenks.equals(xbf.getBean("jenks"))).as("They object equal direct ref").isTrue();
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -29,7 +29,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Tests regarding overloading and overriding of bean methods.
|
||||
* <p>Related to SPR-6618.
|
||||
* Related to SPR-6618.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Phillip Webb
|
||||
@@ -41,7 +41,7 @@ public class BeanMethodPolymorphismTests {
|
||||
@Test
|
||||
public void beanMethodDetectedOnSuperClass() {
|
||||
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
assertThat(ctx.getBean("testBean", TestBean.class)).isNotNull();
|
||||
ctx.getBean("testBean", TestBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
-202
@@ -1,202 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2021 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.parsing.FailFastProblemReporter;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
import org.springframework.core.io.DefaultResourceLoader;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link ConfigurationClassParser}, {@link ConfigurationClass},
|
||||
* and {@link BeanMethod}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 5.3.9
|
||||
*/
|
||||
class ConfigurationClassAndBeanMethodTests {
|
||||
|
||||
@Test
|
||||
void verifyEquals() throws Exception {
|
||||
ConfigurationClass configurationClass1 = newConfigurationClass(Config1.class);
|
||||
ConfigurationClass configurationClass2 = newConfigurationClass(Config1.class);
|
||||
ConfigurationClass configurationClass3 = newConfigurationClass(Config2.class);
|
||||
|
||||
assertThat(configurationClass1.equals(null)).isFalse();
|
||||
assertThat(configurationClass1).isNotSameAs(configurationClass2);
|
||||
|
||||
assertThat(configurationClass1.equals(configurationClass1)).isTrue();
|
||||
assertThat(configurationClass2.equals(configurationClass2)).isTrue();
|
||||
assertThat(configurationClass1.equals(configurationClass2)).isTrue();
|
||||
assertThat(configurationClass2.equals(configurationClass1)).isTrue();
|
||||
|
||||
assertThat(configurationClass1.equals(configurationClass3)).isFalse();
|
||||
assertThat(configurationClass3.equals(configurationClass2)).isFalse();
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
List<BeanMethod> beanMethods1 = getBeanMethods(configurationClass1);
|
||||
BeanMethod beanMethod_1_0 = beanMethods1.get(0);
|
||||
BeanMethod beanMethod_1_1 = beanMethods1.get(1);
|
||||
BeanMethod beanMethod_1_2 = beanMethods1.get(2);
|
||||
|
||||
List<BeanMethod> beanMethods2 = getBeanMethods(configurationClass2);
|
||||
BeanMethod beanMethod_2_0 = beanMethods2.get(0);
|
||||
BeanMethod beanMethod_2_1 = beanMethods2.get(1);
|
||||
BeanMethod beanMethod_2_2 = beanMethods2.get(2);
|
||||
|
||||
List<BeanMethod> beanMethods3 = getBeanMethods(configurationClass3);
|
||||
BeanMethod beanMethod_3_0 = beanMethods3.get(0);
|
||||
BeanMethod beanMethod_3_1 = beanMethods3.get(1);
|
||||
BeanMethod beanMethod_3_2 = beanMethods3.get(2);
|
||||
|
||||
assertThat(beanMethod_1_0.equals(null)).isFalse();
|
||||
assertThat(beanMethod_1_0).isNotSameAs(beanMethod_2_0);
|
||||
|
||||
assertThat(beanMethod_1_0.equals(beanMethod_1_0)).isTrue();
|
||||
assertThat(beanMethod_1_0.equals(beanMethod_2_0)).isTrue();
|
||||
assertThat(beanMethod_1_1.equals(beanMethod_2_1)).isTrue();
|
||||
assertThat(beanMethod_1_2.equals(beanMethod_2_2)).isTrue();
|
||||
|
||||
assertThat(beanMethod_1_0.getMetadata().getMethodName()).isEqualTo(beanMethod_3_0.getMetadata().getMethodName());
|
||||
assertThat(beanMethod_1_0.equals(beanMethod_3_0)).isFalse();
|
||||
assertThat(beanMethod_1_1.equals(beanMethod_3_1)).isFalse();
|
||||
assertThat(beanMethod_1_2.equals(beanMethod_3_2)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyHashCode() throws Exception {
|
||||
ConfigurationClass configurationClass1 = newConfigurationClass(Config1.class);
|
||||
ConfigurationClass configurationClass2 = newConfigurationClass(Config1.class);
|
||||
ConfigurationClass configurationClass3 = newConfigurationClass(Config2.class);
|
||||
|
||||
assertThat(configurationClass1).hasSameHashCodeAs(configurationClass2);
|
||||
assertThat(configurationClass1).doesNotHaveSameHashCodeAs(configurationClass3);
|
||||
|
||||
// ---------------------------------------------------------------------
|
||||
|
||||
List<BeanMethod> beanMethods1 = getBeanMethods(configurationClass1);
|
||||
BeanMethod beanMethod_1_0 = beanMethods1.get(0);
|
||||
BeanMethod beanMethod_1_1 = beanMethods1.get(1);
|
||||
BeanMethod beanMethod_1_2 = beanMethods1.get(2);
|
||||
|
||||
List<BeanMethod> beanMethods2 = getBeanMethods(configurationClass2);
|
||||
BeanMethod beanMethod_2_0 = beanMethods2.get(0);
|
||||
BeanMethod beanMethod_2_1 = beanMethods2.get(1);
|
||||
BeanMethod beanMethod_2_2 = beanMethods2.get(2);
|
||||
|
||||
List<BeanMethod> beanMethods3 = getBeanMethods(configurationClass3);
|
||||
BeanMethod beanMethod_3_0 = beanMethods3.get(0);
|
||||
BeanMethod beanMethod_3_1 = beanMethods3.get(1);
|
||||
BeanMethod beanMethod_3_2 = beanMethods3.get(2);
|
||||
|
||||
assertThat(beanMethod_1_0).hasSameHashCodeAs(beanMethod_2_0);
|
||||
assertThat(beanMethod_1_1).hasSameHashCodeAs(beanMethod_2_1);
|
||||
assertThat(beanMethod_1_2).hasSameHashCodeAs(beanMethod_2_2);
|
||||
|
||||
assertThat(beanMethod_1_0).doesNotHaveSameHashCodeAs(beanMethod_3_0);
|
||||
assertThat(beanMethod_1_1).doesNotHaveSameHashCodeAs(beanMethod_3_1);
|
||||
assertThat(beanMethod_1_2).doesNotHaveSameHashCodeAs(beanMethod_3_2);
|
||||
}
|
||||
|
||||
@Test
|
||||
void verifyToString() throws Exception {
|
||||
ConfigurationClass configurationClass = newConfigurationClass(Config1.class);
|
||||
assertThat(configurationClass.toString())
|
||||
.startsWith("ConfigurationClass: beanName 'Config1', class path resource");
|
||||
|
||||
List<BeanMethod> beanMethods = getBeanMethods(configurationClass);
|
||||
String prefix = "BeanMethod: " + Config1.class.getName();
|
||||
assertThat(beanMethods.get(0).toString()).isEqualTo(prefix + ".bean0()");
|
||||
assertThat(beanMethods.get(1).toString()).isEqualTo(prefix + ".bean1(java.lang.String)");
|
||||
assertThat(beanMethods.get(2).toString()).isEqualTo(prefix + ".bean2(java.lang.String,java.lang.Integer)");
|
||||
}
|
||||
|
||||
|
||||
private static ConfigurationClass newConfigurationClass(Class<?> clazz) throws Exception {
|
||||
ConfigurationClassParser parser = newParser();
|
||||
parser.parse(clazz.getName(), clazz.getSimpleName());
|
||||
assertThat(parser.getConfigurationClasses()).hasSize(1);
|
||||
return parser.getConfigurationClasses().iterator().next();
|
||||
}
|
||||
|
||||
private static ConfigurationClassParser newParser() {
|
||||
return new ConfigurationClassParser(
|
||||
new CachingMetadataReaderFactory(),
|
||||
new FailFastProblemReporter(),
|
||||
new StandardEnvironment(),
|
||||
new DefaultResourceLoader(),
|
||||
new AnnotationBeanNameGenerator(),
|
||||
new DefaultListableBeanFactory());
|
||||
}
|
||||
|
||||
private static List<BeanMethod> getBeanMethods(ConfigurationClass configurationClass) {
|
||||
List<BeanMethod> beanMethods = configurationClass.getBeanMethods().stream()
|
||||
.sorted(Comparator.comparing(beanMethod -> beanMethod.getMetadata().getMethodName()))
|
||||
.collect(Collectors.toList());
|
||||
assertThat(beanMethods).hasSize(3);
|
||||
return beanMethods;
|
||||
}
|
||||
|
||||
static class Config1 {
|
||||
|
||||
@Bean
|
||||
String bean0() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String bean1(String text) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String bean2(String text, Integer num) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static class Config2 {
|
||||
|
||||
@Bean
|
||||
String bean0() {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String bean1(String text) {
|
||||
return "";
|
||||
}
|
||||
|
||||
@Bean
|
||||
String bean2(String text, Integer num) {
|
||||
return "";
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
+38
-38
@@ -79,7 +79,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
* @author Stephane Nicoll
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class AnnotationDrivenEventListenerTests {
|
||||
public class AnnotationDrivenEventListenerTests {
|
||||
|
||||
private ConfigurableApplicationContext context;
|
||||
|
||||
@@ -97,7 +97,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
|
||||
|
||||
@Test
|
||||
void simpleEventJavaConfig() {
|
||||
public void simpleEventJavaConfig() {
|
||||
load(TestEventListener.class);
|
||||
TestEvent event = new TestEvent(this, "test");
|
||||
TestEventListener listener = this.context.getBean(TestEventListener.class);
|
||||
@@ -120,7 +120,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void simpleEventXmlConfig() {
|
||||
public void simpleEventXmlConfig() {
|
||||
this.context = new ClassPathXmlApplicationContext(
|
||||
"org/springframework/context/event/simple-event-configuration.xml");
|
||||
|
||||
@@ -141,7 +141,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void metaAnnotationIsDiscovered() {
|
||||
public void metaAnnotationIsDiscovered() {
|
||||
load(MetaAnnotationListenerTestBean.class);
|
||||
MetaAnnotationListenerTestBean bean = this.context.getBean(MetaAnnotationListenerTestBean.class);
|
||||
this.eventCollector.assertNoEventReceived(bean);
|
||||
@@ -159,7 +159,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void contextEventsAreReceived() {
|
||||
public void contextEventsAreReceived() {
|
||||
load(ContextEventListener.class);
|
||||
ContextEventListener listener = this.context.getBean(ContextEventListener.class);
|
||||
|
||||
@@ -175,7 +175,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void methodSignatureNoEvent() {
|
||||
public void methodSignatureNoEvent() {
|
||||
@SuppressWarnings("resource")
|
||||
AnnotationConfigApplicationContext failingContext =
|
||||
new AnnotationConfigApplicationContext();
|
||||
@@ -189,7 +189,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void simpleReply() {
|
||||
public void simpleReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, "dummy");
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -204,7 +204,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nullReplyIgnored() {
|
||||
public void nullReplyIgnored() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, null); // No response
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -219,7 +219,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void arrayReply() {
|
||||
public void arrayReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, new String[]{"first", "second"});
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -234,7 +234,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectionReply() {
|
||||
public void collectionReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
Set<Object> replies = new LinkedHashSet<>();
|
||||
replies.add("first");
|
||||
@@ -253,7 +253,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void collectionReplyNullValue() {
|
||||
public void collectionReplyNullValue() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, Arrays.asList(null, "test"));
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -268,7 +268,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenableFutureReply() {
|
||||
public void listenableFutureReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
SettableListenableFuture<String> future = new SettableListenableFuture<>();
|
||||
future.set("dummy");
|
||||
@@ -285,7 +285,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void completableFutureReply() {
|
||||
public void completableFutureReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, CompletableFuture.completedFuture("dummy"));
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -300,7 +300,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void monoReply() {
|
||||
public void monoReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, Mono.just("dummy"));
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -315,7 +315,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void fluxReply() {
|
||||
public void fluxReply() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, Flux.just("dummy1", "dummy2"));
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -330,7 +330,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventListenerWorksWithSimpleInterfaceProxy() {
|
||||
public void eventListenerWorksWithSimpleInterfaceProxy() {
|
||||
load(ScopedProxyTestBean.class);
|
||||
|
||||
SimpleService proxy = this.context.getBean(SimpleService.class);
|
||||
@@ -347,7 +347,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventListenerWorksWithAnnotatedInterfaceProxy() {
|
||||
public void eventListenerWorksWithAnnotatedInterfaceProxy() {
|
||||
load(AnnotatedProxyTestBean.class);
|
||||
|
||||
AnnotatedSimpleService proxy = this.context.getBean(AnnotatedSimpleService.class);
|
||||
@@ -364,7 +364,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventListenerWorksWithCglibProxy() {
|
||||
public void eventListenerWorksWithCglibProxy() {
|
||||
load(CglibProxyTestBean.class);
|
||||
|
||||
CglibProxyTestBean proxy = this.context.getBean(CglibProxyTestBean.class);
|
||||
@@ -381,14 +381,14 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void privateMethodOnCglibProxyFails() {
|
||||
public void privateMethodOnCglibProxyFails() {
|
||||
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(() ->
|
||||
load(CglibProxyWithPrivateMethod.class))
|
||||
.withCauseInstanceOf(IllegalStateException.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void eventListenerWorksWithCustomScope() {
|
||||
public void eventListenerWorksWithCustomScope() {
|
||||
load(CustomScopeTestBean.class);
|
||||
CustomScope customScope = new CustomScope();
|
||||
this.context.getBeanFactory().registerScope("custom", customScope);
|
||||
@@ -417,7 +417,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void asyncProcessingApplied() throws InterruptedException {
|
||||
public void asyncProcessingApplied() throws InterruptedException {
|
||||
loadAsync(AsyncEventListener.class);
|
||||
|
||||
String threadName = Thread.currentThread().getName();
|
||||
@@ -432,7 +432,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
|
||||
public void asyncProcessingAppliedWithInterfaceProxy() throws InterruptedException {
|
||||
doLoad(AsyncConfigurationWithInterfaces.class, SimpleProxyTestBean.class);
|
||||
|
||||
String threadName = Thread.currentThread().getName();
|
||||
@@ -447,7 +447,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
|
||||
public void asyncProcessingAppliedWithScopedProxy() throws InterruptedException {
|
||||
doLoad(AsyncConfigurationWithInterfaces.class, ScopedProxyTestBean.class);
|
||||
|
||||
String threadName = Thread.currentThread().getName();
|
||||
@@ -462,7 +462,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void exceptionPropagated() {
|
||||
public void exceptionPropagated() {
|
||||
load(ExceptionEventListener.class);
|
||||
TestEvent event = new TestEvent(this, "fail");
|
||||
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
|
||||
@@ -475,7 +475,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void exceptionNotPropagatedWithAsync() throws InterruptedException {
|
||||
public void exceptionNotPropagatedWithAsync() throws InterruptedException {
|
||||
loadAsync(ExceptionEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, "fail");
|
||||
ExceptionEventListener listener = this.context.getBean(ExceptionEventListener.class);
|
||||
@@ -489,7 +489,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithSimplePayload() {
|
||||
public void listenerWithSimplePayload() {
|
||||
load(TestEventListener.class);
|
||||
TestEventListener listener = this.context.getBean(TestEventListener.class);
|
||||
|
||||
@@ -500,7 +500,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithNonMatchingPayload() {
|
||||
public void listenerWithNonMatchingPayload() {
|
||||
load(TestEventListener.class);
|
||||
TestEventListener listener = this.context.getBean(TestEventListener.class);
|
||||
|
||||
@@ -511,7 +511,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void replyWithPayload() {
|
||||
public void replyWithPayload() {
|
||||
load(TestEventListener.class, ReplyEventListener.class);
|
||||
AnotherTestEvent event = new AnotherTestEvent(this, "String");
|
||||
ReplyEventListener replyEventListener = this.context.getBean(ReplyEventListener.class);
|
||||
@@ -527,7 +527,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithGenericApplicationEvent() {
|
||||
public void listenerWithGenericApplicationEvent() {
|
||||
load(GenericEventListener.class);
|
||||
GenericEventListener listener = this.context.getBean(GenericEventListener.class);
|
||||
|
||||
@@ -538,7 +538,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithResolvableTypeEvent() {
|
||||
public void listenerWithResolvableTypeEvent() {
|
||||
load(ResolvableTypeEventListener.class);
|
||||
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
|
||||
|
||||
@@ -550,7 +550,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void listenerWithResolvableTypeEventWrongGeneric() {
|
||||
public void listenerWithResolvableTypeEventWrongGeneric() {
|
||||
load(ResolvableTypeEventListener.class);
|
||||
ResolvableTypeEventListener listener = this.context.getBean(ResolvableTypeEventListener.class);
|
||||
|
||||
@@ -562,12 +562,12 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void conditionMatch() {
|
||||
public void conditionMatch() {
|
||||
validateConditionMatch(ConditionalEventListener.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
void conditionMatchWithProxy() {
|
||||
public void conditionMatchWithProxy() {
|
||||
validateConditionMatch(ConditionalEventListener.class, MethodValidationPostProcessor.class);
|
||||
}
|
||||
|
||||
@@ -600,7 +600,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void conditionDoesNotMatch() {
|
||||
public void conditionDoesNotMatch() {
|
||||
long maxLong = Long.MAX_VALUE;
|
||||
load(ConditionalEventListener.class);
|
||||
TestEvent event = new TestEvent(this, "KO");
|
||||
@@ -625,7 +625,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void orderedListeners() {
|
||||
public void orderedListeners() {
|
||||
load(OrderedTestListener.class);
|
||||
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
|
||||
|
||||
@@ -635,7 +635,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test @Disabled // SPR-15122
|
||||
void listenersReceiveEarlyEvents() {
|
||||
public void listenersReceiveEarlyEvents() {
|
||||
load(EventOnPostConstruct.class, OrderedTestListener.class);
|
||||
OrderedTestListener listener = this.context.getBean(OrderedTestListener.class);
|
||||
|
||||
@@ -643,7 +643,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void missingListenerBeanIgnored() {
|
||||
public void missingListenerBeanIgnored() {
|
||||
load(MissingEventListener.class);
|
||||
context.getBean(UseMissingEventListener.class);
|
||||
context.getBean(ApplicationEventMulticaster.class).multicastEvent(new TestEvent(this));
|
||||
@@ -697,7 +697,7 @@ class AnnotationDrivenEventListenerTests {
|
||||
static class TestConditionEvaluator {
|
||||
|
||||
public boolean valid(Double ratio) {
|
||||
return Double.valueOf(42).equals(ratio);
|
||||
return new Double(42).equals(ratio);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+7
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -28,6 +28,8 @@ import java.security.Permission;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.ObjectFactory;
|
||||
@@ -38,6 +40,7 @@ import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.beans.factory.config.Scope;
|
||||
import org.springframework.beans.factory.config.TypedStringValue;
|
||||
import org.springframework.beans.factory.support.AutowireCandidateQualifier;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.support.GenericBeanDefinition;
|
||||
import org.springframework.beans.factory.support.RootBeanDefinition;
|
||||
import org.springframework.beans.testfixture.beans.TestBean;
|
||||
@@ -61,6 +64,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
*/
|
||||
class ApplicationContextExpressionTests {
|
||||
|
||||
private static final Log factoryLog = LogFactory.getLog(DefaultListableBeanFactory.class);
|
||||
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void genericApplicationContext() throws Exception {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -341,10 +341,10 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
|
||||
assertIsRegistered("Bean instance not registered", objectName);
|
||||
|
||||
Object result = server.invoke(objectName, "add", new Object[] {2, 3}, new String[] {
|
||||
Object result = server.invoke(objectName, "add", new Object[] {new Integer(2), new Integer(3)}, new String[] {
|
||||
int.class.getName(), int.class.getName()});
|
||||
|
||||
assertThat(Integer.valueOf(5)).as("Incorrect result return from add").isEqualTo(result);
|
||||
assertThat(new Integer(5)).as("Incorrect result return from add").isEqualTo(result);
|
||||
assertThat(server.getAttribute(objectName, "Name")).as("Incorrect attribute value").isEqualTo(name);
|
||||
|
||||
server.setAttribute(objectName, new Attribute("Name", otherName));
|
||||
@@ -352,7 +352,7 @@ public class MBeanExporterTests extends AbstractMBeanServerTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() {
|
||||
void testBonaFideMBeanIsNotExportedWhenAutodetectIsTotallyTurnedOff() throws Exception {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(Person.class);
|
||||
DefaultListableBeanFactory factory = new DefaultListableBeanFactory();
|
||||
factory.registerBeanDefinition("^&_invalidObjectName_(*", builder.getBeanDefinition());
|
||||
|
||||
+11
-11
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -60,7 +60,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
IJmxTestBean bean = getBean();
|
||||
assertThat(bean).isNotNull();
|
||||
MBeanInfo inf = getMBeanInfo();
|
||||
assertThat(inf.getOperations()).as("Incorrect number of operations registered").hasSize(getExpectedOperationCount());
|
||||
assertThat(inf.getOperations().length).as("Incorrect number of operations registered").isEqualTo(getExpectedOperationCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
IJmxTestBean bean = getBean();
|
||||
assertThat(bean).isNotNull();
|
||||
MBeanInfo inf = getMBeanInfo();
|
||||
assertThat(inf.getAttributes()).as("Incorrect number of attributes registered").hasSize(getExpectedAttributeCount());
|
||||
assertThat(inf.getAttributes().length).as("Incorrect number of attributes registered").isEqualTo(getExpectedAttributeCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,7 +81,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
public void testGetMBeanAttributeInfo() throws Exception {
|
||||
ModelMBeanInfo info = getMBeanInfoFromAssembler();
|
||||
MBeanAttributeInfo[] inf = info.getAttributes();
|
||||
assertThat(inf).as("Invalid number of Attributes returned").hasSize(getExpectedAttributeCount());
|
||||
assertThat(inf.length).as("Invalid number of Attributes returned").isEqualTo(getExpectedAttributeCount());
|
||||
|
||||
for (int x = 0; x < inf.length; x++) {
|
||||
assertThat(inf[x]).as("MBeanAttributeInfo should not be null").isNotNull();
|
||||
@@ -93,7 +93,7 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
public void testGetMBeanOperationInfo() throws Exception {
|
||||
ModelMBeanInfo info = getMBeanInfoFromAssembler();
|
||||
MBeanOperationInfo[] inf = info.getOperations();
|
||||
assertThat(inf).as("Invalid number of Operations returned").hasSize(getExpectedOperationCount());
|
||||
assertThat(inf.length).as("Invalid number of Operations returned").isEqualTo(getExpectedOperationCount());
|
||||
|
||||
for (int x = 0; x < inf.length; x++) {
|
||||
assertThat(inf[x]).as("MBeanOperationInfo should not be null").isNotNull();
|
||||
@@ -128,8 +128,8 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
public void testOperationInvocation() throws Exception{
|
||||
ObjectName objectName = ObjectNameManager.getInstance(getObjectName());
|
||||
Object result = getServer().invoke(objectName, "add",
|
||||
new Object[] {20, 30}, new String[] {"int", "int"});
|
||||
assertThat(result).as("Incorrect result").isEqualTo(50);
|
||||
new Object[] {new Integer(20), new Integer(30)}, new String[] {"int", "int"});
|
||||
assertThat(result).as("Incorrect result").isEqualTo(new Integer(50));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -150,12 +150,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
|
||||
ModelMBeanOperationInfo get = info.getOperation("getName");
|
||||
assertThat(get).as("get operation should not be null").isNotNull();
|
||||
assertThat(Integer.valueOf(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
|
||||
assertThat(new Integer(4)).as("get operation should have visibility of four").isEqualTo(get.getDescriptor().getFieldValue("visibility"));
|
||||
assertThat(get.getDescriptor().getFieldValue("role")).as("get operation should have role \"getter\"").isEqualTo("getter");
|
||||
|
||||
ModelMBeanOperationInfo set = info.getOperation("setName");
|
||||
assertThat(set).as("set operation should not be null").isNotNull();
|
||||
assertThat(Integer.valueOf(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
|
||||
assertThat(new Integer(4)).as("set operation should have visibility of four").isEqualTo(set.getDescriptor().getFieldValue("visibility"));
|
||||
assertThat(set.getDescriptor().getFieldValue("role")).as("set operation should have role \"setter\"").isEqualTo("setter");
|
||||
}
|
||||
|
||||
@@ -163,12 +163,12 @@ public abstract class AbstractJmxAssemblerTests extends AbstractJmxTests {
|
||||
public void testNotificationMetadata() throws Exception {
|
||||
ModelMBeanInfo info = (ModelMBeanInfo) getMBeanInfo();
|
||||
MBeanNotificationInfo[] notifications = info.getNotifications();
|
||||
assertThat(notifications).as("Incorrect number of notifications").hasSize(1);
|
||||
assertThat(notifications.length).as("Incorrect number of notifications").isEqualTo(1);
|
||||
assertThat(notifications[0].getName()).as("Incorrect notification name").isEqualTo("My Notification");
|
||||
|
||||
String[] notifTypes = notifications[0].getNotifTypes();
|
||||
|
||||
assertThat(notifTypes).as("Incorrect number of notification types").hasSize(2);
|
||||
assertThat(notifTypes.length).as("Incorrect number of notification types").isEqualTo(2);
|
||||
assertThat(notifTypes[0]).as("Notification type.foo not found").isEqualTo("type.foo");
|
||||
assertThat(notifTypes[1]).as("Notification type.bar not found").isEqualTo("type.bar");
|
||||
}
|
||||
|
||||
+142
-246
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -29,16 +29,9 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ParameterContext;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.converter.ArgumentConversionException;
|
||||
import org.junit.jupiter.params.converter.ArgumentConverter;
|
||||
import org.junit.jupiter.params.converter.ConvertWith;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.aop.scope.ScopedProxyUtils;
|
||||
@@ -67,37 +60,29 @@ import org.springframework.validation.beanvalidation.MethodValidationPostProcess
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.SoftAssertions.assertSoftly;
|
||||
|
||||
/**
|
||||
* Tests for {@link ScheduledAnnotationBeanPostProcessor}.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
* @author Stevo Slavić
|
||||
* @author Victor Brown
|
||||
*/
|
||||
class ScheduledAnnotationBeanPostProcessorTests {
|
||||
public class ScheduledAnnotationBeanPostProcessorTests {
|
||||
|
||||
private final StaticApplicationContext context = new StaticApplicationContext();
|
||||
|
||||
|
||||
@AfterEach
|
||||
void closeContextAfterTest() {
|
||||
public void closeContextAfterTest() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"FixedDelay, 5000",
|
||||
"FixedDelayInSeconds, 5000",
|
||||
"FixedDelayInMinutes, 180000"
|
||||
})
|
||||
void fixedDelayTask(@NameToClass Class<?> beanClass, long expectedInterval) {
|
||||
|
||||
@Test
|
||||
public void fixedDelayTask() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(FixedDelayTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
@@ -111,7 +96,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedDelayTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedDelayTasks");
|
||||
assertThat(fixedDelayTasks).hasSize(1);
|
||||
assertThat(fixedDelayTasks.size()).isEqualTo(1);
|
||||
IntervalTask task = fixedDelayTasks.get(0);
|
||||
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
|
||||
Object targetObject = runnable.getTarget();
|
||||
@@ -119,109 +104,95 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedDelay");
|
||||
assertThat(task.getInitialDelay()).isEqualTo(0L);
|
||||
assertThat(task.getInterval()).isEqualTo(expectedInterval);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"FixedRate, 3000",
|
||||
"FixedRateInSeconds, 5000",
|
||||
"FixedRateInMinutes, 180000"
|
||||
})
|
||||
void fixedRateTask(@NameToClass Class<?> beanClass, long expectedInterval) {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
|
||||
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
|
||||
assertThat(postProcessor.getScheduledTasks().size()).isEqualTo(1);
|
||||
|
||||
Object target = context.getBean("target");
|
||||
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
|
||||
assertThat(fixedRateTasks.size()).isEqualTo(1);
|
||||
IntervalTask task = fixedRateTasks.get(0);
|
||||
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
|
||||
Object targetObject = runnable.getTarget();
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedRate");
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(task.getInitialDelay()).as("initial delay").isEqualTo(0);
|
||||
softly.assertThat(task.getInterval()).as("interval").isEqualTo(expectedInterval);
|
||||
});
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"FixedRateWithInitialDelay, 1000, 3000",
|
||||
"FixedRateWithInitialDelayInSeconds, 5000, 3000",
|
||||
"FixedRateWithInitialDelayInMinutes, 60000, 180000"
|
||||
})
|
||||
void fixedRateTaskWithInitialDelay(@NameToClass Class<?> beanClass, long expectedInitialDelay, long expectedInterval) {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
|
||||
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
|
||||
assertThat(postProcessor.getScheduledTasks().size()).isEqualTo(1);
|
||||
|
||||
Object target = context.getBean("target");
|
||||
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
|
||||
assertThat(fixedRateTasks.size()).isEqualTo(1);
|
||||
IntervalTask task = fixedRateTasks.get(0);
|
||||
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
|
||||
Object targetObject = runnable.getTarget();
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedRate");
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(task.getInitialDelay()).as("initial delay").isEqualTo(expectedInitialDelay);
|
||||
softly.assertThat(task.getInterval()).as("interval").isEqualTo(expectedInterval);
|
||||
});
|
||||
assertThat(task.getInterval()).isEqualTo(5000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalFixedRatesWithRepeatedScheduledAnnotation() {
|
||||
public void fixedRateTask() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(FixedRateTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
|
||||
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
|
||||
assertThat(postProcessor.getScheduledTasks().size()).isEqualTo(1);
|
||||
|
||||
Object target = context.getBean("target");
|
||||
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
|
||||
assertThat(fixedRateTasks.size()).isEqualTo(1);
|
||||
IntervalTask task = fixedRateTasks.get(0);
|
||||
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
|
||||
Object targetObject = runnable.getTarget();
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedRate");
|
||||
assertThat(task.getInitialDelay()).isEqualTo(0L);
|
||||
assertThat(task.getInterval()).isEqualTo(3000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void fixedRateTaskWithInitialDelay() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(FixedRateWithInitialDelayTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
context.refresh();
|
||||
|
||||
ScheduledTaskHolder postProcessor = context.getBean("postProcessor", ScheduledTaskHolder.class);
|
||||
assertThat(postProcessor.getScheduledTasks().size()).isEqualTo(1);
|
||||
|
||||
Object target = context.getBean("target");
|
||||
ScheduledTaskRegistrar registrar = (ScheduledTaskRegistrar)
|
||||
new DirectFieldAccessor(postProcessor).getPropertyValue("registrar");
|
||||
@SuppressWarnings("unchecked")
|
||||
List<IntervalTask> fixedRateTasks = (List<IntervalTask>)
|
||||
new DirectFieldAccessor(registrar).getPropertyValue("fixedRateTasks");
|
||||
assertThat(fixedRateTasks.size()).isEqualTo(1);
|
||||
IntervalTask task = fixedRateTasks.get(0);
|
||||
ScheduledMethodRunnable runnable = (ScheduledMethodRunnable) task.getRunnable();
|
||||
Object targetObject = runnable.getTarget();
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedRate");
|
||||
assertThat(task.getInitialDelay()).isEqualTo(1000L);
|
||||
assertThat(task.getInterval()).isEqualTo(3000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void severalFixedRatesWithRepeatedScheduledAnnotation() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class);
|
||||
severalFixedRates(context, processorDefinition, targetDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalFixedRatesWithSchedulesContainerAnnotation() {
|
||||
public void severalFixedRatesWithSchedulesContainerAnnotation() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithSchedulesContainerAnnotationTestBean.class);
|
||||
severalFixedRates(context, processorDefinition, targetDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalFixedRatesOnBaseClass() {
|
||||
public void severalFixedRatesOnBaseClass() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(FixedRatesSubBean.class);
|
||||
severalFixedRates(context, processorDefinition, targetDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalFixedRatesOnDefaultMethod() {
|
||||
public void severalFixedRatesOnDefaultMethod() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(FixedRatesDefaultBean.class);
|
||||
severalFixedRates(context, processorDefinition, targetDefinition);
|
||||
}
|
||||
|
||||
@Test
|
||||
void severalFixedRatesAgainstNestedCglibProxy() {
|
||||
public void severalFixedRatesAgainstNestedCglibProxy() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean.class);
|
||||
targetDefinition.setFactoryMethodName("nestedProxy");
|
||||
@@ -264,7 +235,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTask() {
|
||||
public void cronTask() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(CronTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -291,7 +262,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTaskWithZone() {
|
||||
public void cronTaskWithZone() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(CronWithTimezoneTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -337,7 +308,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTaskWithInvalidZone() {
|
||||
public void cronTaskWithInvalidZone() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(CronWithInvalidTimezoneTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -347,7 +318,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTaskWithMethodValidation() {
|
||||
public void cronTaskWithMethodValidation() {
|
||||
BeanDefinition validationDefinition = new RootBeanDefinition(MethodValidationPostProcessor.class);
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(CronTestBean.class);
|
||||
@@ -359,7 +330,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void cronTaskWithScopedProxy() {
|
||||
public void cronTaskWithScopedProxy() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
new AnnotatedBeanDefinitionReader(context).register(ProxiedCronTestBean.class, ProxiedCronTestBeanDependent.class);
|
||||
@@ -384,7 +355,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void metaAnnotationWithFixedRate() {
|
||||
public void metaAnnotationWithFixedRate() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(MetaAnnotationFixedRateTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -411,7 +382,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void composedAnnotationWithInitialDelayAndFixedRate() {
|
||||
public void composedAnnotationWithInitialDelayAndFixedRate() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(ComposedAnnotationFixedRateTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -439,7 +410,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void metaAnnotationWithCronExpression() {
|
||||
public void metaAnnotationWithCronExpression() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(MetaAnnotationCronTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -466,7 +437,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyPlaceholderWithCron() {
|
||||
public void propertyPlaceholderWithCron() {
|
||||
String businessHoursCronExpression = "0 0 9-17 * * MON-FRI";
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition placeholderDefinition = new RootBeanDefinition(PropertySourcesPlaceholderConfigurer.class);
|
||||
@@ -499,7 +470,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyPlaceholderWithInactiveCron() {
|
||||
public void propertyPlaceholderWithInactiveCron() {
|
||||
String businessHoursCronExpression = "-";
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition placeholderDefinition = new RootBeanDefinition(PropertySourcesPlaceholderConfigurer.class);
|
||||
@@ -516,23 +487,24 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
assertThat(postProcessor.getScheduledTasks().isEmpty()).isTrue();
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"PropertyPlaceholderWithFixedDelay, 5000, 1000, 5000, 1000",
|
||||
"PropertyPlaceholderWithFixedDelay, PT5S, PT1S, 5000, 1000",
|
||||
"PropertyPlaceholderWithFixedDelayInSeconds, 5000, 1000, 5000000, 1000000",
|
||||
"PropertyPlaceholderWithFixedDelayInSeconds, PT5S, PT1S, 5000, 1000"
|
||||
})
|
||||
void propertyPlaceholderWithFixedDelay(@NameToClass Class<?> beanClass, String fixedDelay, String initialDelay,
|
||||
long expectedInterval, long expectedInitialDelay) {
|
||||
@Test
|
||||
public void propertyPlaceholderWithFixedDelayInMillis() {
|
||||
propertyPlaceholderWithFixedDelay(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderWithFixedDelayInDuration() {
|
||||
propertyPlaceholderWithFixedDelay(true);
|
||||
}
|
||||
|
||||
private void propertyPlaceholderWithFixedDelay(boolean durationFormat) {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition placeholderDefinition = new RootBeanDefinition(PropertySourcesPlaceholderConfigurer.class);
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("fixedDelay", fixedDelay);
|
||||
properties.setProperty("initialDelay", initialDelay);
|
||||
properties.setProperty("fixedDelay", (durationFormat ? "PT5S" : "5000"));
|
||||
properties.setProperty("initialDelay", (durationFormat ? "PT1S" : "1000"));
|
||||
placeholderDefinition.getPropertyValues().addPropertyValue("properties", properties);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(PropertyPlaceholderWithFixedDelayTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("placeholder", placeholderDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
@@ -554,29 +526,28 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedDelay");
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(task.getInitialDelay()).as("initial delay").isEqualTo(expectedInitialDelay);
|
||||
softly.assertThat(task.getInterval()).as("interval").isEqualTo(expectedInterval);
|
||||
});
|
||||
assertThat(task.getInitialDelay()).isEqualTo(1000L);
|
||||
assertThat(task.getInterval()).isEqualTo(5000L);
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@CsvSource({
|
||||
"PropertyPlaceholderWithFixedRate, 3000, 1000, 3000, 1000",
|
||||
"PropertyPlaceholderWithFixedRate, PT3S, PT1S, 3000, 1000",
|
||||
"PropertyPlaceholderWithFixedRateInSeconds, 3000, 1000, 3000000, 1000000",
|
||||
"PropertyPlaceholderWithFixedRateInSeconds, PT3S, PT1S, 3000, 1000"
|
||||
})
|
||||
void propertyPlaceholderWithFixedRate(@NameToClass Class<?> beanClass, String fixedRate, String initialDelay,
|
||||
long expectedInterval, long expectedInitialDelay) {
|
||||
@Test
|
||||
public void propertyPlaceholderWithFixedRateInMillis() {
|
||||
propertyPlaceholderWithFixedRate(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void propertyPlaceholderWithFixedRateInDuration() {
|
||||
propertyPlaceholderWithFixedRate(true);
|
||||
}
|
||||
|
||||
private void propertyPlaceholderWithFixedRate(boolean durationFormat) {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition placeholderDefinition = new RootBeanDefinition(PropertySourcesPlaceholderConfigurer.class);
|
||||
Properties properties = new Properties();
|
||||
properties.setProperty("fixedRate", fixedRate);
|
||||
properties.setProperty("initialDelay", initialDelay);
|
||||
properties.setProperty("fixedRate", (durationFormat ? "PT3S" : "3000"));
|
||||
properties.setProperty("initialDelay", (durationFormat ? "PT1S" : "1000"));
|
||||
placeholderDefinition.getPropertyValues().addPropertyValue("properties", properties);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(beanClass);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(PropertyPlaceholderWithFixedRateTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
context.registerBeanDefinition("placeholder", placeholderDefinition);
|
||||
context.registerBeanDefinition("target", targetDefinition);
|
||||
@@ -598,14 +569,12 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
Method targetMethod = runnable.getMethod();
|
||||
assertThat(targetObject).isEqualTo(target);
|
||||
assertThat(targetMethod.getName()).isEqualTo("fixedRate");
|
||||
assertSoftly(softly -> {
|
||||
softly.assertThat(task.getInitialDelay()).as("initial delay").isEqualTo(expectedInitialDelay);
|
||||
softly.assertThat(task.getInterval()).as("interval").isEqualTo(expectedInterval);
|
||||
});
|
||||
assertThat(task.getInitialDelay()).isEqualTo(1000L);
|
||||
assertThat(task.getInterval()).isEqualTo(3000L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void expressionWithCron() {
|
||||
public void expressionWithCron() {
|
||||
String businessHoursCronExpression = "0 0 9-17 * * MON-FRI";
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(ExpressionWithCronTestBean.class);
|
||||
@@ -636,7 +605,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void propertyPlaceholderForMetaAnnotation() {
|
||||
public void propertyPlaceholderForMetaAnnotation() {
|
||||
String businessHoursCronExpression = "0 0 9-17 * * MON-FRI";
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition placeholderDefinition = new RootBeanDefinition(PropertySourcesPlaceholderConfigurer.class);
|
||||
@@ -669,7 +638,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonVoidReturnType() {
|
||||
public void nonVoidReturnType() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(NonVoidReturnTypeTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -696,7 +665,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void emptyAnnotation() {
|
||||
public void emptyAnnotation() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(EmptyAnnotationTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -706,7 +675,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void invalidCron() throws Throwable {
|
||||
public void invalidCron() throws Throwable {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(InvalidCronTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -716,7 +685,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nonEmptyParamList() {
|
||||
public void nonEmptyParamList() {
|
||||
BeanDefinition processorDefinition = new RootBeanDefinition(ScheduledAnnotationBeanPostProcessor.class);
|
||||
BeanDefinition targetDefinition = new RootBeanDefinition(NonEmptyParamListTestBean.class);
|
||||
context.registerBeanDefinition("postProcessor", processorDefinition);
|
||||
@@ -726,68 +695,26 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
}
|
||||
|
||||
|
||||
static class FixedDelay {
|
||||
static class FixedDelayTestBean {
|
||||
|
||||
@Scheduled(fixedDelay = 5000)
|
||||
void fixedDelay() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedDelayInSeconds {
|
||||
|
||||
@Scheduled(fixedDelay = 5, timeUnit = TimeUnit.SECONDS)
|
||||
void fixedDelay() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedDelayInMinutes {
|
||||
|
||||
@Scheduled(fixedDelay = 3, timeUnit = TimeUnit.MINUTES)
|
||||
void fixedDelay() {
|
||||
public void fixedDelay() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FixedRate {
|
||||
static class FixedRateTestBean {
|
||||
|
||||
@Scheduled(fixedRate = 3000)
|
||||
void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedRateInSeconds {
|
||||
|
||||
@Scheduled(fixedRate = 5, timeUnit = TimeUnit.SECONDS)
|
||||
void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedRateInMinutes {
|
||||
|
||||
@Scheduled(fixedRate = 3, timeUnit = TimeUnit.MINUTES)
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FixedRateWithInitialDelay {
|
||||
static class FixedRateWithInitialDelayTestBean {
|
||||
|
||||
@Scheduled(fixedRate = 3000, initialDelay = 1000)
|
||||
void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedRateWithInitialDelayInSeconds {
|
||||
|
||||
@Scheduled(fixedRate = 3, initialDelay = 5, timeUnit = TimeUnit.SECONDS)
|
||||
void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
static class FixedRateWithInitialDelayInMinutes {
|
||||
|
||||
@Scheduled(fixedRate = 3, initialDelay = 1, timeUnit = TimeUnit.MINUTES)
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -795,7 +722,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class SeveralFixedRatesWithSchedulesContainerAnnotationTestBean {
|
||||
|
||||
@Schedules({@Scheduled(fixedRate = 4000), @Scheduled(fixedRate = 4000, initialDelay = 2000)})
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -804,7 +731,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Scheduled(fixedRate = 4000)
|
||||
@Scheduled(fixedRate = 4000, initialDelay = 2000)
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
|
||||
static SeveralFixedRatesWithRepeatedScheduledAnnotationTestBean nestedProxy() {
|
||||
@@ -821,7 +748,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Scheduled(fixedRate = 4000)
|
||||
@Scheduled(fixedRate = 4000, initialDelay = 2000)
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -865,7 +792,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class CronWithInvalidTimezoneTestBean {
|
||||
|
||||
@Scheduled(cron = "0 0 0-4,6-23 * * ?", zone = "FOO")
|
||||
void cron() throws IOException {
|
||||
public void cron() throws IOException {
|
||||
throw new IOException("no no no");
|
||||
}
|
||||
}
|
||||
@@ -876,7 +803,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class ProxiedCronTestBean {
|
||||
|
||||
@Scheduled(cron = "*/7 * * * * ?")
|
||||
void cron() throws IOException {
|
||||
public void cron() throws IOException {
|
||||
throw new IOException("no no no");
|
||||
}
|
||||
}
|
||||
@@ -884,7 +811,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
|
||||
static class ProxiedCronTestBeanDependent {
|
||||
|
||||
ProxiedCronTestBeanDependent(ProxiedCronTestBean testBean) {
|
||||
public ProxiedCronTestBeanDependent(ProxiedCronTestBean testBean) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -892,7 +819,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class NonVoidReturnTypeTestBean {
|
||||
|
||||
@Scheduled(cron = "0 0 9-17 * * MON-FRI")
|
||||
String cron() {
|
||||
public String cron() {
|
||||
return "oops";
|
||||
}
|
||||
}
|
||||
@@ -901,7 +828,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class EmptyAnnotationTestBean {
|
||||
|
||||
@Scheduled
|
||||
void invalid() {
|
||||
public void invalid() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -909,7 +836,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class InvalidCronTestBean {
|
||||
|
||||
@Scheduled(cron = "abc")
|
||||
void invalid() {
|
||||
public void invalid() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -917,7 +844,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class NonEmptyParamListTestBean {
|
||||
|
||||
@Scheduled(fixedRate = 3000)
|
||||
void invalid(String oops) {
|
||||
public void invalid(String oops) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -949,7 +876,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class MetaAnnotationFixedRateTestBean {
|
||||
|
||||
@EveryFiveSeconds
|
||||
void checkForUpdates() {
|
||||
public void checkForUpdates() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -957,7 +884,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class ComposedAnnotationFixedRateTestBean {
|
||||
|
||||
@WaitASec(fixedRate = 5000)
|
||||
void checkForUpdates() {
|
||||
public void checkForUpdates() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -965,7 +892,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class MetaAnnotationCronTestBean {
|
||||
|
||||
@Hourly
|
||||
void generateReport() {
|
||||
public void generateReport() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -973,37 +900,23 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class PropertyPlaceholderWithCronTestBean {
|
||||
|
||||
@Scheduled(cron = "${schedules.businessHours}")
|
||||
void x() {
|
||||
public void x() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class PropertyPlaceholderWithFixedDelay {
|
||||
static class PropertyPlaceholderWithFixedDelayTestBean {
|
||||
|
||||
@Scheduled(fixedDelayString = "${fixedDelay}", initialDelayString = "${initialDelay}")
|
||||
void fixedDelay() {
|
||||
}
|
||||
}
|
||||
|
||||
static class PropertyPlaceholderWithFixedDelayInSeconds {
|
||||
|
||||
@Scheduled(fixedDelayString = "${fixedDelay}", initialDelayString = "${initialDelay}", timeUnit = TimeUnit.SECONDS)
|
||||
void fixedDelay() {
|
||||
public void fixedDelay() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class PropertyPlaceholderWithFixedRate {
|
||||
static class PropertyPlaceholderWithFixedRateTestBean {
|
||||
|
||||
@Scheduled(fixedRateString = "${fixedRate}", initialDelayString = "${initialDelay}")
|
||||
void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
static class PropertyPlaceholderWithFixedRateInSeconds {
|
||||
|
||||
@Scheduled(fixedRateString = "${fixedRate}", initialDelayString = "${initialDelay}", timeUnit = TimeUnit.SECONDS)
|
||||
void fixedRate() {
|
||||
public void fixedRate() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1011,7 +924,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class ExpressionWithCronTestBean {
|
||||
|
||||
@Scheduled(cron = "#{schedules.businessHours}")
|
||||
void x() {
|
||||
public void x() {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1026,24 +939,7 @@ class ScheduledAnnotationBeanPostProcessorTests {
|
||||
static class PropertyPlaceholderMetaAnnotationTestBean {
|
||||
|
||||
@BusinessHours
|
||||
void y() {
|
||||
}
|
||||
}
|
||||
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@ConvertWith(NameToClass.Converter.class)
|
||||
private @interface NameToClass {
|
||||
class Converter implements ArgumentConverter {
|
||||
@Override
|
||||
public Class<?> convert(Object beanClassName, ParameterContext context) throws ArgumentConversionException {
|
||||
try {
|
||||
String name = getClass().getEnclosingClass().getEnclosingClass().getName() + "$" + beanClassName;
|
||||
return getClass().getClassLoader().loadClass(name);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new ArgumentConversionException("Failed to convert class name to Class", ex);
|
||||
}
|
||||
}
|
||||
public void y() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+2
-81
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2020 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.
|
||||
@@ -16,100 +16,21 @@
|
||||
|
||||
package org.springframework.scheduling.concurrent;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.task.AsyncListenableTaskExecutor;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
* @since 5.0.5
|
||||
*/
|
||||
class ThreadPoolTaskExecutorTests extends AbstractSchedulingTaskExecutorTests {
|
||||
|
||||
private final ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
|
||||
|
||||
@Override
|
||||
protected AsyncListenableTaskExecutor buildExecutor() {
|
||||
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
|
||||
executor.setThreadNamePrefix(this.threadNamePrefix);
|
||||
executor.setMaxPoolSize(1);
|
||||
executor.afterPropertiesSet();
|
||||
return executor;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
void modifyCorePoolSizeWhileRunning() {
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
|
||||
|
||||
executor.setCorePoolSize(0);
|
||||
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(0);
|
||||
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyCorePoolSizeWithInvalidValueWhileRunning() {
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
|
||||
|
||||
assertThatThrownBy(() -> executor.setCorePoolSize(-1))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
|
||||
assertThat(executor.getCorePoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getCorePoolSize()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyMaxPoolSizeWhileRunning() {
|
||||
assertThat(executor.getMaxPoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
|
||||
|
||||
executor.setMaxPoolSize(5);
|
||||
|
||||
assertThat(executor.getMaxPoolSize()).isEqualTo(5);
|
||||
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(5);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyMaxPoolSizeWithInvalidValueWhileRunning() {
|
||||
assertThat(executor.getMaxPoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
|
||||
|
||||
assertThatThrownBy(() -> executor.setMaxPoolSize(0))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
|
||||
assertThat(executor.getMaxPoolSize()).isEqualTo(1);
|
||||
assertThat(executor.getThreadPoolExecutor().getMaximumPoolSize()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyKeepAliveSecondsWhileRunning() {
|
||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
||||
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
|
||||
|
||||
executor.setKeepAliveSeconds(10);
|
||||
|
||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(10);
|
||||
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
void modifyKeepAliveSecondsWithInvalidValueWhileRunning() {
|
||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
||||
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
|
||||
|
||||
assertThatThrownBy(() -> executor.setKeepAliveSeconds(-10))
|
||||
.isInstanceOf(IllegalArgumentException.class);
|
||||
|
||||
assertThat(executor.getKeepAliveSeconds()).isEqualTo(60);
|
||||
assertThat(executor.getThreadPoolExecutor().getKeepAliveTime(TimeUnit.SECONDS)).isEqualTo(60);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
-15
@@ -1319,21 +1319,6 @@ class CronExpressionTests {
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void various() {
|
||||
CronExpression cronExpression = CronExpression.parse("3-57 13-28 17,18 1,15 3-12 6#1");
|
||||
LocalDateTime last = LocalDateTime.of(2022, 9, 15, 17, 44, 11);
|
||||
LocalDateTime expected = LocalDateTime.of(2022, 10, 1, 17, 13, 3);
|
||||
LocalDateTime actual = cronExpression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
|
||||
cronExpression = CronExpression.parse("*/28 56 22 */6 * *");
|
||||
last = LocalDateTime.of(2022, 2, 27, 8, 0, 42);
|
||||
expected = LocalDateTime.of(2022, 3, 1, 22, 56, 0);
|
||||
actual = cronExpression.next(last);
|
||||
assertThat(actual).isNotNull();
|
||||
assertThat(actual).isEqualTo(expected);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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,7 +41,7 @@ import static org.springframework.core.testfixture.TestGroup.LONG_RUNNING;
|
||||
* @author Chris Beams
|
||||
*/
|
||||
@EnabledForTestGroups(LONG_RUNNING)
|
||||
class ScriptFactoryPostProcessorTests {
|
||||
public class ScriptFactoryPostProcessorTests {
|
||||
|
||||
private static final String MESSAGE_TEXT = "Bingo";
|
||||
|
||||
@@ -79,18 +79,18 @@ class ScriptFactoryPostProcessorTests {
|
||||
|
||||
|
||||
@Test
|
||||
void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() {
|
||||
public void testDoesNothingWhenPostProcessingNonScriptFactoryTypeBeforeInstantiation() throws Exception {
|
||||
assertThat(new ScriptFactoryPostProcessor().postProcessBeforeInstantiation(getClass(), "a.bean")).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() {
|
||||
public void testThrowsExceptionIfGivenNonAbstractBeanFactoryImplementation() throws Exception {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
new ScriptFactoryPostProcessor().setBeanFactory(mock(BeanFactory.class)));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
|
||||
public void testChangeScriptWithRefreshableBeanFunctionality() throws Exception {
|
||||
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
|
||||
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
|
||||
|
||||
@@ -111,7 +111,7 @@ class ScriptFactoryPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
|
||||
public void testChangeScriptWithNoRefreshableBeanFunctionality() throws Exception {
|
||||
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(false);
|
||||
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
|
||||
|
||||
@@ -131,7 +131,7 @@ class ScriptFactoryPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
|
||||
public void testRefreshedScriptReferencePropagatesToCollaborators() throws Exception {
|
||||
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
|
||||
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
|
||||
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
|
||||
@@ -159,7 +159,7 @@ class ScriptFactoryPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testReferencesAcrossAContainerHierarchy() throws Exception {
|
||||
public void testReferencesAcrossAContainerHierarchy() throws Exception {
|
||||
GenericApplicationContext businessContext = new GenericApplicationContext();
|
||||
businessContext.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
|
||||
businessContext.refresh();
|
||||
@@ -175,13 +175,13 @@ class ScriptFactoryPostProcessorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void testScriptHavingAReferenceToAnotherBean() throws Exception {
|
||||
public void testScriptHavingAReferenceToAnotherBean() throws Exception {
|
||||
// just tests that the (singleton) script-backed bean is able to be instantiated with references to its collaborators
|
||||
new ClassPathXmlApplicationContext("org/springframework/scripting/support/groovyReferences.xml");
|
||||
}
|
||||
|
||||
@Test
|
||||
void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
|
||||
public void testForRefreshedScriptHavingErrorPickedUpOnFirstCall() throws Exception {
|
||||
BeanDefinition processorBeanDefinition = createScriptFactoryPostProcessor(true);
|
||||
BeanDefinition scriptedBeanDefinition = createScriptedGroovyBean();
|
||||
BeanDefinitionBuilder collaboratorBuilder = BeanDefinitionBuilder.rootBeanDefinition(DefaultMessengerService.class);
|
||||
@@ -202,12 +202,13 @@ class ScriptFactoryPostProcessorTests {
|
||||
// needs The Sundays compiler; must NOT throw any exception here...
|
||||
source.setScript("I keep hoping you are the same as me, and I'll send you letters and come to your house for tea");
|
||||
Messenger refreshedMessenger = (Messenger) ctx.getBean(MESSENGER_BEAN_NAME);
|
||||
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(refreshedMessenger::getMessage)
|
||||
assertThatExceptionOfType(FatalBeanException.class).isThrownBy(() ->
|
||||
refreshedMessenger.getMessage())
|
||||
.matches(ex -> ex.contains(ScriptCompilationException.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
void testPrototypeScriptedBean() throws Exception {
|
||||
public void testPrototypeScriptedBean() throws Exception {
|
||||
GenericApplicationContext ctx = new GenericApplicationContext();
|
||||
ctx.registerBeanDefinition("messenger", BeanDefinitionBuilder.rootBeanDefinition(StubMessenger.class).getBeanDefinition());
|
||||
|
||||
@@ -235,7 +236,7 @@ class ScriptFactoryPostProcessorTests {
|
||||
private static BeanDefinition createScriptFactoryPostProcessor(boolean isRefreshable) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder.rootBeanDefinition(ScriptFactoryPostProcessor.class);
|
||||
if (isRefreshable) {
|
||||
builder.addPropertyValue("defaultRefreshCheckDelay", 1L);
|
||||
builder.addPropertyValue("defaultRefreshCheckDelay", new Long(1));
|
||||
}
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-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.
|
||||
@@ -36,17 +36,17 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Stephane Nicoll
|
||||
* @since 07.03.2006
|
||||
*/
|
||||
class DataBinderFieldAccessTests {
|
||||
public class DataBinderFieldAccessTests {
|
||||
|
||||
@Test
|
||||
void bindingNoErrors() throws Exception {
|
||||
public void bindingNoErrors() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
assertThat(binder.isIgnoreUnknownFields()).isTrue();
|
||||
binder.initDirectFieldAccess();
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
|
||||
pvs.addPropertyValue(new PropertyValue("age", 32));
|
||||
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
|
||||
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
|
||||
|
||||
binder.bind(pvs);
|
||||
@@ -62,21 +62,21 @@ class DataBinderFieldAccessTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindingNoErrorsNotIgnoreUnknown() throws Exception {
|
||||
public void bindingNoErrorsNotIgnoreUnknown() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
binder.initDirectFieldAccess();
|
||||
binder.setIgnoreUnknownFields(false);
|
||||
MutablePropertyValues pvs = new MutablePropertyValues();
|
||||
pvs.addPropertyValue(new PropertyValue("name", "Rod"));
|
||||
pvs.addPropertyValue(new PropertyValue("age", 32));
|
||||
pvs.addPropertyValue(new PropertyValue("age", new Integer(32)));
|
||||
pvs.addPropertyValue(new PropertyValue("nonExisting", "someValue"));
|
||||
assertThatExceptionOfType(NotWritablePropertyException.class).isThrownBy(() ->
|
||||
binder.bind(pvs));
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindingWithErrors() throws Exception {
|
||||
public void bindingWithErrors() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
binder.initDirectFieldAccess();
|
||||
@@ -105,7 +105,7 @@ class DataBinderFieldAccessTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedBindingWithDefaultConversionNoErrors() throws Exception {
|
||||
public void nestedBindingWithDefaultConversionNoErrors() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
assertThat(binder.isIgnoreUnknownFields()).isTrue();
|
||||
@@ -122,7 +122,7 @@ class DataBinderFieldAccessTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void nestedBindingWithDisabledAutoGrow() throws Exception {
|
||||
public void nestedBindingWithDisabledAutoGrow() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
binder.setAutoGrowNestedPaths(false);
|
||||
@@ -135,7 +135,7 @@ class DataBinderFieldAccessTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
void bindingWithErrorsAndCustomEditors() throws Exception {
|
||||
public void bindingWithErrorsAndCustomEditors() throws Exception {
|
||||
FieldAccessBean rod = new FieldAccessBean();
|
||||
DataBinder binder = new DataBinder(rod, "person");
|
||||
binder.initDirectFieldAccess();
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user