mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Compare commits
138 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4343423f1c | |||
| cfefcee788 | |||
| 5fb58e51e5 | |||
| 67c4b4182f | |||
| 6b3052200a | |||
| cf5b86369d | |||
| 7067461d71 | |||
| 34cb5df859 | |||
| 01231fe923 | |||
| 7665424ea8 | |||
| f63a106c85 | |||
| caaf48d4ec | |||
| e52fc2176d | |||
| e8e7fbba94 | |||
| bd1f34e174 | |||
| a490723f02 | |||
| df263d01b9 | |||
| 2a80b64d40 | |||
| e24043ab90 | |||
| 4078b73cec | |||
| dca155e438 | |||
| edabde8a11 | |||
| 8087eb69bf | |||
| e41d865193 | |||
| d68bb4eecd | |||
| 730ad4436f | |||
| 23ab9ca8ca | |||
| 51d263bd06 | |||
| 518dc6df65 | |||
| 59c6b7e445 | |||
| 3e75ec73ab | |||
| 709a41fd43 | |||
| 90072d06fb | |||
| 54bdab4553 | |||
| 75e1811470 | |||
| 18781e58ac | |||
| ed4e2289cd | |||
| ccf95413ed | |||
| fdd6e50721 | |||
| c04fa858fc | |||
| c3ce4f0f90 | |||
| e1200f34e7 | |||
| 999376f9f9 | |||
| c942d789c3 | |||
| 03668f9c10 | |||
| 3e14cdbc69 | |||
| f04e9a8366 | |||
| c1606c5a5e | |||
| 95fac2589f | |||
| 41c8bb4fe1 | |||
| 31a4c274b7 | |||
| d665977787 | |||
| 0b6a54dcc7 | |||
| 1885ab3e07 | |||
| de10bb69cb | |||
| c7642422c3 | |||
| 4c2e0ee5ff | |||
| 79804d92c2 | |||
| f191cf4eb3 | |||
| 0ebb1c5baa | |||
| 4b7d9b1f9c | |||
| ca84559588 | |||
| 1af21bb451 | |||
| ac581bed92 | |||
| 0802581aff | |||
| d7b9270672 | |||
| c44447f622 | |||
| 8b80d38c33 | |||
| b06d267232 | |||
| 8422d9d22f | |||
| c50a5096a0 | |||
| c25c550113 | |||
| 9e09d6cde4 | |||
| 31b8587ce6 | |||
| 00375df4e8 | |||
| b1352e1833 | |||
| b2e94f611f | |||
| ad7cdc5ce9 | |||
| 6cc9538ab9 | |||
| e9083d7d20 | |||
| 98ce171b30 | |||
| 57a5370eec | |||
| 99c7608ffe | |||
| c0f79ee00a | |||
| 9261766677 | |||
| 14f24f43d7 | |||
| d7e0eed8d2 | |||
| 7c834d98c2 | |||
| 70974e006e | |||
| 2f557d9583 | |||
| b84fe99d07 | |||
| 69df27a99f | |||
| 5649a6f8ef | |||
| be6eeafe78 | |||
| b77b45434f | |||
| 6582787678 | |||
| 8b89128c7b | |||
| 2a5713f389 | |||
| 40d2058b97 | |||
| 0d478ca8dd | |||
| 445c0def0c | |||
| ef696c787b | |||
| 27257fb82e | |||
| e209a460ca | |||
| d019c1f82b | |||
| 82d6e07090 | |||
| a1b2695c3a | |||
| 341f4882ed | |||
| 829bed03af | |||
| ce0aed216b | |||
| 0d7c562693 | |||
| 913cc079af | |||
| 3f7dec0b0d | |||
| 830cc3450f | |||
| 6f6d27f50f | |||
| 19a8b94b21 | |||
| 2c53e9e308 | |||
| 2271b6078e | |||
| e8eeb99ac8 | |||
| b67e97d388 | |||
| 656f0591c6 | |||
| 23babe27bb | |||
| bcb9f159ca | |||
| 8ca9187938 | |||
| 1e0bdf95d0 | |||
| 44da9451c4 | |||
| 544f357661 | |||
| ca4f338d75 | |||
| 8e8c88ea5c | |||
| 767299c6dd | |||
| 3290495222 | |||
| b4b3c2ead6 | |||
| dfd5374f02 | |||
| 722ab25f27 | |||
| c37d6c30a0 | |||
| 5fbdd6dcfe | |||
| 29572600dc | |||
| aaf626a537 |
+49
-49
@@ -3,8 +3,8 @@ plugins {
|
||||
id 'io.spring.nohttp' version '0.0.10'
|
||||
id "io.freefair.aspectj" version '6.2.0' apply false
|
||||
id 'org.jetbrains.dokka' version '1.5.0' apply false
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.31' apply false
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.31" apply false
|
||||
id 'org.jetbrains.kotlin.jvm' version '1.5.32' apply false
|
||||
id "org.jetbrains.kotlin.plugin.serialization" version "1.5.32" apply false
|
||||
id 'org.asciidoctor.jvm.convert' version '3.3.2'
|
||||
id 'org.asciidoctor.jvm.pdf' version '3.3.2'
|
||||
id "org.unbroken-dome.xjc" version '2.0.0' apply false
|
||||
@@ -27,19 +27,19 @@ configure(allprojects) { project ->
|
||||
|
||||
dependencyManagement {
|
||||
imports {
|
||||
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.5"
|
||||
mavenBom "io.netty:netty-bom:4.1.70.Final"
|
||||
mavenBom "io.projectreactor:reactor-bom:2020.0.13"
|
||||
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR10"
|
||||
mavenBom "com.fasterxml.jackson:jackson-bom:2.12.6"
|
||||
mavenBom "io.netty:netty-bom:4.1.72.Final"
|
||||
mavenBom "io.projectreactor:reactor-bom:2020.0.15"
|
||||
mavenBom "io.r2dbc:r2dbc-bom:Arabba-SR11"
|
||||
mavenBom "io.rsocket:rsocket-bom:1.1.1"
|
||||
mavenBom "org.eclipse.jetty:jetty-bom:9.4.44.v20210927"
|
||||
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.31"
|
||||
mavenBom "org.jetbrains.kotlin:kotlin-bom:1.5.32"
|
||||
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.1"
|
||||
mavenBom "org.junit:junit-bom:5.8.2"
|
||||
}
|
||||
dependencies {
|
||||
dependencySet(group: 'org.apache.logging.log4j', version: '2.14.1') {
|
||||
dependencySet(group: 'org.apache.logging.log4j', version: '2.17.1') {
|
||||
entry 'log4j-api'
|
||||
entry 'log4j-core'
|
||||
entry 'log4j-jul'
|
||||
@@ -67,23 +67,23 @@ 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.1.1"
|
||||
dependency "io.reactivex.rxjava3:rxjava:3.1.3"
|
||||
dependency "io.smallrye.reactive:mutiny:1.2.0"
|
||||
dependency "io.projectreactor.tools:blockhound:1.0.6.RELEASE"
|
||||
|
||||
dependency "com.caucho:hessian:4.0.63"
|
||||
dependency "com.fasterxml:aalto-xml:1.3.0"
|
||||
dependency("com.fasterxml.woodstox:woodstox-core:6.2.6") {
|
||||
dependency("com.fasterxml.woodstox:woodstox-core:6.2.7") {
|
||||
exclude group: "stax", name: "stax-api"
|
||||
}
|
||||
dependency "com.google.code.gson:gson:2.8.8"
|
||||
dependency "com.google.protobuf:protobuf-java-util:3.18.0"
|
||||
dependency "com.google.code.gson:gson:2.8.9"
|
||||
dependency "com.google.protobuf:protobuf-java-util:3.19.1"
|
||||
dependency "com.googlecode.protobuf-java-format:protobuf-java-format:1.4"
|
||||
dependency("com.thoughtworks.xstream:xstream:1.4.18") {
|
||||
exclude group: "xpp3", name: "xpp3_min"
|
||||
exclude group: "xmlpull", name: "xmlpull"
|
||||
}
|
||||
dependency "org.apache.johnzon:johnzon-jsonb:1.2.14"
|
||||
dependency "org.apache.johnzon:johnzon-jsonb:1.2.15"
|
||||
dependency("org.codehaus.jettison:jettison:1.3.8") {
|
||||
exclude group: "stax", name: "stax-api"
|
||||
}
|
||||
@@ -92,10 +92,10 @@ configure(allprojects) { project ->
|
||||
entry 'jibx-run'
|
||||
}
|
||||
dependency "org.ogce:xpp3:1.1.6"
|
||||
dependency "org.yaml:snakeyaml:1.29"
|
||||
dependency "org.yaml:snakeyaml:1.30"
|
||||
|
||||
dependency "com.h2database:h2:1.4.200"
|
||||
dependency "com.github.ben-manes.caffeine:caffeine:2.9.2"
|
||||
dependency "com.h2database:h2:2.0.206"
|
||||
dependency "com.github.ben-manes.caffeine:caffeine:2.9.3"
|
||||
dependency "com.github.librepdf:openpdf:1.3.26"
|
||||
dependency "com.rometools:rome:1.16.0"
|
||||
dependency "commons-io:commons-io:2.5"
|
||||
@@ -123,48 +123,48 @@ configure(allprojects) { project ->
|
||||
dependency "net.sf.ehcache:ehcache:2.10.6"
|
||||
dependency "org.ehcache:jcache:1.0.1"
|
||||
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.hibernate:hibernate-core:5.4.33.Final"
|
||||
dependency "org.hibernate:hibernate-validator:6.2.1.Final"
|
||||
dependency "org.webjars:webjars-locator-core:0.48"
|
||||
dependency "org.webjars:underscorejs:1.8.3"
|
||||
|
||||
dependencySet(group: 'org.apache.tomcat', version: '9.0.54') {
|
||||
dependencySet(group: 'org.apache.tomcat', version: '9.0.56') {
|
||||
entry 'tomcat-util'
|
||||
entry('tomcat-websocket') {
|
||||
exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
|
||||
exclude group: "org.apache.tomcat", name: "tomcat-servlet-api"
|
||||
exclude group: "org.apache.tomcat", name: "tomcat-websocket-api"
|
||||
}
|
||||
}
|
||||
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.54') {
|
||||
dependencySet(group: 'org.apache.tomcat.embed', version: '9.0.56') {
|
||||
entry 'tomcat-embed-core'
|
||||
entry 'tomcat-embed-websocket'
|
||||
}
|
||||
dependencySet(group: 'io.undertow', version: '2.2.12.Final') {
|
||||
dependencySet(group: 'io.undertow', version: '2.2.14.Final') {
|
||||
entry 'undertow-core'
|
||||
entry('undertow-websockets-jsr') {
|
||||
exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
|
||||
}
|
||||
entry('undertow-servlet') {
|
||||
exclude group: "org.jboss.spec.javax.servlet", name: "jboss-servlet-api_4.0_spec"
|
||||
exclude group: "org.jboss.spec.javax.annotation", name: "jboss-annotations-api_1.3_spec"
|
||||
}
|
||||
entry('undertow-websockets-jsr') {
|
||||
exclude group: "org.jboss.spec.javax.websocket", name: "jboss-websocket-api_1.1_spec"
|
||||
}
|
||||
}
|
||||
|
||||
dependency "org.eclipse.jetty:jetty-reactive-httpclient:1.1.10"
|
||||
dependency 'org.apache.httpcomponents.client5:httpclient5:5.1.2'
|
||||
dependency 'org.apache.httpcomponents.core5:httpcore5-reactive:5.1.2'
|
||||
dependency("org.apache.httpcomponents:httpclient:4.5.13") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.apache.httpcomponents:httpasyncclient:4.1.5") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependencySet(group: 'com.squareup.okhttp3', version: '3.14.9') {
|
||||
entry 'okhttp'
|
||||
entry 'mockwebserver'
|
||||
}
|
||||
dependency("org.apache.httpcomponents:httpclient:4.5.13") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.apache.httpcomponents:httpasyncclient:4.1.4") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
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.jruby:jruby:9.2.19.0"
|
||||
dependency "org.jruby:jruby:9.2.20.1"
|
||||
dependency "org.python:jython-standalone:2.7.1"
|
||||
dependency "org.mozilla:rhino:1.7.11"
|
||||
|
||||
@@ -191,25 +191,25 @@ configure(allprojects) { project ->
|
||||
dependency "org.junit.support:testng-engine:1.0.1"
|
||||
dependency "org.hamcrest:hamcrest:2.1"
|
||||
dependency "org.awaitility:awaitility:3.1.6"
|
||||
dependency "org.assertj:assertj-core:3.21.0"
|
||||
dependencySet(group: 'org.xmlunit', version: '2.8.3') {
|
||||
dependency "org.assertj:assertj-core:3.22.0"
|
||||
dependencySet(group: 'org.xmlunit', version: '2.8.4') {
|
||||
entry 'xmlunit-assertj'
|
||||
entry('xmlunit-matchers') {
|
||||
exclude group: "org.hamcrest", name: "hamcrest-core"
|
||||
}
|
||||
}
|
||||
dependencySet(group: 'org.mockito', version: '4.0.0') {
|
||||
dependencySet(group: 'org.mockito', version: '4.2.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.12.1"
|
||||
|
||||
dependency("net.sourceforge.htmlunit:htmlunit:2.54.0") {
|
||||
dependency("net.sourceforge.htmlunit:htmlunit:2.56.0") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.seleniumhq.selenium:htmlunit-driver:2.54.0") {
|
||||
dependency("org.seleniumhq.selenium:htmlunit-driver:2.56.0") {
|
||||
exclude group: "commons-logging", name: "commons-logging"
|
||||
}
|
||||
dependency("org.seleniumhq.selenium:selenium-java:3.141.59") {
|
||||
@@ -237,7 +237,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 "joda-time:joda-time:2.10.13"
|
||||
dependency "org.eclipse.persistence:org.eclipse.persistence.jpa:2.7.9"
|
||||
dependency "org.javamoney:moneta:1.3"
|
||||
|
||||
@@ -340,7 +340,7 @@ configure([rootProject] + javaProjects) { project ->
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "9.0"
|
||||
toolVersion = "9.2"
|
||||
configDirectory.set(rootProject.file("src/checkstyle"))
|
||||
}
|
||||
|
||||
@@ -353,12 +353,12 @@ configure([rootProject] + javaProjects) { project ->
|
||||
testImplementation("io.mockk:mockk")
|
||||
testImplementation("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-launcher")
|
||||
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")
|
||||
testRuntimeOnly("org.apache.logging.log4j:log4j-slf4j-impl")
|
||||
// JSR-305 only used for non-required meta-annotations
|
||||
compileOnly("com.google.code.findbugs:jsr305")
|
||||
testCompileOnly("com.google.code.findbugs:jsr305")
|
||||
@@ -383,9 +383,9 @@ 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/",
|
||||
// Disabling linking to JUnit 5.8.1, since the `package-list` file no longer exists due to
|
||||
// Disabling linking to JUnit 5.8.2, since the `package-list` file no longer exists due to
|
||||
// https://github.com/junit-team/junit5/commit/67ad4e545518b0ce2b0e7c96df31a669866d5003.
|
||||
// "https://junit.org/junit5/docs/5.8.1/api/",
|
||||
// "https://junit.org/junit5/docs/5.8.2/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/"
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
version=5.3.13-SNAPSHOT
|
||||
version=5.3.15
|
||||
org.gradle.jvmargs=-Xmx1536M
|
||||
org.gradle.caching=true
|
||||
org.gradle.parallel=true
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -74,7 +74,7 @@ class ScheduledAndTransactionalAnnotationIntegrationTests {
|
||||
|
||||
MyRepository repository = ctx.getBean(MyRepository.class);
|
||||
CallCountingTransactionManager txManager = ctx.getBean(CallCountingTransactionManager.class);
|
||||
assertThat(AopUtils.isCglibProxy(repository)).isEqualTo(true);
|
||||
assertThat(AopUtils.isCglibProxy(repository)).isTrue();
|
||||
assertThat(repository.getInvocationCount()).isGreaterThan(0);
|
||||
assertThat(txManager.commits).isGreaterThan(0);
|
||||
}
|
||||
|
||||
+1
-1
@@ -6,7 +6,7 @@ pluginManagement {
|
||||
}
|
||||
|
||||
plugins {
|
||||
id "com.gradle.enterprise" version "3.6.1"
|
||||
id "com.gradle.enterprise" version "3.7.2"
|
||||
id "io.spring.ge.conventions" version "0.0.7"
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -45,9 +45,10 @@ import org.springframework.core.NativeDetector;
|
||||
* @see AdvisedSupport#setProxyTargetClass
|
||||
* @see AdvisedSupport#setInterfaces
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class DefaultAopProxyFactory implements AopProxyFactory, Serializable {
|
||||
|
||||
private static final long serialVersionUID = 7930414337282325166L;
|
||||
|
||||
|
||||
@Override
|
||||
public AopProxy createAopProxy(AdvisedSupport config) throws AopConfigException {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -421,11 +421,7 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
* are unaffected by such changes.
|
||||
*/
|
||||
private synchronized void initializeAdvisorChain() throws AopConfigException, BeansException {
|
||||
if (this.advisorChainInitialized) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!ObjectUtils.isEmpty(this.interceptorNames)) {
|
||||
if (!this.advisorChainInitialized && !ObjectUtils.isEmpty(this.interceptorNames)) {
|
||||
if (this.beanFactory == null) {
|
||||
throw new IllegalStateException("No BeanFactory available anymore (probably due to serialization) " +
|
||||
"- cannot resolve interceptor names " + Arrays.asList(this.interceptorNames));
|
||||
@@ -464,9 +460,9 @@ public class ProxyFactoryBean extends ProxyCreatorSupport
|
||||
addAdvisorOnChainCreation(advice);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.advisorChainInitialized = true;
|
||||
this.advisorChainInitialized = true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* 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.
|
||||
@@ -25,8 +25,8 @@ import org.springframework.aop.Advisor;
|
||||
import org.springframework.aop.ThrowsAdvice;
|
||||
|
||||
/**
|
||||
* Adapter to enable {@link org.springframework.aop.MethodBeforeAdvice}
|
||||
* to be used in the Spring AOP framework.
|
||||
* Adapter to enable {@link org.springframework.aop.ThrowsAdvice} to be used
|
||||
* in the Spring AOP framework.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -322,7 +322,7 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
int b = 12;
|
||||
int c = 25;
|
||||
String d = "d";
|
||||
StringBuffer e = new StringBuffer("stringbuf");
|
||||
StringBuilder e = new StringBuilder("stringbuf");
|
||||
String expectedResult = a + b+ c + d + e;
|
||||
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
|
||||
}
|
||||
@@ -728,12 +728,12 @@ abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Aspect
|
||||
static class ManyValuedArgs {
|
||||
|
||||
String mungeArgs(String a, int b, int c, String d, StringBuffer e) {
|
||||
String mungeArgs(String a, int b, int c, String d, StringBuilder e) {
|
||||
return a + b + c + d + e;
|
||||
}
|
||||
|
||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
||||
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
||||
String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuilder e, String a) throws Throwable {
|
||||
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
|
||||
return a + b + c + d + e;
|
||||
}
|
||||
|
||||
+2
-2
@@ -16,9 +16,9 @@
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getNameCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getNameCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
|
||||
|
||||
|
||||
+1
-1
@@ -9,6 +9,6 @@
|
||||
<aop:advisor advice-ref="countingAdvice" pointcut="within(org.springframework..*)"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="countingAdvice" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
</beans>
|
||||
|
||||
+1
-1
@@ -10,6 +10,6 @@
|
||||
<aop:advisor advice-ref="countingAdvice" pointcut-ref="pc"/>
|
||||
</aop:config>
|
||||
|
||||
<bean id="countingAdvice" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="countingAdvice" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
</beans>
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
|
||||
|
||||
|
||||
+1
-1
@@ -12,7 +12,7 @@
|
||||
</aop:aspect>
|
||||
</aop:config>
|
||||
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.framework.CountingBeforeAdvice"/>
|
||||
<bean id="getAgeCounter" class="org.springframework.aop.testfixture.advice.CountingBeforeAdvice"/>
|
||||
|
||||
<bean id="testBean" class="org.springframework.beans.testfixture.beans.TestBean"/>
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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,6 +19,7 @@ package org.springframework.aop.testfixture.advice;
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Abstract superclass for counting advices etc.
|
||||
@@ -31,7 +32,7 @@ import java.util.HashMap;
|
||||
public class MethodCounter implements Serializable {
|
||||
|
||||
/** Method name --> count, does not understand overloading */
|
||||
private HashMap<String, Integer> map = new HashMap<>();
|
||||
private Map<String, Integer> map = new HashMap<>();
|
||||
|
||||
private int allCount;
|
||||
|
||||
|
||||
+2
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -20,7 +20,6 @@ import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
@@ -107,10 +106,7 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
try {
|
||||
load(MultiCacheManagerConfigurer.class, EnableCachingConfig.class);
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable root = ex.getRootCause();
|
||||
boolean condition = root instanceof IllegalStateException;
|
||||
assertThat(condition).isTrue();
|
||||
catch (IllegalStateException ex) {
|
||||
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,6 +214,7 @@ public interface BeanFactory {
|
||||
/**
|
||||
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
|
||||
* of instances, including availability and uniqueness options.
|
||||
* <p>For matching a generic type, consider {@link #getBeanProvider(ResolvableType)}.
|
||||
* @param requiredType type the bean must match; can be an interface or superclass
|
||||
* @return a corresponding provider handle
|
||||
* @since 5.1
|
||||
@@ -223,13 +224,20 @@ public interface BeanFactory {
|
||||
|
||||
/**
|
||||
* Return a provider for the specified bean, allowing for lazy on-demand retrieval
|
||||
* of instances, including availability and uniqueness options.
|
||||
* @param requiredType type the bean must match; can be a generic type declaration.
|
||||
* Note that collection types are not supported here, in contrast to reflective
|
||||
* of instances, including availability and uniqueness options. This variant allows
|
||||
* for specifying a generic type to match, similar to reflective injection points
|
||||
* with generic type declarations in method/constructor parameters.
|
||||
* <p>Note that collections of beans are not supported here, in contrast to reflective
|
||||
* injection points. For programmatically retrieving a list of beans matching a
|
||||
* specific type, specify the actual bean type as an argument here and subsequently
|
||||
* use {@link ObjectProvider#orderedStream()} or its lazy streaming/iteration options.
|
||||
* <p>Also, generics matching is strict here, as per the Java assignment rules.
|
||||
* For lenient fallback matching with unchecked semantics (similar to the ´unchecked´
|
||||
* Java compiler warning), consider calling {@link #getBeanProvider(Class)} with the
|
||||
* raw type as a second step if no full generic match is
|
||||
* {@link ObjectProvider#getIfAvailable() available} with this variant.
|
||||
* @return a corresponding provider handle
|
||||
* @param requiredType type the bean must match; can be a generic type declaration
|
||||
* @since 5.1
|
||||
* @see ObjectProvider#iterator()
|
||||
* @see ObjectProvider#stream()
|
||||
|
||||
+23
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -353,9 +353,31 @@ public interface ListableBeanFactory extends BeanFactory {
|
||||
* @since 3.0
|
||||
* @see #getBeanNamesForAnnotation
|
||||
* @see #getBeansWithAnnotation
|
||||
* @see #getType(String)
|
||||
*/
|
||||
@Nullable
|
||||
<A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
throws NoSuchBeanDefinitionException;
|
||||
|
||||
/**
|
||||
* Find an {@link Annotation} of {@code annotationType} on the specified bean,
|
||||
* traversing its interfaces and super classes if no annotation can be found on
|
||||
* the given class itself, as well as checking the bean's factory method (if any).
|
||||
* @param beanName the name of the bean to look for annotations on
|
||||
* @param annotationType the type of annotation to look for
|
||||
* (at class, interface or factory method level of the specified bean)
|
||||
* @param allowFactoryBeanInit whether a {@code FactoryBean} may get initialized
|
||||
* just for the purpose of determining its object type
|
||||
* @return the annotation of the given type if found, or {@code null} otherwise
|
||||
* @throws NoSuchBeanDefinitionException if there is no bean with the given name
|
||||
* @since 5.3.14
|
||||
* @see #getBeanNamesForAnnotation
|
||||
* @see #getBeansWithAnnotation
|
||||
* @see #getType(String, boolean)
|
||||
*/
|
||||
@Nullable
|
||||
<A extends Annotation> A findAnnotationOnBean(
|
||||
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
|
||||
throws NoSuchBeanDefinitionException;
|
||||
|
||||
}
|
||||
|
||||
+2
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -34,9 +34,7 @@ import org.springframework.lang.Nullable;
|
||||
*
|
||||
* <p><b>NOTE:</b> This interface is a special purpose interface, mainly for
|
||||
* internal use within the framework. It is recommended to implement the plain
|
||||
* {@link BeanPostProcessor} interface as far as possible, or to derive from
|
||||
* {@link InstantiationAwareBeanPostProcessorAdapter} in order to be shielded
|
||||
* from extensions to this interface.
|
||||
* {@link BeanPostProcessor} interface as far as possible.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Rod Johnson
|
||||
|
||||
+9
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -103,6 +103,14 @@ public abstract class AbstractBeanDefinitionReader implements BeanDefinitionRead
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Return the bean factory to register the bean definitions with.
|
||||
* <p>The factory is exposed through the BeanDefinitionRegistry interface,
|
||||
* encapsulating the methods that are relevant for bean definition handling.
|
||||
* @deprecated as of Spring Framework 5.3.15 in favor of {@link #getRegistry()},
|
||||
* to be removed in Spring Framework 6.0
|
||||
*/
|
||||
@Deprecated
|
||||
public final BeanDefinitionRegistry getBeanFactory() {
|
||||
return this.registry;
|
||||
}
|
||||
|
||||
+17
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -22,15 +22,15 @@ import org.springframework.core.io.ResourceLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
* Simple interface for bean definition readers.
|
||||
* Specifies load methods with Resource and String location parameters.
|
||||
* Simple interface for bean definition readers that specifies load methods with
|
||||
* {@link Resource} and {@link String} location parameters.
|
||||
*
|
||||
* <p>Concrete bean definition readers can of course add additional
|
||||
* load and register methods for bean definitions, specific to
|
||||
* their bean definition format.
|
||||
*
|
||||
* <p>Note that a bean definition reader does not have to implement
|
||||
* this interface. It only serves as suggestion for bean definition
|
||||
* this interface. It only serves as a suggestion for bean definition
|
||||
* readers that want to follow standard naming conventions.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
@@ -41,14 +41,14 @@ public interface BeanDefinitionReader {
|
||||
|
||||
/**
|
||||
* Return the bean factory to register the bean definitions with.
|
||||
* <p>The factory is exposed through the BeanDefinitionRegistry interface,
|
||||
* <p>The factory is exposed through the {@link BeanDefinitionRegistry} interface,
|
||||
* encapsulating the methods that are relevant for bean definition handling.
|
||||
*/
|
||||
BeanDefinitionRegistry getRegistry();
|
||||
|
||||
/**
|
||||
* Return the resource loader to use for resource locations.
|
||||
* Can be checked for the <b>ResourcePatternResolver</b> interface and cast
|
||||
* Return the {@link ResourceLoader} to use for resource locations.
|
||||
* <p>Can be checked for the {@code ResourcePatternResolver} interface and cast
|
||||
* accordingly, for loading multiple resources for a given resource pattern.
|
||||
* <p>A {@code null} return value suggests that absolute resource loading
|
||||
* is not available for this bean definition reader.
|
||||
@@ -56,10 +56,10 @@ public interface BeanDefinitionReader {
|
||||
* from within a bean definition resource, for example via the "import"
|
||||
* tag in XML bean definitions. It is recommended, however, to apply
|
||||
* such imports relative to the defining resource; only explicit full
|
||||
* resource locations will trigger absolute resource loading.
|
||||
* resource locations will trigger absolute path based resource loading.
|
||||
* <p>There is also a {@code loadBeanDefinitions(String)} method available,
|
||||
* for loading bean definitions from a resource location (or location pattern).
|
||||
* This is a convenience to avoid explicit ResourceLoader handling.
|
||||
* This is a convenience to avoid explicit {@code ResourceLoader} handling.
|
||||
* @see #loadBeanDefinitions(String)
|
||||
* @see org.springframework.core.io.support.ResourcePatternResolver
|
||||
*/
|
||||
@@ -70,13 +70,13 @@ public interface BeanDefinitionReader {
|
||||
* Return the class loader to use for bean classes.
|
||||
* <p>{@code null} suggests to not load bean classes eagerly
|
||||
* but rather to just register bean definitions with class names,
|
||||
* with the corresponding Classes to be resolved later (or never).
|
||||
* with the corresponding classes to be resolved later (or never).
|
||||
*/
|
||||
@Nullable
|
||||
ClassLoader getBeanClassLoader();
|
||||
|
||||
/**
|
||||
* Return the BeanNameGenerator to use for anonymous beans
|
||||
* Return the {@link BeanNameGenerator} to use for anonymous beans
|
||||
* (without explicit bean name specified).
|
||||
*/
|
||||
BeanNameGenerator getBeanNameGenerator();
|
||||
@@ -101,9 +101,10 @@ public interface BeanDefinitionReader {
|
||||
/**
|
||||
* Load bean definitions from the specified resource location.
|
||||
* <p>The location can also be a location pattern, provided that the
|
||||
* ResourceLoader of this bean definition reader is a ResourcePatternResolver.
|
||||
* @param location the resource location, to be loaded with the ResourceLoader
|
||||
* (or ResourcePatternResolver) of this bean definition reader
|
||||
* {@link ResourceLoader} of this bean definition reader is a
|
||||
* {@code ResourcePatternResolver}.
|
||||
* @param location the resource location, to be loaded with the {@code ResourceLoader}
|
||||
* (or {@code ResourcePatternResolver}) of this bean definition reader
|
||||
* @return the number of bean definitions found
|
||||
* @throws BeanDefinitionStoreException in case of loading or parsing errors
|
||||
* @see #getResourceLoader()
|
||||
@@ -114,8 +115,8 @@ public interface BeanDefinitionReader {
|
||||
|
||||
/**
|
||||
* Load bean definitions from the specified resource locations.
|
||||
* @param locations the resource locations, to be loaded with the ResourceLoader
|
||||
* (or ResourcePatternResolver) of this bean definition reader
|
||||
* @param locations the resource locations, to be loaded with the {@code ResourceLoader}
|
||||
* (or {@code ResourcePatternResolver}) of this bean definition reader
|
||||
* @return the number of bean definitions found
|
||||
* @throws BeanDefinitionStoreException in case of loading or parsing errors
|
||||
*/
|
||||
|
||||
+13
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -730,14 +730,23 @@ public class DefaultListableBeanFactory extends AbstractAutowireCapableBeanFacto
|
||||
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
return findMergedAnnotationOnBean(beanName, annotationType)
|
||||
return findAnnotationOnBean(beanName, annotationType, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <A extends Annotation> A findAnnotationOnBean(
|
||||
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
return findMergedAnnotationOnBean(beanName, annotationType, allowFactoryBeanInit)
|
||||
.synthesize(MergedAnnotation::isPresent).orElse(null);
|
||||
}
|
||||
|
||||
private <A extends Annotation> MergedAnnotation<A> findMergedAnnotationOnBean(
|
||||
String beanName, Class<A> annotationType) {
|
||||
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit) {
|
||||
|
||||
Class<?> beanType = getType(beanName);
|
||||
Class<?> beanType = getType(beanName, allowFactoryBeanInit);
|
||||
if (beanType != null) {
|
||||
MergedAnnotation<A> annotation =
|
||||
MergedAnnotations.from(beanType, SearchStrategy.TYPE_HIERARCHY).get(annotationType);
|
||||
|
||||
+11
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -459,7 +459,16 @@ public class StaticListableBeanFactory implements ListableBeanFactory {
|
||||
public <A extends Annotation> A findAnnotationOnBean(String beanName, Class<A> annotationType)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
Class<?> beanType = getType(beanName);
|
||||
return findAnnotationOnBean(beanName, annotationType, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <A extends Annotation> A findAnnotationOnBean(
|
||||
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
Class<?> beanType = getType(beanName, allowFactoryBeanInit);
|
||||
return (beanType != null ? AnnotatedElementUtils.findMergedAnnotation(beanType, annotationType) : null);
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -46,7 +46,7 @@ public class BeanWrapperEnumTests {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("customEnum", null);
|
||||
assertThat(gb.getCustomEnum()).isEqualTo(null);
|
||||
assertThat(gb.getCustomEnum()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,7 +54,7 @@ public class BeanWrapperEnumTests {
|
||||
GenericBean<?> gb = new GenericBean<>();
|
||||
BeanWrapper bw = new BeanWrapperImpl(gb);
|
||||
bw.setPropertyValue("customEnum", "");
|
||||
assertThat(gb.getCustomEnum()).isEqualTo(null);
|
||||
assertThat(gb.getCustomEnum()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -433,7 +433,7 @@ class DefaultListableBeanFactoryTests {
|
||||
assertThat(lbf.isTypeMatch("x1", Object.class)).isTrue();
|
||||
assertThat(lbf.isTypeMatch("&x1", Object.class)).isFalse();
|
||||
assertThat(lbf.getType("x1")).isEqualTo(TestBean.class);
|
||||
assertThat(lbf.getType("&x1")).isEqualTo(null);
|
||||
assertThat(lbf.getType("&x1")).isNull();
|
||||
assertThat(TestBeanFactory.initialized).isFalse();
|
||||
|
||||
lbf.registerAlias("x1", "x2");
|
||||
@@ -2622,8 +2622,8 @@ class DefaultListableBeanFactoryTests {
|
||||
void containsBeanReturnsTrueEvenForAbstractBeanDefinition() {
|
||||
lbf.registerBeanDefinition("abs", BeanDefinitionBuilder
|
||||
.rootBeanDefinition(TestBean.class).setAbstract(true).getBeanDefinition());
|
||||
assertThat(lbf.containsBean("abs")).isEqualTo(true);
|
||||
assertThat(lbf.containsBean("bogus")).isEqualTo(false);
|
||||
assertThat(lbf.containsBean("abs")).isTrue();
|
||||
assertThat(lbf.containsBean("bogus")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -111,7 +111,7 @@ public class PropertyResourceConfigurerTests {
|
||||
|
||||
assertThat(tb1.getAge()).isEqualTo(99);
|
||||
assertThat(tb2.getAge()).isEqualTo(99);
|
||||
assertThat(tb1.getName()).isEqualTo(null);
|
||||
assertThat(tb1.getName()).isNull();
|
||||
assertThat(tb2.getName()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@@ -310,7 +310,7 @@ public class PropertyResourceConfigurerTests {
|
||||
TestBean tb2 = (TestBean) factory.getBean("tb2");
|
||||
assertThat(tb1.getAge()).isEqualTo(99);
|
||||
assertThat(tb2.getAge()).isEqualTo(99);
|
||||
assertThat(tb1.getName()).isEqualTo(null);
|
||||
assertThat(tb1.getName()).isNull();
|
||||
assertThat(tb2.getName()).isEqualTo("test");
|
||||
}
|
||||
|
||||
@@ -423,7 +423,7 @@ public class PropertyResourceConfigurerTests {
|
||||
TestBean inner1 = (TestBean) tb2.getSomeMap().get("key3");
|
||||
TestBean inner2 = (TestBean) tb2.getSomeMap().get("mykey4");
|
||||
assertThat(inner1.getAge()).isEqualTo(0);
|
||||
assertThat(inner1.getName()).isEqualTo(null);
|
||||
assertThat(inner1.getName()).isNull();
|
||||
assertThat(inner1.getCountry()).isEqualTo(System.getProperty("os.name"));
|
||||
assertThat(inner2.getAge()).isEqualTo(98);
|
||||
assertThat(inner2.getName()).isEqualTo("namemyvarmyvar${");
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -449,7 +449,7 @@ public class CallbacksSecurityTests {
|
||||
public Object run() {
|
||||
// sanity check
|
||||
assertThat(getCurrentSubjectName()).isEqualTo("user1");
|
||||
assertThat(NonPrivilegedBean.destroyed).isEqualTo(false);
|
||||
assertThat(NonPrivilegedBean.destroyed).isFalse();
|
||||
|
||||
beanFactory.getBean("trusted-spring-callbacks");
|
||||
beanFactory.getBean("trusted-custom-init-destroy");
|
||||
@@ -465,7 +465,7 @@ public class CallbacksSecurityTests {
|
||||
beanFactory.getBean("trusted-working-property-injection");
|
||||
|
||||
beanFactory.destroySingletons();
|
||||
assertThat(NonPrivilegedBean.destroyed).isEqualTo(true);
|
||||
assertThat(NonPrivilegedBean.destroyed).isTrue();
|
||||
return null;
|
||||
}
|
||||
}, provider.getAccessControlContext());
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -100,17 +100,17 @@ public class FactoryMethodTests {
|
||||
|
||||
FactoryMethods fm = (FactoryMethods) xbf.getBean("fullWithNull");
|
||||
assertThat(fm.getNum()).isEqualTo(27);
|
||||
assertThat(fm.getName()).isEqualTo(null);
|
||||
assertThat(fm.getName()).isNull();
|
||||
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
|
||||
|
||||
fm = (FactoryMethods) xbf.getBean("fullWithGenericNull");
|
||||
assertThat(fm.getNum()).isEqualTo(27);
|
||||
assertThat(fm.getName()).isEqualTo(null);
|
||||
assertThat(fm.getName()).isNull();
|
||||
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
|
||||
|
||||
fm = (FactoryMethods) xbf.getBean("fullWithNamedNull");
|
||||
assertThat(fm.getNum()).isEqualTo(27);
|
||||
assertThat(fm.getName()).isEqualTo(null);
|
||||
assertThat(fm.getName()).isNull();
|
||||
assertThat(fm.getTestBean().getName()).isEqualTo("Juergen");
|
||||
}
|
||||
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -342,7 +342,7 @@ public class UtilNamespaceHandlerTests {
|
||||
public void testLoadProperties() {
|
||||
Properties props = (Properties) this.beanFactory.getBean("myProperties");
|
||||
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
|
||||
Properties props2 = (Properties) this.beanFactory.getBean("myProperties");
|
||||
assertThat(props == props2).isTrue();
|
||||
}
|
||||
@@ -351,17 +351,17 @@ public class UtilNamespaceHandlerTests {
|
||||
public void testScopedProperties() {
|
||||
Properties props = (Properties) this.beanFactory.getBean("myScopedProperties");
|
||||
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
|
||||
Properties props2 = (Properties) this.beanFactory.getBean("myScopedProperties");
|
||||
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo("bar");
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo(null);
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isNull();
|
||||
assertThat(props != props2).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLocalProperties() {
|
||||
Properties props = (Properties) this.beanFactory.getBean("myLocalProperties");
|
||||
assertThat(props.get("foo")).as("Incorrect property value").isEqualTo(null);
|
||||
assertThat(props.get("foo")).as("Incorrect property value").isNull();
|
||||
assertThat(props.get("foo2")).as("Incorrect property value").isEqualTo("bar2");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -283,7 +283,7 @@ public class XmlBeanCollectionTests {
|
||||
Iterator it = hasMap.getSet().iterator();
|
||||
assertThat(it.next()).isEqualTo("bar");
|
||||
assertThat(it.next()).isEqualTo(jenny);
|
||||
assertThat(it.next()).isEqualTo(null);
|
||||
assertThat(it.next()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -181,7 +181,7 @@ public class XmlListableBeanFactoryTests extends AbstractListableBeanFactoryTest
|
||||
assertThat(beanNames.contains("aliasWithoutId3")).isFalse();
|
||||
|
||||
TestBean tb4 = (TestBean) getBeanFactory().getBean(TestBean.class.getName() + "#0");
|
||||
assertThat(tb4.getName()).isEqualTo(null);
|
||||
assertThat(tb4.getName()).isNull();
|
||||
|
||||
Map drs = getListableBeanFactory().getBeansOfType(DummyReferencer.class, false, false);
|
||||
assertThat(drs.size()).isEqualTo(5);
|
||||
|
||||
+1
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
|
||||
+9
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -20,7 +20,6 @@ import java.util.function.Supplier;
|
||||
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.cache.annotation.AbstractCachingConfiguration;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.interceptor.CacheResolver;
|
||||
import org.springframework.cache.jcache.interceptor.DefaultJCacheOperationSource;
|
||||
import org.springframework.cache.jcache.interceptor.JCacheOperationSource;
|
||||
@@ -46,11 +45,14 @@ public abstract class AbstractJCacheConfiguration extends AbstractCachingConfigu
|
||||
|
||||
|
||||
@Override
|
||||
protected void useCachingConfigurer(CachingConfigurer config) {
|
||||
super.useCachingConfigurer(config);
|
||||
if (config instanceof JCacheConfigurer) {
|
||||
this.exceptionCacheResolver = ((JCacheConfigurer) config)::exceptionCacheResolver;
|
||||
}
|
||||
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
|
||||
super.useCachingConfigurer(cachingConfigurerSupplier);
|
||||
this.exceptionCacheResolver = cachingConfigurerSupplier.adapt(config -> {
|
||||
if (config instanceof JCacheConfigurer) {
|
||||
return ((JCacheConfigurer) config).exceptionCacheResolver();
|
||||
}
|
||||
return null;
|
||||
});
|
||||
}
|
||||
|
||||
@Bean(name = "jCacheOperationSource")
|
||||
|
||||
Vendored
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,8 +26,7 @@ import org.springframework.lang.Nullable;
|
||||
* <p>To be implemented by classes annotated with
|
||||
* {@link org.springframework.cache.annotation.EnableCaching} that wish
|
||||
* or need to specify explicitly how exception caches are resolved for
|
||||
* annotation-driven cache management. Consider extending {@link JCacheConfigurerSupport},
|
||||
* which provides a stub implementation of all interface methods.
|
||||
* annotation-driven cache management.
|
||||
*
|
||||
* <p>See {@link org.springframework.cache.annotation.EnableCaching} for
|
||||
* general examples and context; see {@link #exceptionCacheResolver()} for
|
||||
@@ -36,7 +35,6 @@ import org.springframework.lang.Nullable;
|
||||
* @author Stephane Nicoll
|
||||
* @since 4.1
|
||||
* @see CachingConfigurer
|
||||
* @see JCacheConfigurerSupport
|
||||
* @see org.springframework.cache.annotation.EnableCaching
|
||||
*/
|
||||
public interface JCacheConfigurer extends CachingConfigurer {
|
||||
@@ -60,6 +58,8 @@ public interface JCacheConfigurer extends CachingConfigurer {
|
||||
* See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples.
|
||||
*/
|
||||
@Nullable
|
||||
CacheResolver exceptionCacheResolver();
|
||||
default CacheResolver exceptionCacheResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -79,7 +79,7 @@ public abstract class AbstractFallbackJCacheOperationSource implements JCacheOpe
|
||||
|
||||
@Nullable
|
||||
private JCacheOperation<?> computeCacheOperation(Method method, @Nullable Class<?> targetClass) {
|
||||
// Don't allow no-public methods as required.
|
||||
// Don't allow non-public methods, as configured.
|
||||
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -39,6 +39,8 @@ import org.springframework.lang.Nullable;
|
||||
* Subclass of Quartz's {@link JobStoreCMT} class that delegates to a Spring-managed
|
||||
* {@link DataSource} instead of using a Quartz-managed JDBC connection pool.
|
||||
* This JobStore will be used if SchedulerFactoryBean's "dataSource" property is set.
|
||||
* You may also configure it explicitly, possibly as a custom subclass of this
|
||||
* {@code LocalDataSourceJobStore} or as an equivalent {@code JobStoreCMT} variant.
|
||||
*
|
||||
* <p>Supports both transactional and non-transactional DataSource access.
|
||||
* With a non-XA DataSource and local Spring transactions, a single DataSource
|
||||
@@ -58,6 +60,8 @@ import org.springframework.lang.Nullable;
|
||||
* @since 1.1
|
||||
* @see SchedulerFactoryBean#setDataSource
|
||||
* @see SchedulerFactoryBean#setNonTransactionalDataSource
|
||||
* @see SchedulerFactoryBean#getConfigTimeDataSource()
|
||||
* @see SchedulerFactoryBean#getConfigTimeNonTransactionalDataSource()
|
||||
* @see org.springframework.jdbc.datasource.DataSourceUtils#doGetConnection
|
||||
* @see org.springframework.jdbc.datasource.DataSourceUtils#releaseConnection
|
||||
*/
|
||||
|
||||
+3
-1
@@ -310,9 +310,11 @@ public class SchedulerFactoryBean extends SchedulerAccessor implements FactoryBe
|
||||
|
||||
/**
|
||||
* Set the default {@link DataSource} to be used by the Scheduler.
|
||||
* If set, this will override corresponding settings in Quartz properties.
|
||||
* <p>Note: If this is set, the Quartz settings should not define
|
||||
* a job store "dataSource" to avoid meaningless double configuration.
|
||||
* Also, do not define a "org.quartz.jobStore.class" property at all.
|
||||
* (You may explicitly define Spring's {@link LocalDataSourceJobStore}
|
||||
* but that's the default when using this method anyway.)
|
||||
* <p>A Spring-specific subclass of Quartz' JobStoreCMT will be used.
|
||||
* It is therefore strongly recommended to perform all operations on
|
||||
* the Scheduler within Spring-managed (or plain JTA) transactions.
|
||||
|
||||
Vendored
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -106,7 +106,7 @@ class CaffeineCacheTests extends AbstractValueAdaptingCacheTests<CaffeineCache>
|
||||
Cache.ValueWrapper wrapper = cache.putIfAbsent(key, "anotherValue");
|
||||
// A value is set but is 'null'
|
||||
assertThat(wrapper).isNotNull();
|
||||
assertThat(wrapper.get()).isEqualTo(null);
|
||||
assertThat(wrapper.get()).isNull();
|
||||
// not changed
|
||||
assertThat(cache.get(key).get()).isEqualTo(value);
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,7 +26,7 @@ import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
@@ -104,7 +104,7 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class EnableCachingConfig extends CachingConfigurerSupport {
|
||||
static class EnableCachingConfig implements CachingConfigurer {
|
||||
|
||||
@Autowired
|
||||
CachingProvider cachingProvider;
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -180,7 +180,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public static class EmptyConfigSupportConfig extends JCacheConfigurerSupport {
|
||||
public static class EmptyConfigSupportConfig implements JCacheConfigurer {
|
||||
@Bean
|
||||
public CacheManager cm() {
|
||||
return new NoOpCacheManager();
|
||||
@@ -190,7 +190,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class FullCachingConfigSupport extends JCacheConfigurerSupport {
|
||||
static class FullCachingConfigSupport implements JCacheConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
@@ -220,7 +220,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class NoExceptionCacheResolverConfig extends JCacheConfigurerSupport {
|
||||
static class NoExceptionCacheResolverConfig implements JCacheConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
|
||||
import org.springframework.cache.jcache.config.JCacheConfigurer;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
@@ -141,7 +141,7 @@ public class JCacheErrorHandlerTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends JCacheConfigurerSupport {
|
||||
static class Config implements JCacheConfigurer {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -34,7 +34,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.cache.interceptor.KeyGenerator;
|
||||
import org.springframework.cache.interceptor.SimpleKey;
|
||||
import org.springframework.cache.interceptor.SimpleKeyGenerator;
|
||||
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
|
||||
import org.springframework.cache.jcache.config.JCacheConfigurer;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
@@ -97,7 +97,7 @@ public class JCacheKeyGeneratorTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends JCacheConfigurerSupport {
|
||||
static class Config implements JCacheConfigurer {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
@@ -151,7 +151,7 @@ public class JCacheKeyGeneratorTests {
|
||||
@Override
|
||||
public Object generate(Object target, Method method, Object... params) {
|
||||
assertThat(Arrays.equals(expectedParams, params)).as("Unexpected parameters: expected: "
|
||||
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
|
||||
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
|
||||
return new SimpleKey(params);
|
||||
}
|
||||
}
|
||||
|
||||
Vendored
+56
-21
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,9 +16,12 @@
|
||||
|
||||
package org.springframework.cache.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||
@@ -30,6 +33,7 @@ import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.function.SingletonSupplier;
|
||||
|
||||
/**
|
||||
* Abstract base {@code @Configuration} class providing common structure
|
||||
@@ -63,36 +67,67 @@ public abstract class AbstractCachingConfiguration implements ImportAware {
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableCaching = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableCaching.class.getName(), false));
|
||||
importMetadata.getAnnotationAttributes(EnableCaching.class.getName()));
|
||||
if (this.enableCaching == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableCaching is not present on importing class " + importMetadata.getClassName());
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired(required = false)
|
||||
void setConfigurers(Collection<CachingConfigurer> configurers) {
|
||||
if (CollectionUtils.isEmpty(configurers)) {
|
||||
return;
|
||||
}
|
||||
if (configurers.size() > 1) {
|
||||
throw new IllegalStateException(configurers.size() + " implementations of " +
|
||||
"CachingConfigurer were found when only 1 was expected. " +
|
||||
"Refactor the configuration such that CachingConfigurer is " +
|
||||
"implemented only once or not at all.");
|
||||
}
|
||||
CachingConfigurer configurer = configurers.iterator().next();
|
||||
useCachingConfigurer(configurer);
|
||||
@Autowired
|
||||
void setConfigurers(ObjectProvider<CachingConfigurer> configurers) {
|
||||
Supplier<CachingConfigurer> configurer = () -> {
|
||||
List<CachingConfigurer> candidates = configurers.stream().collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(candidates)) {
|
||||
return null;
|
||||
}
|
||||
if (candidates.size() > 1) {
|
||||
throw new IllegalStateException(candidates.size() + " implementations of " +
|
||||
"CachingConfigurer were found when only 1 was expected. " +
|
||||
"Refactor the configuration such that CachingConfigurer is " +
|
||||
"implemented only once or not at all.");
|
||||
}
|
||||
return candidates.get(0);
|
||||
};
|
||||
useCachingConfigurer(new CachingConfigurerSupplier(configurer));
|
||||
}
|
||||
|
||||
/**
|
||||
* Extract the configuration from the nominated {@link CachingConfigurer}.
|
||||
*/
|
||||
protected void useCachingConfigurer(CachingConfigurer config) {
|
||||
this.cacheManager = config::cacheManager;
|
||||
this.cacheResolver = config::cacheResolver;
|
||||
this.keyGenerator = config::keyGenerator;
|
||||
this.errorHandler = config::errorHandler;
|
||||
protected void useCachingConfigurer(CachingConfigurerSupplier cachingConfigurerSupplier) {
|
||||
this.cacheManager = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheManager);
|
||||
this.cacheResolver = cachingConfigurerSupplier.adapt(CachingConfigurer::cacheResolver);
|
||||
this.keyGenerator = cachingConfigurerSupplier.adapt(CachingConfigurer::keyGenerator);
|
||||
this.errorHandler = cachingConfigurerSupplier.adapt(CachingConfigurer::errorHandler);
|
||||
}
|
||||
|
||||
|
||||
protected static class CachingConfigurerSupplier {
|
||||
|
||||
private final Supplier<CachingConfigurer> supplier;
|
||||
|
||||
public CachingConfigurerSupplier(Supplier<CachingConfigurer> supplier) {
|
||||
this.supplier = SingletonSupplier.of(supplier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adapt the {@link CachingConfigurer} supplier to another supplier
|
||||
* provided by the specified mapping function. If the underlying
|
||||
* {@link CachingConfigurer} is {@code null}, {@code null} is returned
|
||||
* and the mapping function is not invoked.
|
||||
* @param provider the provider to use to adapt the supplier
|
||||
* @param <T> the type of the supplier
|
||||
* @return another supplier mapped by the specified function
|
||||
*/
|
||||
@Nullable
|
||||
public <T> Supplier<T> adapt(Function<CachingConfigurer, T> provider) {
|
||||
return () -> {
|
||||
CachingConfigurer cachingConfigurer = this.supplier.get();
|
||||
return (cachingConfigurer != null ? provider.apply(cachingConfigurer) : null);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,8 +26,7 @@ import org.springframework.lang.Nullable;
|
||||
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
|
||||
* Configuration} classes annotated with @{@link EnableCaching} that wish or need to
|
||||
* specify explicitly how caches are resolved and how keys are generated for annotation-driven
|
||||
* cache management. Consider extending {@link CachingConfigurerSupport}, which provides a
|
||||
* stub implementation of all interface methods.
|
||||
* cache management.
|
||||
*
|
||||
* <p>See @{@link EnableCaching} for general examples and context; see
|
||||
* {@link #cacheManager()}, {@link #cacheResolver()} and {@link #keyGenerator()}
|
||||
@@ -37,7 +36,6 @@ import org.springframework.lang.Nullable;
|
||||
* @author Stephane Nicoll
|
||||
* @since 3.1
|
||||
* @see EnableCaching
|
||||
* @see CachingConfigurerSupport
|
||||
*/
|
||||
public interface CachingConfigurer {
|
||||
|
||||
@@ -64,7 +62,9 @@ public interface CachingConfigurer {
|
||||
* See @{@link EnableCaching} for more complete examples.
|
||||
*/
|
||||
@Nullable
|
||||
CacheManager cacheManager();
|
||||
default CacheManager cacheManager() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link CacheResolver} bean to use to resolve regular caches for
|
||||
@@ -89,7 +89,9 @@ public interface CachingConfigurer {
|
||||
* See {@link EnableCaching} for more complete examples.
|
||||
*/
|
||||
@Nullable
|
||||
CacheResolver cacheResolver();
|
||||
default CacheResolver cacheResolver() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the key generator bean to use for annotation-driven cache management.
|
||||
@@ -110,7 +112,9 @@ public interface CachingConfigurer {
|
||||
* See @{@link EnableCaching} for more complete examples.
|
||||
*/
|
||||
@Nullable
|
||||
KeyGenerator keyGenerator();
|
||||
default KeyGenerator keyGenerator() {
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the {@link CacheErrorHandler} to use to handle cache-related errors.
|
||||
@@ -133,6 +137,8 @@ public interface CachingConfigurer {
|
||||
* See @{@link EnableCaching} for more complete examples.
|
||||
*/
|
||||
@Nullable
|
||||
CacheErrorHandler errorHandler();
|
||||
default CacheErrorHandler errorHandler() {
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -124,7 +124,7 @@ public abstract class AbstractFallbackCacheOperationSource implements CacheOpera
|
||||
|
||||
@Nullable
|
||||
private Collection<CacheOperation> computeCacheOperations(Method method, @Nullable Class<?> targetClass) {
|
||||
// Don't allow no-public methods as required.
|
||||
// Don't allow non-public methods, as configured.
|
||||
if (allowPublicMethodsOnly() && !Modifier.isPublic(method.getModifiers())) {
|
||||
return null;
|
||||
}
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -47,9 +47,10 @@ import org.springframework.util.StringUtils;
|
||||
*
|
||||
* <p>If the annotation's value doesn't indicate a bean name, an appropriate
|
||||
* name will be built based on the short name of the class (with the first
|
||||
* letter lower-cased). For example:
|
||||
* letter lower-cased), unless the two first letters are uppercase. For example:
|
||||
*
|
||||
* <pre class="code">com.xyz.FooServiceImpl -> fooServiceImpl</pre>
|
||||
* <pre class="code">com.xyz.URLFooServiceImpl -> URLFooServiceImpl</pre>
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
* @author Mark Fisher
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -282,7 +282,7 @@ public abstract class AnnotationConfigUtils {
|
||||
|
||||
@Nullable
|
||||
static AnnotationAttributes attributesFor(AnnotatedTypeMetadata metadata, String annotationClassName) {
|
||||
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName, false));
|
||||
return AnnotationAttributes.fromMap(metadata.getAnnotationAttributes(annotationClassName));
|
||||
}
|
||||
|
||||
static Set<AnnotationAttributes> attributesForRepeatable(AnnotationMetadata metadata,
|
||||
@@ -298,10 +298,10 @@ public abstract class AnnotationConfigUtils {
|
||||
Set<AnnotationAttributes> result = new LinkedHashSet<>();
|
||||
|
||||
// Direct annotation present?
|
||||
addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName, false));
|
||||
addAttributesIfNotNull(result, metadata.getAnnotationAttributes(annotationClassName));
|
||||
|
||||
// Container annotation present?
|
||||
Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName, false);
|
||||
Map<String, Object> container = metadata.getAnnotationAttributes(containerClassName);
|
||||
if (container != null && container.containsKey("value")) {
|
||||
for (Map<String, Object> containedAttributes : (Map<String, Object>[]) container.get("value")) {
|
||||
addAttributesIfNotNull(result, containedAttributes);
|
||||
|
||||
+10
@@ -1331,6 +1331,16 @@ public abstract class AbstractApplicationContext extends DefaultResourceLoader
|
||||
return getBeanFactory().findAnnotationOnBean(beanName, annotationType);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public <A extends Annotation> A findAnnotationOnBean(
|
||||
String beanName, Class<A> annotationType, boolean allowFactoryBeanInit)
|
||||
throws NoSuchBeanDefinitionException {
|
||||
|
||||
assertBeanFactoryActive();
|
||||
return getBeanFactory().findAnnotationOnBean(beanName, annotationType, allowFactoryBeanInit);
|
||||
}
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Implementation of HierarchicalBeanFactory interface
|
||||
|
||||
+28
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,11 +16,14 @@
|
||||
|
||||
package org.springframework.scheduling.annotation;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.Executor;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.Supplier;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler;
|
||||
import org.springframework.beans.factory.ObjectProvider;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportAware;
|
||||
@@ -28,6 +31,7 @@ import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.type.AnnotationMetadata;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
import org.springframework.util.function.SingletonSupplier;
|
||||
|
||||
/**
|
||||
* Abstract base {@code Configuration} class providing common structure for enabling
|
||||
@@ -55,7 +59,7 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
|
||||
@Override
|
||||
public void setImportMetadata(AnnotationMetadata importMetadata) {
|
||||
this.enableAsync = AnnotationAttributes.fromMap(
|
||||
importMetadata.getAnnotationAttributes(EnableAsync.class.getName(), false));
|
||||
importMetadata.getAnnotationAttributes(EnableAsync.class.getName()));
|
||||
if (this.enableAsync == null) {
|
||||
throw new IllegalArgumentException(
|
||||
"@EnableAsync is not present on importing class " + importMetadata.getClassName());
|
||||
@@ -65,17 +69,27 @@ public abstract class AbstractAsyncConfiguration implements ImportAware {
|
||||
/**
|
||||
* Collect any {@link AsyncConfigurer} beans through autowiring.
|
||||
*/
|
||||
@Autowired(required = false)
|
||||
void setConfigurers(Collection<AsyncConfigurer> configurers) {
|
||||
if (CollectionUtils.isEmpty(configurers)) {
|
||||
return;
|
||||
}
|
||||
if (configurers.size() > 1) {
|
||||
throw new IllegalStateException("Only one AsyncConfigurer may exist");
|
||||
}
|
||||
AsyncConfigurer configurer = configurers.iterator().next();
|
||||
this.executor = configurer::getAsyncExecutor;
|
||||
this.exceptionHandler = configurer::getAsyncUncaughtExceptionHandler;
|
||||
@Autowired
|
||||
void setConfigurers(ObjectProvider<AsyncConfigurer> configurers) {
|
||||
Supplier<AsyncConfigurer> configurer = SingletonSupplier.of(() -> {
|
||||
List<AsyncConfigurer> candidates = configurers.stream().collect(Collectors.toList());
|
||||
if (CollectionUtils.isEmpty(candidates)) {
|
||||
return null;
|
||||
}
|
||||
if (candidates.size() > 1) {
|
||||
throw new IllegalStateException("Only one AsyncConfigurer may exist");
|
||||
}
|
||||
return candidates.get(0);
|
||||
});
|
||||
this.executor = adapt(configurer, AsyncConfigurer::getAsyncExecutor);
|
||||
this.exceptionHandler = adapt(configurer, AsyncConfigurer::getAsyncUncaughtExceptionHandler);
|
||||
}
|
||||
|
||||
private <T> Supplier<T> adapt(Supplier<AsyncConfigurer> supplier, Function<AsyncConfigurer, T> provider) {
|
||||
return () -> {
|
||||
AsyncConfigurer configurer = supplier.get();
|
||||
return (configurer != null ? provider.apply(configurer) : null);
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
* 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.
|
||||
@@ -28,11 +28,6 @@ import org.springframework.lang.Nullable;
|
||||
* {@link AsyncUncaughtExceptionHandler} instance used to process exception thrown from
|
||||
* async method with {@code void} return type.
|
||||
*
|
||||
* <p>Consider using {@link AsyncConfigurerSupport} providing default implementations for
|
||||
* both methods if only one element needs to be customized. Furthermore, backward compatibility
|
||||
* of this interface will be insured in case new customization options are introduced
|
||||
* in the future.
|
||||
*
|
||||
* <p>See @{@link EnableAsync} for usage examples.
|
||||
*
|
||||
* @author Chris Beams
|
||||
@@ -40,7 +35,6 @@ import org.springframework.lang.Nullable;
|
||||
* @since 3.1
|
||||
* @see AbstractAsyncConfiguration
|
||||
* @see EnableAsync
|
||||
* @see AsyncConfigurerSupport
|
||||
*/
|
||||
public interface AsyncConfigurer {
|
||||
|
||||
|
||||
+17
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,9 +26,7 @@ import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.springframework.beans.factory.DisposableBean;
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
/**
|
||||
@@ -65,7 +63,7 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
|
||||
implements FactoryBean<ExecutorService>, InitializingBean, DisposableBean {
|
||||
implements FactoryBean<ExecutorService> {
|
||||
|
||||
private int corePoolSize = 1;
|
||||
|
||||
@@ -75,6 +73,8 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
|
||||
|
||||
private boolean allowCoreThreadTimeOut = false;
|
||||
|
||||
private boolean prestartAllCoreThreads = false;
|
||||
|
||||
private int queueCapacity = Integer.MAX_VALUE;
|
||||
|
||||
private boolean exposeUnconfigurableExecutor = false;
|
||||
@@ -118,6 +118,16 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
|
||||
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to start all core threads, causing them to idly wait for work.
|
||||
* <p>Default is "false".
|
||||
* @since 5.3.14
|
||||
* @see java.util.concurrent.ThreadPoolExecutor#prestartAllCoreThreads
|
||||
*/
|
||||
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) {
|
||||
this.prestartAllCoreThreads = prestartAllCoreThreads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the capacity for the ThreadPoolExecutor's BlockingQueue.
|
||||
* Default is {@code Integer.MAX_VALUE}.
|
||||
@@ -153,6 +163,9 @@ public class ThreadPoolExecutorFactoryBean extends ExecutorConfigurationSupport
|
||||
if (this.allowCoreThreadTimeOut) {
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
}
|
||||
if (this.prestartAllCoreThreads) {
|
||||
executor.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
// Wrap executor with an unconfigurable decorator.
|
||||
this.exposedExecutor = (this.exposeUnconfigurableExecutor ?
|
||||
|
||||
+16
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -94,6 +94,8 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
|
||||
private boolean allowCoreThreadTimeOut = false;
|
||||
|
||||
private boolean prestartAllCoreThreads = false;
|
||||
|
||||
@Nullable
|
||||
private TaskDecorator taskDecorator;
|
||||
|
||||
@@ -197,6 +199,16 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
this.allowCoreThreadTimeOut = allowCoreThreadTimeOut;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify whether to start all core threads, causing them to idly wait for work.
|
||||
* <p>Default is "false".
|
||||
* @since 5.3.14
|
||||
* @see java.util.concurrent.ThreadPoolExecutor#prestartAllCoreThreads
|
||||
*/
|
||||
public void setPrestartAllCoreThreads(boolean prestartAllCoreThreads) {
|
||||
this.prestartAllCoreThreads = prestartAllCoreThreads;
|
||||
}
|
||||
|
||||
/**
|
||||
* Specify a custom {@link TaskDecorator} to be applied to any {@link Runnable}
|
||||
* about to be executed.
|
||||
@@ -256,6 +268,9 @@ public class ThreadPoolTaskExecutor extends ExecutorConfigurationSupport
|
||||
if (this.allowCoreThreadTimeOut) {
|
||||
executor.allowCoreThreadTimeOut(true);
|
||||
}
|
||||
if (this.prestartAllCoreThreads) {
|
||||
executor.prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
this.threadPoolExecutor = executor;
|
||||
return executor;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -418,11 +418,13 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register fields that should be allowed for binding. Default is all
|
||||
* fields. Restrict this for example to avoid unwanted modifications
|
||||
* by malicious users when binding HTTP request parameters.
|
||||
* <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
|
||||
* can be implemented by overriding the {@code isAllowed} method.
|
||||
* Register fields that should be allowed for binding. Default is all fields.
|
||||
* Restrict this for example to avoid unwanted modifications by malicious
|
||||
* users when binding HTTP request parameters.
|
||||
* <p>Supports "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
|
||||
* arbitrary number of pattern parts), as well as direct equality. More
|
||||
* sophisticated matching can be implemented by overriding the
|
||||
* {@code isAllowed} method.
|
||||
* <p>Alternatively, specify a list of <i>disallowed</i> fields.
|
||||
* @param allowedFields array of field names
|
||||
* @see #setDisallowedFields
|
||||
@@ -442,11 +444,13 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
}
|
||||
|
||||
/**
|
||||
* Register fields that should <i>not</i> be allowed for binding. Default is none.
|
||||
* Mark fields as disallowed for example to avoid unwanted modifications
|
||||
* by malicious users when binding HTTP request parameters.
|
||||
* <p>Supports "xxx*", "*xxx" and "*xxx*" patterns. More sophisticated matching
|
||||
* can be implemented by overriding the {@code isAllowed} method.
|
||||
* Register fields that should <i>not</i> be allowed for binding. Default
|
||||
* is none. Mark fields as disallowed for example to avoid unwanted
|
||||
* modifications by malicious users when binding HTTP request parameters.
|
||||
* <p>Supports "xxx*", "*xxx", "*xxx*" and "xxx*yyy" matches (with an
|
||||
* arbitrary number of pattern parts), as well as direct equality.
|
||||
* More sophisticated matching can be implemented by overriding the
|
||||
* {@code isAllowed} method.
|
||||
* <p>Alternatively, specify a list of <i>allowed</i> fields.
|
||||
* @param disallowedFields array of field names
|
||||
* @see #setAllowedFields
|
||||
@@ -772,10 +776,11 @@ public class DataBinder implements PropertyEditorRegistry, TypeConverter {
|
||||
/**
|
||||
* Return if the given field is allowed for binding.
|
||||
* Invoked for each passed-in property value.
|
||||
* <p>The default implementation checks for "xxx*", "*xxx" and "*xxx*" matches,
|
||||
* as well as direct equality, in the specified lists of allowed fields and
|
||||
* disallowed fields. A field matching a disallowed pattern will not be accepted
|
||||
* even if it also happens to match a pattern in the allowed list.
|
||||
* <p>The default implementation checks for "xxx*", "*xxx", "*xxx*" and "xxx*yyy"
|
||||
* matches (with an arbitrary number of pattern parts), as well as direct equality,
|
||||
* in the specified lists of allowed fields and disallowed fields. A field matching
|
||||
* a disallowed pattern will not be accepted even if it also happens to match a
|
||||
* pattern in the allowed list.
|
||||
* <p>Can be overridden in subclasses.
|
||||
* @param field the field to check
|
||||
* @return if the field is allowed
|
||||
|
||||
+34
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -65,10 +65,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIOException;
|
||||
|
||||
/**
|
||||
* @since 13.03.2003
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Chris Beams
|
||||
* @since 13.03.2003
|
||||
*/
|
||||
public class ProxyFactoryBeanTests {
|
||||
|
||||
@@ -633,20 +633,50 @@ public class ProxyFactoryBeanTests {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(FROZEN_CONTEXT, CLASS));
|
||||
|
||||
Advised advised = (Advised)bf.getBean("frozen");
|
||||
Advised advised = (Advised) bf.getBean("frozen");
|
||||
assertThat(advised.isFrozen()).as("The proxy should be frozen").isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDetectsInterfaces() throws Exception {
|
||||
public void testDetectsInterfaces() {
|
||||
ProxyFactoryBean fb = new ProxyFactoryBean();
|
||||
fb.setTarget(new TestBean());
|
||||
fb.addAdvice(new DebugInterceptor());
|
||||
fb.setBeanFactory(new DefaultListableBeanFactory());
|
||||
|
||||
ITestBean proxy = (ITestBean) fb.getObject();
|
||||
assertThat(AopUtils.isJdkDynamicProxy(proxy)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithInterceptorNames() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("debug", new DebugInterceptor());
|
||||
|
||||
ProxyFactoryBean fb = new ProxyFactoryBean();
|
||||
fb.setTarget(new TestBean());
|
||||
fb.setInterceptorNames("debug");
|
||||
fb.setBeanFactory(bf);
|
||||
|
||||
Advised proxy = (Advised) fb.getObject();
|
||||
assertThat(proxy.getAdvisorCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithLateInterceptorNames() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
bf.registerSingleton("debug", new DebugInterceptor());
|
||||
|
||||
ProxyFactoryBean fb = new ProxyFactoryBean();
|
||||
fb.setTarget(new TestBean());
|
||||
fb.setBeanFactory(bf);
|
||||
fb.getObject();
|
||||
|
||||
fb.setInterceptorNames("debug");
|
||||
Advised proxy = (Advised) fb.getObject();
|
||||
assertThat(proxy.getAdvisorCount()).isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Fires only on void methods. Saves list of methods intercepted.
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -196,7 +196,7 @@ class CommonsPool2TargetSourceTests {
|
||||
void testSetWhenExhaustedAction() {
|
||||
CommonsPool2TargetSource targetSource = new CommonsPool2TargetSource();
|
||||
targetSource.setBlockWhenExhausted(true);
|
||||
assertThat(targetSource.isBlockWhenExhausted()).isEqualTo(true);
|
||||
assertThat(targetSource.isBlockWhenExhausted()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+8
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -876,7 +876,7 @@ class XmlBeanFactoryTests {
|
||||
// should have been autowired
|
||||
assertThat(rod1.getSpouse1()).isEqualTo(kerry);
|
||||
assertThat(rod1.getAge()).isEqualTo(0);
|
||||
assertThat(rod1.getName()).isEqualTo(null);
|
||||
assertThat(rod1.getName()).isNull();
|
||||
|
||||
ConstructorDependenciesBean rod2 = (ConstructorDependenciesBean) xbf.getBean("rod2");
|
||||
TestBean kerry1 = (TestBean) xbf.getBean("kerry1");
|
||||
@@ -885,7 +885,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(rod2.getSpouse1()).isEqualTo(kerry2);
|
||||
assertThat(rod2.getSpouse2()).isEqualTo(kerry1);
|
||||
assertThat(rod2.getAge()).isEqualTo(0);
|
||||
assertThat(rod2.getName()).isEqualTo(null);
|
||||
assertThat(rod2.getName()).isNull();
|
||||
|
||||
ConstructorDependenciesBean rod = (ConstructorDependenciesBean) xbf.getBean("rod3");
|
||||
IndexedTestBean other = (IndexedTestBean) xbf.getBean("other");
|
||||
@@ -894,7 +894,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(rod.getSpouse2()).isEqualTo(kerry);
|
||||
assertThat(rod.getOther()).isEqualTo(other);
|
||||
assertThat(rod.getAge()).isEqualTo(0);
|
||||
assertThat(rod.getName()).isEqualTo(null);
|
||||
assertThat(rod.getName()).isNull();
|
||||
|
||||
xbf.getBean("rod4", ConstructorDependenciesBean.class);
|
||||
// should have been autowired
|
||||
@@ -902,7 +902,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(rod.getSpouse2()).isEqualTo(kerry);
|
||||
assertThat(rod.getOther()).isEqualTo(other);
|
||||
assertThat(rod.getAge()).isEqualTo(0);
|
||||
assertThat(rod.getName()).isEqualTo(null);
|
||||
assertThat(rod.getName()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -929,7 +929,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(rod6.getSpouse2()).isEqualTo(kerry1);
|
||||
assertThat(rod6.getOther()).isEqualTo(other);
|
||||
assertThat(rod6.getAge()).isEqualTo(0);
|
||||
assertThat(rod6.getName()).isEqualTo(null);
|
||||
assertThat(rod6.getName()).isNull();
|
||||
|
||||
xbf.destroySingletons();
|
||||
assertThat(rod6.destroyed).isTrue();
|
||||
@@ -967,7 +967,7 @@ class XmlBeanFactoryTests {
|
||||
assertThat(rod9c.getAge()).isEqualTo(97);
|
||||
|
||||
ConstructorDependenciesBean rod10 = (ConstructorDependenciesBean) xbf.getBean("rod10");
|
||||
assertThat(rod10.getName()).isEqualTo(null);
|
||||
assertThat(rod10.getName()).isNull();
|
||||
|
||||
ConstructorDependenciesBean rod11 = (ConstructorDependenciesBean) xbf.getBean("rod11");
|
||||
assertThat(rod11.getSpouse1()).isEqualTo(kerry2);
|
||||
@@ -1331,7 +1331,7 @@ class XmlBeanFactoryTests {
|
||||
|
||||
OverrideOneMethodSubclass ooms = (OverrideOneMethodSubclass) xbf.getBean("replaceVoidMethod");
|
||||
DoSomethingReplacer dos = (DoSomethingReplacer) xbf.getBean("doSomethingReplacer");
|
||||
assertThat(dos.lastArg).isEqualTo(null);
|
||||
assertThat(dos.lastArg).isNull();
|
||||
String s1 = "";
|
||||
String s2 = "foo bar black sheep";
|
||||
ooms.doSomething(s1);
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.beans.testfixture.beans.TestBean;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCache;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
@@ -306,7 +306,7 @@ public class CacheReproTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
public static class Spr13081Config extends CachingConfigurerSupport {
|
||||
public static class Spr13081Config implements CachingConfigurer {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
|
||||
Vendored
+46
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -83,6 +83,19 @@ public class EnableCachingIntegrationTests {
|
||||
assertCacheHit(key, value, cache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void barServiceWithCacheableInterfaceCglib() {
|
||||
this.context = new AnnotationConfigApplicationContext(BarConfigCglib.class);
|
||||
BarService service = this.context.getBean(BarService.class);
|
||||
Cache cache = getCache();
|
||||
|
||||
Object key = new Object();
|
||||
assertCacheMiss(key, cache);
|
||||
|
||||
Object value = service.getSimple(key);
|
||||
assertCacheHit(key, value, cache);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void beanConditionOff() {
|
||||
this.context = new AnnotationConfigApplicationContext(BeanConditionConfig.class);
|
||||
@@ -124,7 +137,7 @@ public class EnableCachingIntegrationTests {
|
||||
|
||||
|
||||
@Configuration
|
||||
static class SharedConfig extends CachingConfigurerSupport {
|
||||
static class SharedConfig implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
@@ -185,6 +198,36 @@ public class EnableCachingIntegrationTests {
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(SharedConfig.class)
|
||||
@EnableCaching(proxyTargetClass = true)
|
||||
static class BarConfigCglib {
|
||||
|
||||
@Bean
|
||||
public BarService barService() {
|
||||
return new BarServiceImpl();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
interface BarService {
|
||||
|
||||
@Cacheable(cacheNames = "testCache")
|
||||
Object getSimple(Object key);
|
||||
}
|
||||
|
||||
|
||||
static class BarServiceImpl implements BarService {
|
||||
|
||||
private final AtomicLong counter = new AtomicLong();
|
||||
|
||||
@Override
|
||||
public Object getSimple(Object key) {
|
||||
return this.counter.getAndIncrement();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
@Import(FooConfig.class)
|
||||
@EnableCaching
|
||||
|
||||
+7
-11
@@ -18,11 +18,10 @@ package org.springframework.cache.config;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.beans.factory.BeanCreationException;
|
||||
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
|
||||
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.interceptor.CacheErrorHandler;
|
||||
import org.springframework.cache.interceptor.CacheInterceptor;
|
||||
@@ -107,11 +106,8 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
try {
|
||||
ctx.refresh();
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable root = ex.getRootCause();
|
||||
boolean condition = root instanceof IllegalStateException;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(root.getMessage().contains("implementations of CachingConfigurer")).isTrue();
|
||||
catch (IllegalStateException ex) {
|
||||
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -150,7 +146,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class EnableCachingConfig extends CachingConfigurerSupport {
|
||||
static class EnableCachingConfig implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
@@ -227,7 +223,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class MultiCacheManagerConfigurer extends CachingConfigurerSupport {
|
||||
static class MultiCacheManagerConfigurer implements CachingConfigurer {
|
||||
|
||||
@Bean
|
||||
public CacheManager cm1() {
|
||||
@@ -253,7 +249,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class EmptyConfigSupportConfig extends CachingConfigurerSupport {
|
||||
static class EmptyConfigSupportConfig implements CachingConfigurer {
|
||||
|
||||
@Bean
|
||||
public CacheManager cm() {
|
||||
@@ -264,7 +260,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class FullCachingConfig extends CachingConfigurerSupport {
|
||||
static class FullCachingConfig implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
|
||||
spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* 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.
|
||||
@@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -122,7 +122,7 @@ public class ExpressionCachingIntegrationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class SharedConfig extends CachingConfigurerSupport {
|
||||
static class SharedConfig implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -28,7 +28,7 @@ import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.support.SimpleCacheManager;
|
||||
import org.springframework.cache.support.SimpleValueWrapper;
|
||||
@@ -170,7 +170,7 @@ public class CacheErrorHandlerTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends CachingConfigurerSupport {
|
||||
static class Config implements CachingConfigurer {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.CachePut;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
@@ -106,7 +106,7 @@ public class CachePutEvaluationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends CachingConfigurerSupport {
|
||||
static class Config implements CachingConfigurer {
|
||||
|
||||
@Bean
|
||||
@Override
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -29,7 +29,7 @@ import org.springframework.cache.Cache;
|
||||
import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheConfig;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -149,7 +149,7 @@ public class CacheResolverCustomizationTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends CachingConfigurerSupport {
|
||||
static class Config implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
|
||||
Vendored
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -26,7 +26,7 @@ import org.springframework.cache.CacheManager;
|
||||
import org.springframework.cache.annotation.CacheEvict;
|
||||
import org.springframework.cache.annotation.Cacheable;
|
||||
import org.springframework.cache.annotation.Caching;
|
||||
import org.springframework.cache.annotation.CachingConfigurerSupport;
|
||||
import org.springframework.cache.annotation.CachingConfigurer;
|
||||
import org.springframework.cache.annotation.EnableCaching;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
@@ -133,7 +133,7 @@ public class CacheSyncFailureTests {
|
||||
|
||||
@Configuration
|
||||
@EnableCaching
|
||||
static class Config extends CachingConfigurerSupport {
|
||||
static class Config implements CachingConfigurer {
|
||||
|
||||
@Override
|
||||
@Bean
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,7 +47,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
public void primitiveLookupByName() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean("b", boolean.class);
|
||||
assertThat(b).isEqualTo(true);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean("i", int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
}
|
||||
@@ -56,7 +56,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
public void primitiveLookupByType() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class);
|
||||
boolean b = ctx.getBean(boolean.class);
|
||||
assertThat(b).isEqualTo(true);
|
||||
assertThat(b).isTrue();
|
||||
int i = ctx.getBean(int.class);
|
||||
assertThat(i).isEqualTo(42);
|
||||
}
|
||||
@@ -65,7 +65,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
public void primitiveAutowiredInjection() {
|
||||
ApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, AutowiredComponent.class);
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).b).isEqualTo(true);
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(AutowiredComponent.class).i).isEqualTo(42);
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ public class PrimitiveBeanLookupAndAutowiringTests {
|
||||
public void primitiveResourceInjection() {
|
||||
ApplicationContext ctx =
|
||||
new AnnotationConfigApplicationContext(Config.class, ResourceComponent.class);
|
||||
assertThat(ctx.getBean(ResourceComponent.class).b).isEqualTo(true);
|
||||
assertThat(ctx.getBean(ResourceComponent.class).b).isTrue();
|
||||
assertThat(ctx.getBean(ResourceComponent.class).i).isEqualTo(42);
|
||||
}
|
||||
|
||||
|
||||
+3
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.expression.spel.standard.SpelExpressionParser;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
|
||||
import static org.mockito.Mockito.spy;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
@@ -43,7 +44,7 @@ public class CachedExpressionEvaluatorTests {
|
||||
Method method = ReflectionUtils.findMethod(getClass(), "toString");
|
||||
Expression expression = expressionEvaluator.getTestExpression("true", method, getClass());
|
||||
hasParsedExpression("true");
|
||||
assertThat(expression.getValue()).isEqualTo(true);
|
||||
assertThat(expression.getValue()).asInstanceOf(BOOLEAN).isTrue();
|
||||
assertThat(expressionEvaluator.testCache.size()).as("Expression should be in cache").isEqualTo(1);
|
||||
}
|
||||
|
||||
|
||||
+5
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -25,6 +25,7 @@ import org.springframework.core.ParameterNameDiscoverer;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.BOOLEAN;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link MethodBasedEvaluationContext}.
|
||||
@@ -47,9 +48,9 @@ public class MethodBasedEvaluationContextTests {
|
||||
assertThat(context.lookupVariable("p0")).isEqualTo("test");
|
||||
assertThat(context.lookupVariable("foo")).isEqualTo("test");
|
||||
|
||||
assertThat(context.lookupVariable("a1")).isEqualTo(true);
|
||||
assertThat(context.lookupVariable("p1")).isEqualTo(true);
|
||||
assertThat(context.lookupVariable("flag")).isEqualTo(true);
|
||||
assertThat(context.lookupVariable("a1")).asInstanceOf(BOOLEAN).isTrue();
|
||||
assertThat(context.lookupVariable("p1")).asInstanceOf(BOOLEAN).isTrue();
|
||||
assertThat(context.lookupVariable("flag")).asInstanceOf(BOOLEAN).isTrue();
|
||||
|
||||
assertThat(context.lookupVariable("a2")).isNull();
|
||||
assertThat(context.lookupVariable("p2")).isNull();
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -345,7 +345,7 @@ public class PropertySourcesPlaceholderConfigurerTests {
|
||||
.addPropertyValue("jedi", "${jedi:false}")
|
||||
.getBeanDefinition());
|
||||
ppc.postProcessBeanFactory(bf);
|
||||
assertThat(bf.getBean(TestBean.class).isJedi()).isEqualTo(true);
|
||||
assertThat(bf.getBean(TestBean.class).isJedi()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -281,7 +281,7 @@ public class FormattingConversionServiceTests {
|
||||
@Test
|
||||
public void printNullDefault() {
|
||||
assertThat(formattingService
|
||||
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isEqualTo(null);
|
||||
.convert(null, TypeDescriptor.valueOf(Integer.class), TypeDescriptor.valueOf(String.class))).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -42,7 +42,7 @@ public class JndiLocatorDelegateTests {
|
||||
builderField.set(null, null);
|
||||
|
||||
try {
|
||||
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isEqualTo(false);
|
||||
assertThat(JndiLocatorDelegate.isDefaultJndiEnvironmentAvailable()).isFalse();
|
||||
}
|
||||
finally {
|
||||
builderField.set(null, oldBuilder);
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -218,8 +218,8 @@ public class AsyncAnnotationBeanPostProcessorTests {
|
||||
private void assertFutureWithException(Future<Object> result,
|
||||
TestableAsyncUncaughtExceptionHandler exceptionHandler) {
|
||||
assertThatExceptionOfType(ExecutionException.class).isThrownBy(
|
||||
result::get)
|
||||
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
|
||||
result::get)
|
||||
.withCauseExactlyInstanceOf(UnsupportedOperationException.class);
|
||||
assertThat(exceptionHandler.isCalled()).as("handler should never be called with Future return type").isFalse();
|
||||
}
|
||||
|
||||
@@ -343,7 +343,7 @@ public class AsyncAnnotationBeanPostProcessorTests {
|
||||
|
||||
@Configuration
|
||||
@EnableAsync
|
||||
static class ConfigWithExceptionHandler extends AsyncConfigurerSupport {
|
||||
static class ConfigWithExceptionHandler implements AsyncConfigurer {
|
||||
|
||||
@Bean
|
||||
public ITestBean target() {
|
||||
|
||||
+45
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,8 +16,12 @@
|
||||
|
||||
package org.springframework.scheduling.concurrent;
|
||||
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.FutureTask;
|
||||
import java.util.concurrent.RejectedExecutionHandler;
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
@@ -25,10 +29,16 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.support.GenericApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
||||
/**
|
||||
* Tests for {@link ThreadPoolExecutorFactoryBean}.
|
||||
*
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
class ThreadPoolExecutorFactoryBeanTests {
|
||||
@@ -44,6 +54,28 @@ class ThreadPoolExecutorFactoryBeanTests {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
void executorWithDefaultSettingsDoesNotPrestartAllCoreThreads() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("taskExecutor", ThreadPoolExecutorFactoryBean.class, TestThreadPoolExecutorFactoryBean::new);
|
||||
context.refresh();
|
||||
ThreadPoolExecutor threadPoolExecutor = context.getBean(ThreadPoolExecutor.class);
|
||||
verify(threadPoolExecutor, never()).prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
@Test
|
||||
void executorWithPrestartAllCoreThreads() {
|
||||
GenericApplicationContext context = new GenericApplicationContext();
|
||||
context.registerBean("taskExecutor", ThreadPoolExecutorFactoryBean.class, () -> {
|
||||
TestThreadPoolExecutorFactoryBean factoryBean = new TestThreadPoolExecutorFactoryBean();
|
||||
factoryBean.setPrestartAllCoreThreads(true);
|
||||
return factoryBean;
|
||||
});
|
||||
context.refresh();
|
||||
ThreadPoolExecutor threadPoolExecutor = context.getBean(ThreadPoolExecutor.class);
|
||||
verify(threadPoolExecutor).prestartAllCoreThreads();
|
||||
}
|
||||
|
||||
|
||||
@Configuration
|
||||
static class ExecutorConfig {
|
||||
@@ -52,7 +84,19 @@ class ThreadPoolExecutorFactoryBeanTests {
|
||||
ThreadPoolExecutorFactoryBean executor() {
|
||||
return new ThreadPoolExecutorFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
private static class TestThreadPoolExecutorFactoryBean extends ThreadPoolExecutorFactoryBean {
|
||||
|
||||
@Override
|
||||
protected ThreadPoolExecutor createExecutor(
|
||||
int corePoolSize, int maxPoolSize, int keepAliveSeconds, BlockingQueue<Runnable> queue,
|
||||
ThreadFactory threadFactory, RejectedExecutionHandler rejectedExecutionHandler) {
|
||||
|
||||
return mock(ThreadPoolExecutor.class);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -57,7 +57,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertThat(getMaxPoolSize(executor)).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
|
||||
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
||||
|
||||
FutureTask<String> task = new FutureTask<>(new Callable<String>() {
|
||||
@Override
|
||||
@@ -96,7 +96,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertThat(getCorePoolSize(executor)).isEqualTo(9);
|
||||
assertThat(getMaxPoolSize(executor)).isEqualTo(9);
|
||||
assertThat(getKeepAliveSeconds(executor)).isEqualTo(37);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
|
||||
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@@ -106,7 +106,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
assertThat(getCorePoolSize(executor)).isEqualTo(123);
|
||||
assertThat(getMaxPoolSize(executor)).isEqualTo(123);
|
||||
assertThat(getKeepAliveSeconds(executor)).isEqualTo(60);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
||||
assertThat(getQueueCapacity(executor)).isEqualTo(Integer.MAX_VALUE);
|
||||
}
|
||||
|
||||
@@ -115,7 +115,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
Object executor = this.context.getBean("propertyPlaceholderWithRange");
|
||||
assertThat(getCorePoolSize(executor)).isEqualTo(5);
|
||||
assertThat(getMaxPoolSize(executor)).isEqualTo(25);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(false);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isFalse();
|
||||
assertThat(getQueueCapacity(executor)).isEqualTo(10);
|
||||
}
|
||||
|
||||
@@ -124,7 +124,7 @@ public class ExecutorBeanDefinitionParserTests {
|
||||
Object executor = this.context.getBean("propertyPlaceholderWithRangeAndCoreThreadTimeout");
|
||||
assertThat(getCorePoolSize(executor)).isEqualTo(99);
|
||||
assertThat(getMaxPoolSize(executor)).isEqualTo(99);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isEqualTo(true);
|
||||
assertThat(getAllowCoreThreadTimeOut(executor)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -1242,7 +1242,7 @@ class DataBinderTests {
|
||||
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("NOT_ROD.java.lang.String");
|
||||
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("NOT_ROD");
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
|
||||
|
||||
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
|
||||
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
|
||||
@@ -1314,7 +1314,7 @@ class DataBinderTests {
|
||||
assertThat(errors.getFieldError("name").getCodes()[2]).isEqualTo("validation.NOT_ROD.java.lang.String");
|
||||
assertThat(errors.getFieldError("name").getCodes()[3]).isEqualTo("validation.NOT_ROD");
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getField()).isEqualTo("name");
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isEqualTo(null);
|
||||
assertThat((errors.getFieldErrors("name").get(0)).getRejectedValue()).isNull();
|
||||
|
||||
assertThat(errors.hasFieldErrors("spouse.age")).isTrue();
|
||||
assertThat(errors.getFieldErrorCount("spouse.age")).isEqualTo(1);
|
||||
@@ -1339,7 +1339,7 @@ class DataBinderTests {
|
||||
assertThat(errors.getFieldErrorCount("spouse")).isEqualTo(1);
|
||||
assertThat(errors.getFieldError("spouse").getCode()).isEqualTo("SPOUSE_NOT_AVAILABLE");
|
||||
assertThat((errors.getFieldErrors("spouse").get(0)).getObjectName()).isEqualTo("tb");
|
||||
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isEqualTo(null);
|
||||
assertThat((errors.getFieldErrors("spouse").get(0)).getRejectedValue()).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -194,7 +194,7 @@ public class ClassReader {
|
||||
this.b = classFileBuffer;
|
||||
// Check the class' major_version. This field is after the magic and minor_version fields, which
|
||||
// use 4 and 2 bytes respectively.
|
||||
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V18) {
|
||||
if (checkClassVersion && readShort(classFileOffset + 6) > Opcodes.V19) {
|
||||
throw new IllegalArgumentException(
|
||||
"Unsupported class file major version " + readShort(classFileOffset + 6));
|
||||
}
|
||||
|
||||
@@ -283,6 +283,7 @@ public interface Opcodes {
|
||||
int V16 = 0 << 16 | 60;
|
||||
int V17 = 0 << 16 | 61;
|
||||
int V18 = 0 << 16 | 62;
|
||||
int V19 = 0 << 16 | 63;
|
||||
|
||||
/**
|
||||
* Version flag indicating that the class is using 'preview' features.
|
||||
|
||||
+3
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -101,6 +101,8 @@ public class LocalVariableTableParameterNameDiscoverer implements ParameterNameD
|
||||
}
|
||||
return NO_DEBUG_INFO_MAP;
|
||||
}
|
||||
// We cannot use try-with-resources here for the InputStream, since we have
|
||||
// custom handling of the close() method in a finally-block.
|
||||
try {
|
||||
ClassReader classReader = new ClassReader(is);
|
||||
Map<Executable, String[]> map = new ConcurrentHashMap<>(32);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -48,11 +48,11 @@ import org.springframework.util.StringUtils;
|
||||
* {@link #getGeneric(int...) generic parameters} along with the ability to ultimately
|
||||
* {@link #resolve() resolve} to a {@link java.lang.Class}.
|
||||
*
|
||||
* <p>{@code ResolvableTypes} may be obtained from {@link #forField(Field) fields},
|
||||
* {@link #forMethodParameter(Method, int) method parameters},
|
||||
* {@link #forMethodReturnType(Method) method returns} or
|
||||
* {@link #forClass(Class) classes}. Most methods on this class will themselves return
|
||||
* {@link ResolvableType ResolvableTypes}, allowing easy navigation. For example:
|
||||
* <p>A {@code ResolvableType} may be obtained from a {@linkplain #forField(Field) field},
|
||||
* a {@linkplain #forMethodParameter(Method, int) method parameter},
|
||||
* a {@linkplain #forMethodReturnType(Method) method return type}, or a
|
||||
* {@linkplain #forClass(Class) class}. Most methods on this class will themselves return
|
||||
* a {@code ResolvableType}, allowing for easy navigation. For example:
|
||||
* <pre class="code">
|
||||
* private HashMap<Integer, List<String>> myMap;
|
||||
*
|
||||
@@ -182,7 +182,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Private constructor used to create a new {@link ResolvableType} on a {@link Class} basis.
|
||||
* Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
|
||||
* <p>Avoids all {@code instanceof} checks in order to create a straight {@link Class} wrapper.
|
||||
* @since 4.2
|
||||
*/
|
||||
private ResolvableType(@Nullable Class<?> clazz) {
|
||||
@@ -406,7 +406,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Convenience method to return this type as a resolvable {@link Collection} type.
|
||||
* Returns {@link #NONE} if this type does not implement or extend
|
||||
* <p>Returns {@link #NONE} if this type does not implement or extend
|
||||
* {@link Collection}.
|
||||
* @see #as(Class)
|
||||
* @see #asMap()
|
||||
@@ -417,7 +417,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Convenience method to return this type as a resolvable {@link Map} type.
|
||||
* Returns {@link #NONE} if this type does not implement or extend
|
||||
* <p>Returns {@link #NONE} if this type does not implement or extend
|
||||
* {@link Map}.
|
||||
* @see #as(Class)
|
||||
* @see #asCollection()
|
||||
@@ -458,7 +458,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Return a {@link ResolvableType} representing the direct supertype of this type.
|
||||
* If no supertype is available this method returns {@link #NONE}.
|
||||
* <p>If no supertype is available this method returns {@link #NONE}.
|
||||
* <p>Note: The resulting {@link ResolvableType} instance may not be {@link Serializable}.
|
||||
* @see #getInterfaces()
|
||||
*/
|
||||
@@ -608,7 +608,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified nesting level.
|
||||
* See {@link #getNested(int, Map)} for details.
|
||||
* <p>See {@link #getNested(int, Map)} for details.
|
||||
* @param nestingLevel the nesting level
|
||||
* @return the {@link ResolvableType} type, or {@code #NONE}
|
||||
*/
|
||||
@@ -999,7 +999,7 @@ public class ResolvableType implements Serializable {
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified {@link Class},
|
||||
* using the full generic type information for assignability checks.
|
||||
* For example: {@code ResolvableType.forClass(MyArrayList.class)}.
|
||||
* <p>For example: {@code ResolvableType.forClass(MyArrayList.class)}.
|
||||
* @param clazz the class to introspect ({@code null} is semantically
|
||||
* equivalent to {@code Object.class} for typical use cases here)
|
||||
* @return a {@link ResolvableType} for the specified class
|
||||
@@ -1014,7 +1014,7 @@ public class ResolvableType implements Serializable {
|
||||
* Return a {@link ResolvableType} for the specified {@link Class},
|
||||
* doing assignability checks against the raw class only (analogous to
|
||||
* {@link Class#isAssignableFrom}, which this serves as a wrapper for.
|
||||
* For example: {@code ResolvableType.forRawClass(List.class)}.
|
||||
* <p>For example: {@code ResolvableType.forRawClass(List.class)}.
|
||||
* @param clazz the class to introspect ({@code null} is semantically
|
||||
* equivalent to {@code Object.class} for typical use cases here)
|
||||
* @return a {@link ResolvableType} for the specified class
|
||||
@@ -1043,7 +1043,7 @@ public class ResolvableType implements Serializable {
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified base type
|
||||
* (interface or base class) with a given implementation class.
|
||||
* For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
|
||||
* <p>For example: {@code ResolvableType.forClass(List.class, MyArrayList.class)}.
|
||||
* @param baseType the base type (must not be {@code null})
|
||||
* @param implementationClass the implementation class
|
||||
* @return a {@link ResolvableType} for the specified base type backed by the
|
||||
@@ -1085,7 +1085,7 @@ public class ResolvableType implements Serializable {
|
||||
Assert.notNull(clazz, "Class must not be null");
|
||||
Assert.notNull(generics, "Generics array must not be null");
|
||||
TypeVariable<?>[] variables = clazz.getTypeParameters();
|
||||
Assert.isTrue(variables.length == generics.length, "Mismatched number of generics specified");
|
||||
Assert.isTrue(variables.length == generics.length, () -> "Mismatched number of generics specified for " + clazz.toGenericString());
|
||||
|
||||
Type[] arguments = new Type[generics.length];
|
||||
for (int i = 0; i < generics.length; i++) {
|
||||
@@ -1238,7 +1238,7 @@ public class ResolvableType implements Serializable {
|
||||
|
||||
/**
|
||||
* Return a {@link ResolvableType} for the specified {@link Method} return type.
|
||||
* Use this variant when the class that declares the method includes generic
|
||||
* <p>Use this variant when the class that declares the method includes generic
|
||||
* parameter variables that are satisfied by the implementation class.
|
||||
* @param method the source for the method return type
|
||||
* @param implementationClass the implementation class
|
||||
|
||||
@@ -17,10 +17,12 @@
|
||||
package org.springframework.core.log;
|
||||
|
||||
import java.util.function.Function;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Utility methods for formatting and logging messages.
|
||||
@@ -35,10 +37,15 @@ import org.springframework.lang.Nullable;
|
||||
*/
|
||||
public abstract class LogFormatUtils {
|
||||
|
||||
private static final Pattern NEWLINE_PATTERN = Pattern.compile("[\n\r]");
|
||||
|
||||
private static final Pattern CONTROL_CHARACTER_PATTERN = Pattern.compile("\\p{Cc}");
|
||||
|
||||
|
||||
/**
|
||||
* Convenience variant of {@link #formatValue(Object, int, boolean)} that
|
||||
* limits the length of a log message to 100 characters and also replaces
|
||||
* newline characters if {@code limitLength} is set to "true".
|
||||
* newline and control characters if {@code limitLength} is set to "true".
|
||||
* @param value the value to format
|
||||
* @param limitLength whether to truncate the value at a length of 100
|
||||
* @return the formatted value
|
||||
@@ -53,25 +60,29 @@ public abstract class LogFormatUtils {
|
||||
* compacting it into a single line when {@code replaceNewLines} is set.
|
||||
* @param value the value to be formatted
|
||||
* @param maxLength the max length, after which to truncate, or -1 for unlimited
|
||||
* @param replaceNewlines whether to replace newline characters with placeholders
|
||||
* @param replaceNewlinesAndControlCharacters whether to replace newline and
|
||||
* control characters with placeholders
|
||||
* @return the formatted value
|
||||
*/
|
||||
public static String formatValue(@Nullable Object value, int maxLength, boolean replaceNewlines) {
|
||||
public static String formatValue(
|
||||
@Nullable Object value, int maxLength, boolean replaceNewlinesAndControlCharacters) {
|
||||
|
||||
if (value == null) {
|
||||
return "";
|
||||
}
|
||||
String result;
|
||||
try {
|
||||
result = value.toString();
|
||||
result = ObjectUtils.nullSafeToString(value);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
result = ex.toString();
|
||||
result = ObjectUtils.nullSafeToString(ex);
|
||||
}
|
||||
if (maxLength != -1) {
|
||||
result = (result.length() > maxLength ? result.substring(0, maxLength) + " (truncated)..." : result);
|
||||
}
|
||||
if (replaceNewlines) {
|
||||
result = result.replace("\n", "<LF>").replace("\r", "<CR>");
|
||||
if (replaceNewlinesAndControlCharacters) {
|
||||
result = NEWLINE_PATTERN.matcher(result).replaceAll("<EOL>");
|
||||
result = CONTROL_CHARACTER_PATTERN.matcher(result).replaceAll("?");
|
||||
}
|
||||
if (value instanceof CharSequence) {
|
||||
result = "\"" + result + "\"";
|
||||
|
||||
+1
-1
@@ -162,7 +162,7 @@ public class StandardAnnotationMetadata extends StandardClassMetadata implements
|
||||
throw new IllegalStateException("Failed to introspect annotated methods on " + getIntrospectedClass(), ex);
|
||||
}
|
||||
}
|
||||
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
|
||||
return (annotatedMethods != null ? annotatedMethods : Collections.emptySet());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-5
@@ -127,6 +127,11 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata {
|
||||
return this.memberClassNames.clone();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedAnnotations getAnnotations() {
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Set<String> getAnnotationTypes() {
|
||||
Set<String> annotationTypes = this.annotationTypes;
|
||||
@@ -149,13 +154,9 @@ final class SimpleAnnotationMetadata implements AnnotationMetadata {
|
||||
annotatedMethods.add(annotatedMethod);
|
||||
}
|
||||
}
|
||||
return annotatedMethods != null ? annotatedMethods : Collections.emptySet();
|
||||
return (annotatedMethods != null ? annotatedMethods : Collections.emptySet());
|
||||
}
|
||||
|
||||
@Override
|
||||
public MergedAnnotations getAnnotations() {
|
||||
return this.annotations;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object obj) {
|
||||
|
||||
+2
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -99,8 +99,7 @@ final class SimpleAnnotationMetadataReadingVisitor extends ClassVisitor {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void visitInnerClass(String name, @Nullable String outerName, String innerName,
|
||||
int access) {
|
||||
public void visitInnerClass(String name, @Nullable String outerName, String innerName, int access) {
|
||||
if (outerName != null) {
|
||||
String className = toClassName(name);
|
||||
String outerClassName = toClassName(outerName);
|
||||
|
||||
@@ -733,6 +733,10 @@ public class AntPathMatcher implements PathMatcher {
|
||||
}
|
||||
for (int i = 1; i <= matcher.groupCount(); i++) {
|
||||
String name = this.variableNames.get(i - 1);
|
||||
if (name.startsWith("*")) {
|
||||
throw new IllegalArgumentException("Capturing patterns (" + name + ") are not " +
|
||||
"supported by the AntPathMatcher. Use the PathPatternParser instead.");
|
||||
}
|
||||
String value = matcher.group(i);
|
||||
uriTemplateVariables.put(name, value);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,8 @@ class GenericTypeResolverTests {
|
||||
void methodReturnTypes() {
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "integer"), MyInterfaceType.class)).isEqualTo(Integer.class);
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "string"), MyInterfaceType.class)).isEqualTo(String.class);
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isEqualTo(null);
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isEqualTo(null);
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "raw"), MyInterfaceType.class)).isNull();
|
||||
assertThat(resolveReturnTypeArgument(findMethod(MyTypeWithMethods.class, "object"), MyInterfaceType.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -370,9 +370,9 @@ class ReactiveAdapterRegistryTests {
|
||||
|
||||
@Test
|
||||
void deferred() {
|
||||
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isEqualTo(false);
|
||||
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isEqualTo(true);
|
||||
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isEqualTo(true);
|
||||
assertThat(getAdapter(CompletableFuture.class).getDescriptor().isDeferred()).isFalse();
|
||||
assertThat(getAdapter(Deferred.class).getDescriptor().isDeferred()).isTrue();
|
||||
assertThat(getAdapter(kotlinx.coroutines.flow.Flow.class).getDescriptor().isDeferred()).isTrue();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -83,19 +83,19 @@ class ResolvableTypeTests {
|
||||
assertThat(none.asMap()).isEqualTo(ResolvableType.NONE);
|
||||
assertThat(none.getComponentType()).isEqualTo(ResolvableType.NONE);
|
||||
assertThat(none.getGeneric(0)).isEqualTo(ResolvableType.NONE);
|
||||
assertThat(none.getGenerics().length).isEqualTo(0);
|
||||
assertThat(none.getInterfaces().length).isEqualTo(0);
|
||||
assertThat(none.getGenerics()).isEmpty();
|
||||
assertThat(none.getInterfaces()).isEmpty();
|
||||
assertThat(none.getSuperType()).isEqualTo(ResolvableType.NONE);
|
||||
assertThat(none.getType()).isEqualTo(ResolvableType.EmptyType.INSTANCE);
|
||||
assertThat(none.hasGenerics()).isEqualTo(false);
|
||||
assertThat(none.isArray()).isEqualTo(false);
|
||||
assertThat(none.hasGenerics()).isFalse();
|
||||
assertThat(none.isArray()).isFalse();
|
||||
assertThat(none.resolve()).isNull();
|
||||
assertThat(none.resolve(String.class)).isEqualTo(String.class);
|
||||
assertThat(none.resolveGeneric(0)).isNull();
|
||||
assertThat(none.resolveGenerics().length).isEqualTo(0);
|
||||
assertThat(none.resolveGenerics()).isEmpty();
|
||||
assertThat(none.toString()).isEqualTo("?");
|
||||
assertThat(none.hasUnresolvableGenerics()).isEqualTo(false);
|
||||
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isEqualTo(false);
|
||||
assertThat(none.hasUnresolvableGenerics()).isFalse();
|
||||
assertThat(none.isAssignableFrom(ResolvableType.forClass(Object.class))).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -148,9 +148,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forInstanceMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forInstance(null))
|
||||
.withMessageContaining("Instance must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forInstance(null))
|
||||
.withMessage("Instance must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,9 +201,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forFieldMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forField(null))
|
||||
.withMessageContaining("Field must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forField(null))
|
||||
.withMessage("Field must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -215,9 +215,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forConstructorParameterMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forConstructorParameter(null, 0))
|
||||
.withMessageContaining("Constructor must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forConstructorParameter(null, 0))
|
||||
.withMessage("Constructor must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -229,9 +229,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forMethodParameterByIndexMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forMethodParameter(null, 0))
|
||||
.withMessageContaining("Method must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forMethodParameter(null, 0))
|
||||
.withMessage("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -269,9 +269,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forMethodParameterMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forMethodParameter(null))
|
||||
.withMessageContaining("MethodParameter must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forMethodParameter(null))
|
||||
.withMessage("MethodParameter must not be null");
|
||||
}
|
||||
|
||||
@Test // SPR-16210
|
||||
@@ -296,9 +296,9 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forMethodReturnMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forMethodReturnType(null))
|
||||
.withMessageContaining("Method must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forMethodReturnType(null))
|
||||
.withMessage("Method must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -317,7 +317,7 @@ class ResolvableTypeTests {
|
||||
void arrayClassType() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("arrayClassType"));
|
||||
assertThat(type.getType()).isInstanceOf(Class.class);
|
||||
assertThat(((Class) type.getType()).isArray()).isEqualTo(true);
|
||||
assertThat(((Class) type.getType()).isArray()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -343,7 +343,7 @@ class ResolvableTypeTests {
|
||||
void getComponentTypeForClassArray() throws Exception {
|
||||
Field field = Fields.class.getField("arrayClassType");
|
||||
ResolvableType type = ResolvableType.forField(field);
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.getComponentType().getType())
|
||||
.isEqualTo(((Class) field.getGenericType()).getComponentType());
|
||||
}
|
||||
@@ -351,7 +351,7 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void getComponentTypeForGenericArrayType() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("genericArrayType"));
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.getComponentType().getType()).isEqualTo(
|
||||
((GenericArrayType) type.getType()).getGenericComponentType());
|
||||
}
|
||||
@@ -359,7 +359,7 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void getComponentTypeForVariableThatResolvesToGenericArray() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(ListOfGenericArray.class).asCollection().getGeneric();
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.getType()).isInstanceOf(TypeVariable.class);
|
||||
assertThat(type.getComponentType().getType().toString()).isEqualTo(
|
||||
"java.util.List<java.lang.String>");
|
||||
@@ -368,7 +368,7 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void getComponentTypeForNonArray() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(String.class);
|
||||
assertThat(type.isArray()).isEqualTo(false);
|
||||
assertThat(type.isArray()).isFalse();
|
||||
assertThat(type.getComponentType()).isEqualTo(ResolvableType.NONE);
|
||||
}
|
||||
|
||||
@@ -438,7 +438,7 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void getInterfaces() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
|
||||
assertThat(type.getInterfaces().length).isEqualTo(0);
|
||||
assertThat(type.getInterfaces()).isEmpty();
|
||||
SortedSet<String> interfaces = new TreeSet<>();
|
||||
for (ResolvableType interfaceType : type.getSuperType().getInterfaces()) {
|
||||
interfaces.add(interfaceType.toString());
|
||||
@@ -529,8 +529,8 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void hasGenerics() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
|
||||
assertThat(type.hasGenerics()).isEqualTo(false);
|
||||
assertThat(type.asCollection().hasGenerics()).isEqualTo(true);
|
||||
assertThat(type.hasGenerics()).isFalse();
|
||||
assertThat(type.asCollection().hasGenerics()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -553,7 +553,7 @@ class ResolvableTypeTests {
|
||||
void noGetGenerics() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(ExtendsList.class);
|
||||
ResolvableType[] generics = type.getGenerics();
|
||||
assertThat(generics.length).isEqualTo(0);
|
||||
assertThat(generics).isEmpty();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -602,7 +602,7 @@ class ResolvableTypeTests {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringArrayList"));
|
||||
ResolvableType generic = type.asCollection().getGeneric();
|
||||
assertThat(generic.getType().toString()).isEqualTo("E");
|
||||
assertThat(generic.isArray()).isEqualTo(true);
|
||||
assertThat(generic.isArray()).isTrue();
|
||||
assertThat(generic.resolve()).isEqualTo(String[].class);
|
||||
}
|
||||
|
||||
@@ -610,7 +610,7 @@ class ResolvableTypeTests {
|
||||
void resolveVariableGenericArray() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"), TypedFields.class);
|
||||
assertThat(type.getType().toString()).isEqualTo("T[]");
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.resolve()).isEqualTo(String[].class);
|
||||
}
|
||||
|
||||
@@ -618,7 +618,7 @@ class ResolvableTypeTests {
|
||||
void resolveVariableGenericArrayUnknown() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
|
||||
assertThat(type.getType().toString()).isEqualTo("T[]");
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.resolve()).isNull();
|
||||
}
|
||||
|
||||
@@ -626,7 +626,7 @@ class ResolvableTypeTests {
|
||||
void resolveVariableGenericArrayUnknownWithFallback() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("variableTypeGenericArray"));
|
||||
assertThat(type.getType().toString()).isEqualTo("T[]");
|
||||
assertThat(type.isArray()).isEqualTo(true);
|
||||
assertThat(type.isArray()).isTrue();
|
||||
assertThat(type.toClass()).isEqualTo(Object.class);
|
||||
}
|
||||
|
||||
@@ -965,16 +965,16 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void isAssignableFromMustNotBeNull() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
|
||||
.withMessageContaining("Type must not be null");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forClass(Object.class).isAssignableFrom((ResolvableType) null))
|
||||
.withMessage("ResolvableType must not be null");
|
||||
}
|
||||
|
||||
@Test
|
||||
void isAssignableFromForNone() throws Exception {
|
||||
ResolvableType objectType = ResolvableType.forClass(Object.class);
|
||||
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isEqualTo(false);
|
||||
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isEqualTo(false);
|
||||
assertThat(objectType.isAssignableFrom(ResolvableType.NONE)).isFalse();
|
||||
assertThat(ResolvableType.NONE.isAssignableFrom(objectType)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1159,6 +1159,20 @@ class ResolvableTypeTests {
|
||||
assertThatResolvableType(complex4).isNotAssignableFrom(complex3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void identifyTypeVariable() throws Exception {
|
||||
Method method = ClassArguments.class.getMethod("typedArgumentFirst", Class.class, Class.class, Class.class);
|
||||
ResolvableType returnType = ResolvableType.forMethodReturnType(method, ClassArguments.class);
|
||||
|
||||
ResolvableType arg0 = ResolvableType.forMethodParameter(method, 0, ClassArguments.class);
|
||||
ResolvableType arg1 = ResolvableType.forMethodParameter(method, 1, ClassArguments.class);
|
||||
ResolvableType arg2 = ResolvableType.forMethodParameter(method, 2, ClassArguments.class);
|
||||
|
||||
assertThat(returnType.getType().equals(arg0.as(Class.class).getGeneric(0).getType())).isTrue();
|
||||
assertThat(returnType.getType().equals(arg1.as(Class.class).getGeneric(0).getType())).isFalse();
|
||||
assertThat(returnType.getType().equals(arg2.as(Class.class).getGeneric(0).getType())).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hashCodeAndEquals() throws Exception {
|
||||
ResolvableType forClass = ResolvableType.forClass(List.class);
|
||||
@@ -1207,9 +1221,10 @@ class ResolvableTypeTests {
|
||||
|
||||
@Test
|
||||
void forClassWithMismatchedGenerics() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
ResolvableType.forClassWithGenerics(Map.class, Integer.class))
|
||||
.withMessageContaining("Mismatched number of generics specified");
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(() -> ResolvableType.forClassWithGenerics(Map.class, Integer.class))
|
||||
.withMessageContaining("Mismatched number of generics specified for")
|
||||
.withMessageContaining("java.util.Map<K,V>");
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1248,19 +1263,19 @@ class ResolvableTypeTests {
|
||||
@Test
|
||||
void hasUnresolvableGenerics() throws Exception {
|
||||
ResolvableType type = ResolvableType.forField(Fields.class.getField("stringList"));
|
||||
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
|
||||
assertThat(type.hasUnresolvableGenerics()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasUnresolvableGenericsBasedOnOwnGenerics() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(List.class);
|
||||
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
|
||||
assertThat(type.hasUnresolvableGenerics()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasUnresolvableGenericsWhenSelfNotResolvable() throws Exception {
|
||||
ResolvableType type = ResolvableType.forClass(List.class).getGeneric();
|
||||
assertThat(type.hasUnresolvableGenerics()).isEqualTo(false);
|
||||
assertThat(type.hasUnresolvableGenerics()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1269,7 +1284,7 @@ class ResolvableTypeTests {
|
||||
for (ResolvableType generic : type.getGenerics()) {
|
||||
assertThat(generic.resolve()).isNotNull();
|
||||
}
|
||||
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
|
||||
assertThat(type.hasUnresolvableGenerics()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1278,7 +1293,7 @@ class ResolvableTypeTests {
|
||||
for (ResolvableType generic : type.getGenerics()) {
|
||||
assertThat(generic.resolve()).isNotNull();
|
||||
}
|
||||
assertThat(type.hasUnresolvableGenerics()).isEqualTo(true);
|
||||
assertThat(type.hasUnresolvableGenerics()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -1427,6 +1442,10 @@ class ResolvableTypeTests {
|
||||
}
|
||||
|
||||
|
||||
interface TypedMethods extends Methods<String> {
|
||||
}
|
||||
|
||||
|
||||
static class AssignmentBase<O, C, S> {
|
||||
|
||||
public O o;
|
||||
@@ -1479,7 +1498,9 @@ class ResolvableTypeTests {
|
||||
}
|
||||
|
||||
|
||||
interface TypedMethods extends Methods<String> {
|
||||
interface ClassArguments {
|
||||
|
||||
<T> T typedArgumentFirst(Class<T> arg0, Class<?> arg1, Class<Object> arg2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,8 +60,8 @@ class AnnotationAttributesTests {
|
||||
|
||||
assertThat(attributes.getString("name")).isEqualTo("dave");
|
||||
assertThat(attributes.getStringArray("names")).isEqualTo(new String[] {"dave", "frank", "hal"});
|
||||
assertThat(attributes.getBoolean("bool1")).isEqualTo(true);
|
||||
assertThat(attributes.getBoolean("bool2")).isEqualTo(false);
|
||||
assertThat(attributes.getBoolean("bool1")).isTrue();
|
||||
assertThat(attributes.getBoolean("bool2")).isFalse();
|
||||
assertThat(attributes.<Color>getEnum("color")).isEqualTo(Color.RED);
|
||||
assertThat(attributes.getClass("class").equals(Integer.class)).isTrue();
|
||||
assertThat(attributes.getClassArray("classes")).isEqualTo(new Class<?>[] {Number.class, Short.class, Integer.class});
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -257,7 +257,7 @@ class MissingMergedAnnotationTests {
|
||||
|
||||
@Test
|
||||
void synthesizeThrowsNoSuchElementException() {
|
||||
assertThatNoSuchElementException().isThrownBy(() -> this.missing.synthesize());
|
||||
assertThatNoSuchElementException().isThrownBy(this.missing::synthesize);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+20
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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,7 +79,7 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void stringToCharacterEmptyString() {
|
||||
assertThat(conversionService.convert("", Character.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert("", Character.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -95,29 +95,29 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void stringToBooleanTrue() {
|
||||
assertThat(conversionService.convert("true", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("on", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("yes", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("1", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("TRUE", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("ON", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("YES", Boolean.class)).isEqualTo(true);
|
||||
assertThat(conversionService.convert("true", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("on", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("yes", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("1", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("TRUE", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("ON", Boolean.class)).isTrue();
|
||||
assertThat(conversionService.convert("YES", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringToBooleanFalse() {
|
||||
assertThat(conversionService.convert("false", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("off", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("no", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("0", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("FALSE", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("OFF", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("NO", Boolean.class)).isEqualTo(false);
|
||||
assertThat(conversionService.convert("false", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("off", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("no", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("0", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("FALSE", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("OFF", Boolean.class)).isFalse();
|
||||
assertThat(conversionService.convert("NO", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void stringToBooleanEmptyString() {
|
||||
assertThat(conversionService.convert("", Boolean.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert("", Boolean.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -219,7 +219,7 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void stringToNumberEmptyString() {
|
||||
assertThat(conversionService.convert("", Number.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert("", Number.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -234,7 +234,7 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void stringToEnumEmptyString() {
|
||||
assertThat(conversionService.convert("", Foo.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert("", Foo.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -254,7 +254,7 @@ class DefaultConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void integerToEnumNull() {
|
||||
assertThat(conversionService.convert(null, Foo.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert(null, Foo.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+3
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -109,7 +109,7 @@ class GenericConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void convertNullSource() {
|
||||
assertThat(conversionService.convert(null, Integer.class)).isEqualTo(null);
|
||||
assertThat(conversionService.convert(null, Integer.class)).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,12 +190,7 @@ class GenericConversionServiceTests {
|
||||
|
||||
@Test
|
||||
void convertSuperSourceType() {
|
||||
conversionService.addConverter(new Converter<CharSequence, Integer>() {
|
||||
@Override
|
||||
public Integer convert(CharSequence source) {
|
||||
return Integer.valueOf(source.toString());
|
||||
}
|
||||
});
|
||||
conversionService.addConverter(CharSequence.class, Integer.class, source -> Integer.valueOf(source.toString()));
|
||||
Integer result = conversionService.convert("3", Integer.class);
|
||||
assertThat((int) result).isEqualTo((int) Integer.valueOf(3));
|
||||
}
|
||||
|
||||
+24
-57
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,16 +26,18 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.converter.Converter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.list;
|
||||
import static org.assertj.core.api.InstanceOfAssertFactories.stream;
|
||||
|
||||
/**
|
||||
* Tests for {@link StreamConverter}.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
* @author Sam Brannen
|
||||
* @since 4.2
|
||||
*/
|
||||
class StreamConverterTests {
|
||||
@@ -57,60 +59,41 @@ class StreamConverterTests {
|
||||
@Test
|
||||
void convertFromStreamToList() throws NoSuchFieldException {
|
||||
this.conversionService.addConverter(Number.class, String.class, new ObjectToStringConverter());
|
||||
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
|
||||
Stream<Integer> stream = Stream.of(1, 2, 3);
|
||||
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("listOfStrings"));
|
||||
Object result = this.conversionService.convert(stream, listOfStrings);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
boolean condition = result instanceof List;
|
||||
assertThat(condition).as("Converted object must be a list").isTrue();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<String> content = (List<String>) result;
|
||||
assertThat(content.get(0)).isEqualTo("1");
|
||||
assertThat(content.get(1)).isEqualTo("2");
|
||||
assertThat(content.get(2)).isEqualTo("3");
|
||||
assertThat(content.size()).as("Wrong number of elements").isEqualTo(3);
|
||||
assertThat(result).asInstanceOf(list(String.class)).containsExactly("1", "2", "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertFromStreamToArray() throws NoSuchFieldException {
|
||||
this.conversionService.addConverterFactory(new NumberToNumberConverterFactory());
|
||||
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
|
||||
Stream<Integer> stream = Stream.of(1, 2, 3);
|
||||
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
|
||||
Object result = this.conversionService.convert(stream, arrayOfLongs);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
assertThat(result.getClass().isArray()).as("Converted object must be an array").isTrue();
|
||||
Long[] content = (Long[]) result;
|
||||
assertThat(content[0]).isEqualTo(Long.valueOf(1L));
|
||||
assertThat(content[1]).isEqualTo(Long.valueOf(2L));
|
||||
assertThat(content[2]).isEqualTo(Long.valueOf(3L));
|
||||
assertThat(content.length).as("Wrong number of elements").isEqualTo(3);
|
||||
assertThat(content).containsExactly(1L, 2L, 3L);
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertFromStreamToRawList() throws NoSuchFieldException {
|
||||
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
|
||||
Stream<Integer> stream = Stream.of(1, 2, 3);
|
||||
TypeDescriptor listOfStrings = new TypeDescriptor(Types.class.getField("rawList"));
|
||||
Object result = this.conversionService.convert(stream, listOfStrings);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
boolean condition = result instanceof List;
|
||||
assertThat(condition).as("Converted object must be a list").isTrue();
|
||||
@SuppressWarnings("unchecked")
|
||||
List<Object> content = (List<Object>) result;
|
||||
assertThat(content.get(0)).isEqualTo(1);
|
||||
assertThat(content.get(1)).isEqualTo(2);
|
||||
assertThat(content.get(2)).isEqualTo(3);
|
||||
assertThat(content.size()).as("Wrong number of elements").isEqualTo(3);
|
||||
assertThat(result).asInstanceOf(list(Object.class)).containsExactly(1, 2, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
void convertFromStreamToArrayNoConverter() throws NoSuchFieldException {
|
||||
Stream<Integer> stream = Arrays.asList(1, 2, 3).stream();
|
||||
Stream<Integer> stream = Stream.of(1, 2, 3);
|
||||
TypeDescriptor arrayOfLongs = new TypeDescriptor(Types.class.getField("arrayOfLongs"));
|
||||
assertThatExceptionOfType(ConversionFailedException.class).isThrownBy(() ->
|
||||
this.conversionService.convert(stream, arrayOfLongs))
|
||||
assertThatExceptionOfType(ConversionFailedException.class)
|
||||
.isThrownBy(() -> this.conversionService.convert(stream, arrayOfLongs))
|
||||
.withCauseInstanceOf(ConverterNotFoundException.class);
|
||||
}
|
||||
|
||||
@@ -118,13 +101,11 @@ class StreamConverterTests {
|
||||
@SuppressWarnings("resource")
|
||||
void convertFromListToStream() throws NoSuchFieldException {
|
||||
this.conversionService.addConverterFactory(new StringToNumberConverterFactory());
|
||||
List<String> stream = Arrays.asList("1", "2", "3");
|
||||
List<String> list = Arrays.asList("1", "2", "3");
|
||||
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("streamOfIntegers"));
|
||||
Object result = this.conversionService.convert(stream, streamOfInteger);
|
||||
Object result = this.conversionService.convert(list, streamOfInteger);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
boolean condition = result instanceof Stream;
|
||||
assertThat(condition).as("Converted object must be a stream").isTrue();
|
||||
assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<Integer> content = (Stream<Integer>) result;
|
||||
assertThat(content.mapToInt(x -> x).sum()).isEqualTo(6);
|
||||
@@ -133,39 +114,25 @@ class StreamConverterTests {
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void convertFromArrayToStream() throws NoSuchFieldException {
|
||||
Integer[] stream = new Integer[] {1, 0, 1};
|
||||
this.conversionService.addConverter(new Converter<Integer, Boolean>() {
|
||||
@Override
|
||||
public Boolean convert(Integer source) {
|
||||
return source == 1;
|
||||
}
|
||||
});
|
||||
Integer[] array = new Integer[] {1, 0, 1};
|
||||
this.conversionService.addConverter(Integer.class, Boolean.class, source -> source == 1);
|
||||
TypeDescriptor streamOfBoolean = new TypeDescriptor(Types.class.getField("streamOfBooleans"));
|
||||
Object result = this.conversionService.convert(stream, streamOfBoolean);
|
||||
Object result = this.conversionService.convert(array, streamOfBoolean);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
boolean condition = result instanceof Stream;
|
||||
assertThat(condition).as("Converted object must be a stream").isTrue();
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<Boolean> content = (Stream<Boolean>) result;
|
||||
assertThat(content.filter(x -> x).count()).isEqualTo(2);
|
||||
assertThat(result).asInstanceOf(stream(Boolean.class)).filteredOn(x -> x).hasSize(2);
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("resource")
|
||||
void convertFromListToRawStream() throws NoSuchFieldException {
|
||||
List<String> stream = Arrays.asList("1", "2", "3");
|
||||
List<String> list = Arrays.asList("1", "2", "3");
|
||||
TypeDescriptor streamOfInteger = new TypeDescriptor(Types.class.getField("rawStream"));
|
||||
Object result = this.conversionService.convert(stream, streamOfInteger);
|
||||
Object result = this.conversionService.convert(list, streamOfInteger);
|
||||
|
||||
assertThat(result).as("Converted object must not be null").isNotNull();
|
||||
boolean condition = result instanceof Stream;
|
||||
assertThat(condition).as("Converted object must be a stream").isTrue();
|
||||
assertThat(result).as("Converted object must be a stream").isInstanceOf(Stream.class);
|
||||
@SuppressWarnings("unchecked")
|
||||
Stream<Object> content = (Stream<Object>) result;
|
||||
StringBuilder sb = new StringBuilder();
|
||||
content.forEach(sb::append);
|
||||
assertThat(sb.toString()).isEqualTo("123");
|
||||
assertThat(content).containsExactly("1", "2", "3");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -47,8 +47,8 @@ class ProfilesTests {
|
||||
|
||||
@Test
|
||||
void ofWhenEmptyThrowsException() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
Profiles.of())
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(Profiles::of)
|
||||
.withMessageContaining("Must specify at least one profile");
|
||||
}
|
||||
|
||||
@@ -354,8 +354,8 @@ class ProfilesTests {
|
||||
|
||||
|
||||
private static void assertMalformed(Supplier<Profiles> supplier) {
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
supplier::get)
|
||||
assertThatIllegalArgumentException()
|
||||
.isThrownBy(supplier::get)
|
||||
.withMessageContaining("Malformed");
|
||||
}
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,7 +79,7 @@ class PropertySourceTests {
|
||||
PropertySource<?> ps1 = new MapPropertySource("ps1", map1);
|
||||
ps1.getSource();
|
||||
List<PropertySource<?>> propertySources = new ArrayList<>();
|
||||
assertThat(propertySources.add(ps1)).isEqualTo(true);
|
||||
assertThat(propertySources.add(ps1)).isTrue();
|
||||
assertThat(propertySources.contains(ps1)).isTrue();
|
||||
assertThat(propertySources.contains(PropertySource.named("ps1"))).isTrue();
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -212,7 +212,7 @@ public class StandardEnvironmentTests {
|
||||
void defaultProfileWithCircularPlaceholder() {
|
||||
try {
|
||||
System.setProperty(DEFAULT_PROFILES_PROPERTY_NAME, "${spring.profiles.default}");
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> environment.getDefaultProfiles());
|
||||
assertThatIllegalArgumentException().isThrownBy(environment::getDefaultProfiles);
|
||||
}
|
||||
finally {
|
||||
System.clearProperty(DEFAULT_PROFILES_PROPERTY_NAME);
|
||||
|
||||
Vendored
+31
-31
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -50,7 +50,7 @@ class SystemEnvironmentPropertySourceTests {
|
||||
|
||||
@Test
|
||||
void none() {
|
||||
assertThat(ps.containsProperty("a.key")).isEqualTo(false);
|
||||
assertThat(ps.containsProperty("a.key")).isFalse();
|
||||
assertThat(ps.getProperty("a.key")).isNull();
|
||||
}
|
||||
|
||||
@@ -58,7 +58,7 @@ class SystemEnvironmentPropertySourceTests {
|
||||
void normalWithoutPeriod() {
|
||||
envMap.put("akey", "avalue");
|
||||
|
||||
assertThat(ps.containsProperty("akey")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("akey")).isTrue();
|
||||
assertThat(ps.getProperty("akey")).isEqualTo("avalue");
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ class SystemEnvironmentPropertySourceTests {
|
||||
void normalWithPeriod() {
|
||||
envMap.put("a.key", "a.value");
|
||||
|
||||
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a.key")).isTrue();
|
||||
assertThat(ps.getProperty("a.key")).isEqualTo("a.value");
|
||||
}
|
||||
|
||||
@@ -74,8 +74,8 @@ class SystemEnvironmentPropertySourceTests {
|
||||
void withUnderscore() {
|
||||
envMap.put("a_key", "a_value");
|
||||
|
||||
assertThat(ps.containsProperty("a_key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a_key")).isTrue();
|
||||
assertThat(ps.containsProperty("a.key")).isTrue();
|
||||
|
||||
assertThat(ps.getProperty("a_key")).isEqualTo("a_value");
|
||||
assertThat( ps.getProperty("a.key")).isEqualTo("a_value");
|
||||
@@ -97,30 +97,30 @@ class SystemEnvironmentPropertySourceTests {
|
||||
envMap.put("A_DOT.KEY", "a_dot_value");
|
||||
envMap.put("A_HYPHEN-KEY", "a_hyphen_value");
|
||||
|
||||
assertThat(ps.containsProperty("A_KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a_key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a.key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("a-key")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_LONG_KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.LONG.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-LONG-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.LONG-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-LONG.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_long_KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.long.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-long-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.long-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-long.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_DOT.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-DOT.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_dot.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A-dot.KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_HYPHEN-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.HYPHEN-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_hyphen-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A.hyphen-KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("a_key")).isTrue();
|
||||
assertThat(ps.containsProperty("a.key")).isTrue();
|
||||
assertThat(ps.containsProperty("a-key")).isTrue();
|
||||
assertThat(ps.containsProperty("A_LONG_KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.LONG.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-LONG-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.LONG-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-LONG.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A_long_KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.long.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-long-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.long-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-long.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A_DOT.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-DOT.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A_dot.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A-dot.KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A_HYPHEN-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.HYPHEN-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A_hyphen-KEY")).isTrue();
|
||||
assertThat(ps.containsProperty("A.hyphen-KEY")).isTrue();
|
||||
|
||||
assertThat(ps.getProperty("A_KEY")).isEqualTo("a_value");
|
||||
assertThat(ps.getProperty("A.KEY")).isEqualTo("a_value");
|
||||
@@ -170,7 +170,7 @@ class SystemEnvironmentPropertySourceTests {
|
||||
}
|
||||
};
|
||||
|
||||
assertThat(ps.containsProperty("A_KEY")).isEqualTo(true);
|
||||
assertThat(ps.containsProperty("A_KEY")).isTrue();
|
||||
assertThat(ps.getProperty("A_KEY")).isEqualTo("a_value");
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -124,37 +124,37 @@ class PathResourceTests {
|
||||
@Test
|
||||
void fileExists() {
|
||||
PathResource resource = new PathResource(TEST_FILE);
|
||||
assertThat(resource.exists()).isEqualTo(true);
|
||||
assertThat(resource.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void dirExists() {
|
||||
PathResource resource = new PathResource(TEST_DIR);
|
||||
assertThat(resource.exists()).isEqualTo(true);
|
||||
assertThat(resource.exists()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileDoesNotExist() {
|
||||
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
||||
assertThat(resource.exists()).isEqualTo(false);
|
||||
assertThat(resource.exists()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void fileIsReadable() {
|
||||
PathResource resource = new PathResource(TEST_FILE);
|
||||
assertThat(resource.isReadable()).isEqualTo(true);
|
||||
assertThat(resource.isReadable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void doesNotExistIsNotReadable() {
|
||||
PathResource resource = new PathResource(NON_EXISTING_FILE);
|
||||
assertThat(resource.isReadable()).isEqualTo(false);
|
||||
assertThat(resource.isReadable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void directoryIsNotReadable() {
|
||||
PathResource resource = new PathResource(TEST_DIR);
|
||||
assertThat(resource.isReadable()).isEqualTo(false);
|
||||
assertThat(resource.isReadable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -256,13 +256,13 @@ class PathResourceTests {
|
||||
@Test
|
||||
void fileIsWritable() {
|
||||
PathResource resource = new PathResource(TEST_FILE);
|
||||
assertThat(resource.isWritable()).isEqualTo(true);
|
||||
assertThat(resource.isWritable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void directoryIsNotWritable() {
|
||||
PathResource resource = new PathResource(TEST_DIR);
|
||||
assertThat(resource.isWritable()).isEqualTo(false);
|
||||
assertThat(resource.isWritable()).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
* 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.
|
||||
@@ -80,7 +80,7 @@ class DataBufferUtilsTests extends AbstractDataBufferAllocatingTests {
|
||||
super.bufferFactory = bufferFactory;
|
||||
|
||||
Flux<DataBuffer> flux = DataBufferUtils.readInputStream(
|
||||
() -> this.resource.getInputStream(), super.bufferFactory, 3);
|
||||
this.resource::getInputStream, super.bufferFactory, 3);
|
||||
|
||||
verifyReadData(flux);
|
||||
}
|
||||
|
||||
+2
-9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* 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.
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.core.task;
|
||||
|
||||
import java.util.concurrent.ThreadFactory;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.util.ConcurrencyThrottleSupport;
|
||||
@@ -61,12 +59,7 @@ class SimpleAsyncTaskExecutorTests {
|
||||
@Test
|
||||
void threadFactoryOverridesDefaults() throws Exception {
|
||||
final Object monitor = new Object();
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(new ThreadFactory() {
|
||||
@Override
|
||||
public Thread newThread(Runnable r) {
|
||||
return new Thread(r, "test");
|
||||
}
|
||||
});
|
||||
SimpleAsyncTaskExecutor executor = new SimpleAsyncTaskExecutor(runnable -> new Thread(runnable, "test"));
|
||||
ThreadNameHarvester task = new ThreadNameHarvester(monitor);
|
||||
executeAndWait(executor, task, monitor);
|
||||
assertThat(task.getThreadName()).isEqualTo("test");
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -115,7 +115,7 @@ class AnnotationMetadataTests {
|
||||
assertThat(metadata.getAnnotationAttributes(MetaAnnotation.class.getName(), false)).isNull();
|
||||
assertThat(metadata.getAnnotationAttributes(MetaAnnotation.class.getName(), true)).isNull();
|
||||
assertThat(metadata.getAnnotatedMethods(DirectAnnotation.class.getName()).size()).isEqualTo(0);
|
||||
assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName())).isEqualTo(false);
|
||||
assertThat(metadata.isAnnotated(IsAnnotatedAnnotation.class.getName())).isFalse();
|
||||
assertThat(metadata.getAllAnnotationAttributes(DirectAnnotation.class.getName())).isNull();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2022 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,8 +28,8 @@ class PatternMatchUtilsTests {
|
||||
|
||||
@Test
|
||||
void trivial() {
|
||||
assertThat(PatternMatchUtils.simpleMatch((String) null, "")).isEqualTo(false);
|
||||
assertThat(PatternMatchUtils.simpleMatch("1", null)).isEqualTo(false);
|
||||
assertThat(PatternMatchUtils.simpleMatch((String) null, "")).isFalse();
|
||||
assertThat(PatternMatchUtils.simpleMatch("1", null)).isFalse();
|
||||
doTest("*", "123", true);
|
||||
doTest("123", "123", true);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2021 the original author or authors.
|
||||
* Copyright 2002-2022 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.
|
||||
@@ -37,18 +37,18 @@ class StringUtilsTests {
|
||||
@Test
|
||||
void hasTextBlank() {
|
||||
String blank = " ";
|
||||
assertThat(StringUtils.hasText(blank)).isEqualTo(false);
|
||||
assertThat(StringUtils.hasText(blank)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTextNullEmpty() {
|
||||
assertThat(StringUtils.hasText(null)).isEqualTo(false);
|
||||
assertThat(StringUtils.hasText("")).isEqualTo(false);
|
||||
assertThat(StringUtils.hasText(null)).isFalse();
|
||||
assertThat(StringUtils.hasText("")).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
void hasTextValid() {
|
||||
assertThat(StringUtils.hasText("t")).isEqualTo(true);
|
||||
assertThat(StringUtils.hasText("t")).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -68,7 +68,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimWhitespace() {
|
||||
assertThat(StringUtils.trimWhitespace(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.trimWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimWhitespace("\t")).isEqualTo("");
|
||||
@@ -83,7 +83,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimAllWhitespace() {
|
||||
assertThat(StringUtils.trimAllWhitespace(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.trimAllWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimAllWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimAllWhitespace("\t")).isEqualTo("");
|
||||
@@ -98,7 +98,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimLeadingWhitespace() {
|
||||
assertThat(StringUtils.trimLeadingWhitespace(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.trimLeadingWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimLeadingWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingWhitespace("\t")).isEqualTo("");
|
||||
@@ -113,7 +113,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimTrailingWhitespace() {
|
||||
assertThat(StringUtils.trimTrailingWhitespace(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.trimTrailingWhitespace(null)).isNull();
|
||||
assertThat(StringUtils.trimTrailingWhitespace("")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace(" ")).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingWhitespace("\t")).isEqualTo("");
|
||||
@@ -128,7 +128,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimLeadingCharacter() {
|
||||
assertThat(StringUtils.trimLeadingCharacter(null, ' ')).isEqualTo(null);
|
||||
assertThat(StringUtils.trimLeadingCharacter(null, ' ')).isNull();
|
||||
assertThat(StringUtils.trimLeadingCharacter("", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingCharacter(" ", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimLeadingCharacter("\t", ' ')).isEqualTo("\t");
|
||||
@@ -141,7 +141,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void trimTrailingCharacter() {
|
||||
assertThat(StringUtils.trimTrailingCharacter(null, ' ')).isEqualTo(null);
|
||||
assertThat(StringUtils.trimTrailingCharacter(null, ' ')).isNull();
|
||||
assertThat(StringUtils.trimTrailingCharacter("", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingCharacter(" ", ' ')).isEqualTo("");
|
||||
assertThat(StringUtils.trimTrailingCharacter("\t", ' ')).isEqualTo("\t");
|
||||
@@ -152,6 +152,14 @@ class StringUtilsTests {
|
||||
assertThat(StringUtils.trimTrailingCharacter(" a b c ", ' ')).isEqualTo(" a b c");
|
||||
}
|
||||
|
||||
@Test
|
||||
void matchesCharacter() {
|
||||
assertThat(StringUtils.matchesCharacter(null, '/')).isFalse();
|
||||
assertThat(StringUtils.matchesCharacter("/a", '/')).isFalse();
|
||||
assertThat(StringUtils.matchesCharacter("a", '/')).isFalse();
|
||||
assertThat(StringUtils.matchesCharacter("/", '/')).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
void startsWithIgnoreCase() {
|
||||
String prefix = "fOo";
|
||||
@@ -332,7 +340,7 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void getFilename() {
|
||||
assertThat(StringUtils.getFilename(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilename(null)).isNull();
|
||||
assertThat(StringUtils.getFilename("")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilename("myfile")).isEqualTo("myfile");
|
||||
assertThat(StringUtils.getFilename("mypath/myfile")).isEqualTo("myfile");
|
||||
@@ -344,11 +352,11 @@ class StringUtilsTests {
|
||||
|
||||
@Test
|
||||
void getFilenameExtension() {
|
||||
assertThat(StringUtils.getFilenameExtension(null)).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilenameExtension("")).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilenameExtension("myfile")).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile")).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile")).isEqualTo(null);
|
||||
assertThat(StringUtils.getFilenameExtension(null)).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("/home/user/.m2/settings/myfile")).isNull();
|
||||
assertThat(StringUtils.getFilenameExtension("myfile.")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilenameExtension("myPath/myfile.")).isEqualTo("");
|
||||
assertThat(StringUtils.getFilenameExtension("myfile.txt")).isEqualTo("txt");
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user