mirror of
https://github.com/spring-projects/spring-framework
synced 2026-06-08 17:33:33 +00:00
Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 2137e8d963 |
@@ -1,17 +0,0 @@
|
||||
<!--
|
||||
!!! For Security Vulnerabilities, please go to https://pivotal.io/security !!!
|
||||
-->
|
||||
**Affects:** \<Spring Framework version>
|
||||
|
||||
---
|
||||
<!--
|
||||
Thanks for taking the time to create an issue. Please read the following:
|
||||
|
||||
- Questions should be asked on Stack Overflow.
|
||||
- For bugs, specify affected versions and explain what you are trying to do.
|
||||
- For enhancements, provide context and describe the problem.
|
||||
|
||||
Issue or Pull Request? Create only one, not both. GitHub treats them as the same.
|
||||
If unsure, start with an issue, and if you submit a pull request later, the
|
||||
issue will be closed as superseded.
|
||||
-->
|
||||
+12
-10
@@ -29,7 +29,7 @@ If you have a question, check StackOverflow using
|
||||
Find an existing discussion or start a new one if necessary.
|
||||
|
||||
If you suspect an issue, perform a search in the
|
||||
[GitHub issue tracker](https://github.com/spring-projects/spring-framework/issues), using a few different keywords.
|
||||
[Github issue tracker](https://github.com/spring-projects/spring-framework/issues), using a few different keywords.
|
||||
When you find related issues and discussions, prior or current, it helps you to learn and
|
||||
it helps us to make a decision.
|
||||
|
||||
@@ -42,17 +42,18 @@ Before you create a ticket, please take the time to [research first](#discuss).
|
||||
|
||||
If creating a ticket after a discussion on StackOverflow, please provide a self-sufficient description in the ticket, independent of the details on StackOverview. We understand this is extra work but the issue tracker is an important place of record for design discussions and decisions that can often be referenced long after the fix version, for example to revisit decisions, to understand the origin of a feature, and so on.
|
||||
|
||||
When ready create a ticket in the [GitHub issue tracker](https://github.com/spring-projects/spring-framework/issues).
|
||||
When ready create a ticket in the [Github issue tracker](https://github.com/spring-projects/spring-framework/issues).
|
||||
|
||||
#### Ticket Lifecycle
|
||||
|
||||
When an issue is first created, it is flagged `waiting-for-triage` waiting for a team
|
||||
member to triage it. Within a day or two, the issue will then be reviewed and the team
|
||||
may ask for further information if needed. Based on the findings, the issue is either
|
||||
assigned a fix version or declined.
|
||||
When an issue is first created, it may not be assigned and will not have a fix version.
|
||||
Within a day or two, the issue is assigned to a specific committer and the target
|
||||
version is set to "Waiting for Triage". The committer will then review the issue, ask for
|
||||
further information if needed, and based on the findings, the issue is either assigned a fix
|
||||
version or rejected.
|
||||
|
||||
When a fix is ready, the issue is closed and may still be re-opened. Once a fix is
|
||||
released, the issue can't be reopened. If necessary, you will need to create a new,
|
||||
When a fix is ready, the issue is marked "Resolved" and may still be re-opened. Once a fix
|
||||
is released, the issue is permanently "Closed". If necessary, you will need to create a new,
|
||||
related ticket with a fresh description.
|
||||
|
||||
#### Submit a Pull Request
|
||||
@@ -82,8 +83,9 @@ multiple edits or corrections of the same logical change. See
|
||||
[Rewriting History section of Pro Git](https://git-scm.com/book/en/Git-Tools-Rewriting-History)
|
||||
for an overview of streamlining commit history.
|
||||
|
||||
1. Format commit messages using 55 characters for the subject line, 72 characters per line
|
||||
for the description, followed by the issue fixed, e.g. `Closes gh-22276`. See the
|
||||
1. Format commit messages using 55 characters for the subject line, 72 lines for the
|
||||
description, followed by the issue fixed, e.g. `Fixes #22276`.
|
||||
See the
|
||||
[Commit Guidelines section of Pro Git](https://git-scm.com/book/en/Distributed-Git-Contributing-to-a-Project#Commit-Guidelines)
|
||||
for best practices around commit messages and use `git log` to see some examples.
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ The Spring Framework maintains reference documentation ([published](https://docs
|
||||
|
||||
## Build from Source
|
||||
|
||||
See the [Build from Source](https://github.com/spring-projects/spring-framework/wiki/Build-from-Source) Wiki page and the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
||||
See the [Build from Source](https://github.com/spring-projects/spring-framework/wiki/Build-from-Source) Wikipedia page and the [CONTRIBUTING.md](CONTRIBUTING.md) file.
|
||||
|
||||
## Stay in Touch
|
||||
|
||||
|
||||
-11
@@ -1,11 +0,0 @@
|
||||
# Security Policy
|
||||
|
||||
## Supported Versions
|
||||
|
||||
Please see the
|
||||
[Spring Framework Versions](https://github.com/spring-projects/spring-framework/wiki/Spring-Framework-Versions)
|
||||
wiki page.
|
||||
|
||||
## Reporting a Vulnerability
|
||||
|
||||
Please see https://pivotal.io/security.
|
||||
+28
-28
@@ -10,14 +10,14 @@ buildscript {
|
||||
|
||||
// 3rd party plugin repositories can be configured in settings.gradle
|
||||
plugins {
|
||||
id "io.spring.dependency-management" version "1.0.7.RELEASE" apply false
|
||||
id "org.jetbrains.kotlin.jvm" version "1.3.31" apply false
|
||||
id "org.jetbrains.dokka" version "0.9.18"
|
||||
id "io.spring.dependency-management" version "1.0.5.RELEASE" apply false
|
||||
id "org.jetbrains.kotlin.jvm" version "1.2.71" apply false
|
||||
id "org.jetbrains.dokka" version "0.9.17"
|
||||
id "org.asciidoctor.convert" version "1.5.8"
|
||||
}
|
||||
|
||||
ext {
|
||||
linkHomepage = "https://spring.io/projects/spring-framework"
|
||||
linkHomepage = "https://projects.spring.io/spring-framework"
|
||||
linkCi = "https://build.spring.io/browse/SPR"
|
||||
linkIssue = "https://github.com/spring-projects/spring-framework/issues"
|
||||
linkScmUrl = "https://github.com/spring-projects/spring-framework"
|
||||
@@ -25,29 +25,27 @@ ext {
|
||||
linkScmDevConnection = "scm:git:ssh://git@github.com:spring-projects/spring-framework.git"
|
||||
|
||||
moduleProjects = subprojects.findAll {
|
||||
(it.name != "spring-build-src") && (it.name != "spring-framework-bom") && (it.name != "spring-core-coroutines")
|
||||
!it.name.equals("spring-build-src") && !it.name.equals("spring-framework-bom")
|
||||
}
|
||||
|
||||
aspectjVersion = "1.9.3"
|
||||
coroutinesVersion = "1.2.1"
|
||||
aspectjVersion = "1.9.2"
|
||||
freemarkerVersion = "2.3.28"
|
||||
groovyVersion = "2.5.7"
|
||||
groovyVersion = "2.5.6"
|
||||
hsqldbVersion = "2.4.1"
|
||||
jackson2Version = "2.9.9"
|
||||
jettyVersion = "9.4.18.v20190429"
|
||||
junit5Version = "5.5.0-RC1"
|
||||
kotlinVersion = "1.3.31"
|
||||
jackson2Version = "2.9.8"
|
||||
jettyVersion = "9.4.15.v20190215"
|
||||
junit5Version = "5.3.2"
|
||||
kotlinVersion = "1.2.71"
|
||||
log4jVersion = "2.11.2"
|
||||
nettyVersion = "4.1.36.Final"
|
||||
reactorVersion = "Dysprosium-M2"
|
||||
rsocketVersion = "0.12.2-RC4"
|
||||
nettyVersion = "4.1.34.Final"
|
||||
reactorVersion = "Californium-SR6"
|
||||
rxjavaVersion = "1.3.8"
|
||||
rxjavaAdapterVersion = "1.2.1"
|
||||
rxjava2Version = "2.2.9"
|
||||
rxjava2Version = "2.2.8"
|
||||
slf4jVersion = "1.7.26" // spring-jcl + consistent 3rd party deps
|
||||
tiles3Version = "3.0.8"
|
||||
tomcatVersion = "9.0.21"
|
||||
undertowVersion = "2.0.21.Final"
|
||||
tomcatVersion = "9.0.17"
|
||||
undertowVersion = "2.0.19.Final"
|
||||
|
||||
gradleScriptDir = "${rootProject.projectDir}/gradle"
|
||||
withoutJclOverSlf4J = {
|
||||
@@ -119,6 +117,8 @@ configure(allprojects) { project ->
|
||||
kotlinOptions {
|
||||
jvmTarget = "1.8"
|
||||
freeCompilerArgs = ["-Xjsr305=strict"]
|
||||
apiVersion = "1.1"
|
||||
languageVersion = "1.1"
|
||||
}
|
||||
}
|
||||
|
||||
@@ -143,27 +143,27 @@ configure(allprojects) { project ->
|
||||
}
|
||||
|
||||
checkstyle {
|
||||
toolVersion = "8.21"
|
||||
toolVersion = "8.18"
|
||||
configDir = rootProject.file("src/checkstyle")
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenCentral()
|
||||
maven { url "https://repo.spring.io/libs-release" }
|
||||
maven { url "https://repo.spring.io/milestone" } // Reactor
|
||||
mavenLocal()
|
||||
}
|
||||
|
||||
dependencies {
|
||||
testCompile("junit:junit:4.13-beta-3") {
|
||||
testCompile("junit:junit:4.12") {
|
||||
exclude group: "org.hamcrest", module: "hamcrest-core"
|
||||
}
|
||||
testCompile("org.mockito:mockito-core:2.28.2") {
|
||||
testCompile("org.mockito:mockito-core:2.25.1") {
|
||||
exclude group: "org.hamcrest", module: "hamcrest-core"
|
||||
}
|
||||
testCompile("io.mockk:mockk:1.9.3")
|
||||
testCompile("com.nhaarman:mockito-kotlin:1.6.0") {
|
||||
exclude module: "kotlin-stdlib"
|
||||
exclude module: "kotlin-reflect"
|
||||
exclude module: "mockito-core"
|
||||
}
|
||||
testCompile("org.hamcrest:hamcrest-all:1.3")
|
||||
testCompile("org.assertj:assertj-core:3.12.2")
|
||||
testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
|
||||
testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
|
||||
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")
|
||||
@@ -177,7 +177,7 @@ configure(allprojects) { project ->
|
||||
"https://docs.oracle.com/javase/8/docs/api/",
|
||||
"https://docs.oracle.com/javaee/7/api/",
|
||||
"https://docs.oracle.com/cd/E13222_01/wls/docs90/javadocs/", // CommonJ
|
||||
"https://www.ibm.com/support/knowledgecenter/SS7JFU_8.5.5/com.ibm.websphere.javadoc.doc/web/apidocs/",
|
||||
"https://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/apidocs/",
|
||||
"https://glassfish.java.net/nonav/docs/v3/api/",
|
||||
"https://docs.jboss.org/jbossas/javadoc/4.0.5/connector/",
|
||||
"https://docs.jboss.org/jbossas/javadoc/7.1.2.Final/",
|
||||
@@ -195,7 +195,7 @@ configure(allprojects) { project ->
|
||||
] as String[]
|
||||
}
|
||||
|
||||
configure(subprojects.findAll { (it.name != "spring-build-src") && (it.name != "spring-core-coroutines") } ) { subproject ->
|
||||
configure(subprojects - project(":spring-build-src")) { subproject ->
|
||||
apply from: "${gradleScriptDir}/publish-maven.gradle"
|
||||
|
||||
jar {
|
||||
|
||||
+1
-1
@@ -5,7 +5,7 @@
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
|
||||
+1
-1
@@ -1 +1 @@
|
||||
version=5.2.0.M3
|
||||
version=5.1.6.RELEASE
|
||||
|
||||
+6
-32
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -77,37 +77,15 @@ dokka {
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://www.reactive-streams.org/reactive-streams-1.0.1-javadoc/")
|
||||
}
|
||||
externalDocumentationLink {
|
||||
url = new URL("https://kotlin.github.io/kotlinx.coroutines/kotlinx-coroutines-core/")
|
||||
}
|
||||
}
|
||||
|
||||
configurations {
|
||||
docs
|
||||
}
|
||||
|
||||
dependencies {
|
||||
// for documentation resources
|
||||
docs "io.spring.docresources:spring-doc-resources:0.1.0.RELEASE@zip"
|
||||
}
|
||||
|
||||
task extractDocResources(type: Sync) {
|
||||
dependsOn configurations.docs
|
||||
from "src/docs/asciidoc/"
|
||||
from {
|
||||
configurations.docs.collect { zipTree(it) }
|
||||
}
|
||||
into "$buildDir/asciidoc/build"
|
||||
}
|
||||
|
||||
asciidoctor {
|
||||
sourceDir "$buildDir/asciidoc/build"
|
||||
sources {
|
||||
include '*.adoc'
|
||||
}
|
||||
resources {
|
||||
from(sourceDir) {
|
||||
include 'images/*', 'css/**', 'js/**'
|
||||
include 'images/*', 'stylesheets/*', 'tocbot-3.0.2/*'
|
||||
}
|
||||
}
|
||||
logDocuments = true
|
||||
@@ -120,21 +98,17 @@ asciidoctor {
|
||||
attributes 'icons': 'font',
|
||||
'idprefix': '',
|
||||
'idseparator': '-',
|
||||
docinfo: 'shared',
|
||||
docinfo: '',
|
||||
revnumber: project.version,
|
||||
sectanchors: '',
|
||||
sectnums: '',
|
||||
'source-highlighter=highlight.js',
|
||||
'highlightjsdir=js/highlight',
|
||||
'highlightjs-theme=atom-one-dark-reasonable',
|
||||
stylesdir: "css/",
|
||||
stylesheet: 'spring.css',
|
||||
'source-highlighter': 'coderay@', // TODO switch to 'rouge' once supported by the html5 backend
|
||||
stylesdir: 'stylesheets/',
|
||||
stylesheet: 'main.css',
|
||||
'spring-version': project.version
|
||||
|
||||
}
|
||||
|
||||
asciidoctor.dependsOn extractDocResources
|
||||
|
||||
task docsZip(type: Zip, dependsOn: ['api', 'asciidoctor', 'dokka']) {
|
||||
group = "Distribution"
|
||||
baseName = "spring-framework"
|
||||
|
||||
@@ -15,7 +15,7 @@ https://sourceforge.net/projects/javadiff
|
||||
|
||||
To use the Ant task on your own project, see example.xml. More examples
|
||||
of using JDiff to compare the public APIs of J2SE1.3 and J2SE1.4 can
|
||||
be seen at http://javadiff.sourceforge.net/
|
||||
be seen at http://www.jdiff.org
|
||||
|
||||
For an example with the source distribution, run "ant" and
|
||||
look at the HTML output in ./build/reports/example/changes.html
|
||||
|
||||
Vendored
BIN
Binary file not shown.
+1
-1
@@ -1,5 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-bin.zip
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.3-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
||||
|
||||
@@ -1,21 +1,5 @@
|
||||
#!/usr/bin/env sh
|
||||
|
||||
#
|
||||
# Copyright 2015 the original author or authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# http://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
##
|
||||
## Gradle start up script for UN*X
|
||||
@@ -45,7 +29,7 @@ APP_BASE_NAME=`basename "$0"`
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
GRADLE_OPTS="-XX:MaxMetaspaceSize=1024m -Xmx1024m $GRADLE_OPTS"
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
DEFAULT_JVM_OPTS=""
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD="maximum"
|
||||
|
||||
Vendored
+1
-17
@@ -1,19 +1,3 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem http://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%" == "" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@@ -31,7 +15,7 @@ set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set GRADLE_OPTS=-XX:MaxMetaspaceSize=1024m -Xmx1024m -XX:MaxHeapSize=256m %GRADLE_OPTS%
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
set DEFAULT_JVM_OPTS=
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
@@ -22,7 +22,7 @@ _Within your locally cloned `spring-framework` working directory:_
|
||||
to directory -> Select Finish)
|
||||
3. If prompted, exclude the `spring-aspects` module (or after the import by closing or
|
||||
deleting the project)
|
||||
4. In the `spring-oxm` project, add the `jaxb` folder in
|
||||
4. In the `spring-oxm` project, add the two folders (`castor` and `jaxb`) in
|
||||
`build/generated-sources` to the build path (right click on them and select
|
||||
`Build Path -> Use as Source Folder`)
|
||||
5. To apply project specific settings run `./gradlew eclipseBuildship`
|
||||
|
||||
@@ -5,7 +5,6 @@ include "spring-context"
|
||||
include "spring-context-support"
|
||||
include "spring-context-indexer"
|
||||
include "spring-core"
|
||||
include "spring-core-coroutines"
|
||||
include "spring-expression"
|
||||
include "spring-instrument"
|
||||
include "spring-jcl"
|
||||
|
||||
@@ -720,7 +720,7 @@ public abstract class AbstractAspectJAdvice implements Advice, AspectJPrecedence
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+6
-3
@@ -519,7 +519,7 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -544,7 +544,9 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("AspectJExpressionPointcut: (");
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append("AspectJExpressionPointcut: ");
|
||||
sb.append("(");
|
||||
for (int i = 0; i < this.pointcutParameterTypes.length; i++) {
|
||||
sb.append(this.pointcutParameterTypes[i].getName());
|
||||
sb.append(" ");
|
||||
@@ -553,7 +555,8 @@ public class AspectJExpressionPointcut extends AbstractExpressionPointcut
|
||||
sb.append(", ");
|
||||
}
|
||||
}
|
||||
sb.append(") ");
|
||||
sb.append(")");
|
||||
sb.append(" ");
|
||||
if (getExpression() != null) {
|
||||
sb.append(getExpression());
|
||||
}
|
||||
|
||||
+1
-1
@@ -93,7 +93,7 @@ public class AspectJPointcutAdvisor implements PointcutAdvisor, Ordered {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -263,7 +263,7 @@ final class InstantiationModelAwarePointcutAdvisorImpl
|
||||
* Note that this is a <i>dynamic</i> pointcut; otherwise it might be optimized out
|
||||
* if it does not at first match statically.
|
||||
*/
|
||||
private static final class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
|
||||
private final class PerTargetInstantiationModelPointcut extends DynamicMethodMatcherPointcut {
|
||||
|
||||
private final AspectJExpressionPointcut declaredPointcut;
|
||||
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -153,7 +153,7 @@ public class ReflectiveAspectJAdvisorFactory extends AbstractAspectJAdvisorFacto
|
||||
if (AnnotationUtils.getAnnotation(method, Pointcut.class) == null) {
|
||||
methods.add(method);
|
||||
}
|
||||
}, ReflectionUtils.USER_DECLARED_METHODS);
|
||||
});
|
||||
methods.sort(METHOD_COMPARATOR);
|
||||
return methods;
|
||||
}
|
||||
|
||||
@@ -592,7 +592,7 @@ public class AdvisedSupport extends ProxyConfig implements Advised {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || (other instanceof MethodCacheKey &&
|
||||
this.method == ((MethodCacheKey) other).method));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -112,7 +112,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
/** Dispatcher used for methods on Advised. */
|
||||
private final transient AdvisedDispatcher advisedDispatcher;
|
||||
|
||||
private transient Map<Method, Integer> fixedInterceptorMap = Collections.emptyMap();
|
||||
private transient Map<String, Integer> fixedInterceptorMap = Collections.emptyMap();
|
||||
|
||||
private transient int fixedInterceptorOffset;
|
||||
|
||||
@@ -166,7 +166,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
Assert.state(rootClass != null, "Target class must be available for creating a CGLIB proxy");
|
||||
|
||||
Class<?> proxySuperClass = rootClass;
|
||||
if (rootClass.getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)) {
|
||||
if (ClassUtils.isCglibProxyClass(rootClass)) {
|
||||
proxySuperClass = rootClass.getSuperclass();
|
||||
Class<?>[] additionalInterfaces = rootClass.getInterfaces();
|
||||
for (Class<?> additionalInterface : additionalInterfaces) {
|
||||
@@ -327,11 +327,10 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
|
||||
// TODO: small memory optimization here (can skip creation for methods with no advice)
|
||||
for (int x = 0; x < methods.length; x++) {
|
||||
Method method = methods[x];
|
||||
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(method, rootClass);
|
||||
List<Object> chain = this.advised.getInterceptorsAndDynamicInterceptionAdvice(methods[x], rootClass);
|
||||
fixedCallbacks[x] = new FixedChainStaticTargetInterceptor(
|
||||
chain, this.advised.getTargetSource().getTarget(), this.advised.getTargetClass());
|
||||
this.fixedInterceptorMap.put(method, x);
|
||||
this.fixedInterceptorMap.put(methods[x].toString(), x);
|
||||
}
|
||||
|
||||
// Now copy both the callbacks from mainCallbacks
|
||||
@@ -349,7 +348,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || (other instanceof CglibAopProxy &&
|
||||
AopProxyUtils.equalsInProxy(this.advised, ((CglibAopProxy) other).advised)));
|
||||
}
|
||||
@@ -703,7 +702,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other ||
|
||||
(other instanceof DynamicAdvisedInterceptor &&
|
||||
this.advised.equals(((DynamicAdvisedInterceptor) other).advised)));
|
||||
@@ -763,12 +762,12 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
|
||||
private final AdvisedSupport advised;
|
||||
|
||||
private final Map<Method, Integer> fixedInterceptorMap;
|
||||
private final Map<String, Integer> fixedInterceptorMap;
|
||||
|
||||
private final int fixedInterceptorOffset;
|
||||
|
||||
public ProxyCallbackFilter(
|
||||
AdvisedSupport advised, Map<Method, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
||||
AdvisedSupport advised, Map<String, Integer> fixedInterceptorMap, int fixedInterceptorOffset) {
|
||||
|
||||
this.advised = advised;
|
||||
this.fixedInterceptorMap = fixedInterceptorMap;
|
||||
@@ -853,7 +852,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
return AOP_PROXY;
|
||||
}
|
||||
Method key = method;
|
||||
String key = method.toString();
|
||||
// Check to see if we have fixed interceptor to serve this method.
|
||||
// Else use the AOP_PROXY.
|
||||
if (isStatic && isFrozen && this.fixedInterceptorMap.containsKey(key)) {
|
||||
@@ -899,7 +898,7 @@ class CglibAopProxy implements AopProxy, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -154,6 +154,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
@Override
|
||||
@Nullable
|
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
|
||||
MethodInvocation invocation;
|
||||
Object oldProxy = null;
|
||||
boolean setProxyContext = false;
|
||||
|
||||
@@ -206,8 +207,7 @@ final class JdkDynamicAopProxy implements AopProxy, InvocationHandler, Serializa
|
||||
}
|
||||
else {
|
||||
// We need to create a method invocation...
|
||||
MethodInvocation invocation =
|
||||
new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
|
||||
invocation = new ReflectiveMethodInvocation(proxy, target, method, args, targetClass, chain);
|
||||
// Proceed to the joinpoint through the interceptor chain.
|
||||
retVal = invocation.proceed();
|
||||
}
|
||||
|
||||
+5
-1
@@ -98,12 +98,16 @@ public abstract class AbstractMonitoringInterceptor extends AbstractTraceInterce
|
||||
* @see #setSuffix
|
||||
*/
|
||||
protected String createInvocationTraceName(MethodInvocation invocation) {
|
||||
StringBuilder sb = new StringBuilder(getPrefix());
|
||||
Method method = invocation.getMethod();
|
||||
Class<?> clazz = method.getDeclaringClass();
|
||||
if (this.logTargetClassInvocation && clazz.isInstance(invocation.getThis())) {
|
||||
clazz = invocation.getThis().getClass();
|
||||
}
|
||||
return getPrefix() + clazz.getName() + '.' + method.getName() + getSuffix();
|
||||
sb.append(clazz.getName());
|
||||
sb.append('.').append(method.getName());
|
||||
sb.append(getSuffix());
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+2
-2
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,7 @@ import java.lang.reflect.Method;
|
||||
*
|
||||
* <p>An asynchronous method usually returns a {@link java.util.concurrent.Future}
|
||||
* instance that gives access to the underlying exception. When the method does
|
||||
* not provide that return type, this handler can be used to manage such
|
||||
* not provide that return type, this handler can be used to managed such
|
||||
* uncaught exceptions.
|
||||
*
|
||||
* @author Stephane Nicoll
|
||||
|
||||
+1
-1
@@ -65,7 +65,7 @@ public abstract class AbstractPointcutAdvisor implements PointcutAdvisor, Ordere
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
@@ -196,7 +195,7 @@ public abstract class AbstractRegexpMethodPointcut extends StaticMethodMatcherPo
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -66,8 +66,8 @@ public abstract class AopUtils {
|
||||
* @see #isCglibProxy
|
||||
*/
|
||||
public static boolean isAopProxy(@Nullable Object object) {
|
||||
return (object instanceof SpringProxy && (Proxy.isProxyClass(object.getClass()) ||
|
||||
object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR)));
|
||||
return (object instanceof SpringProxy &&
|
||||
(Proxy.isProxyClass(object.getClass()) || ClassUtils.isCglibProxyClass(object.getClass())));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -91,8 +91,7 @@ public abstract class AopUtils {
|
||||
* @see ClassUtils#isCglibProxy(Object)
|
||||
*/
|
||||
public static boolean isCglibProxy(@Nullable Object object) {
|
||||
return (object instanceof SpringProxy &&
|
||||
object.getClass().getName().contains(ClassUtils.CGLIB_CLASS_SEPARATOR));
|
||||
return (object instanceof SpringProxy && ClassUtils.isCglibProxy(object));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.aop.support;
|
||||
import java.io.Serializable;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
@@ -107,7 +106,7 @@ public abstract class ClassFilters {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || (other instanceof UnionClassFilter &&
|
||||
ObjectUtils.nullSafeEquals(this.filters, ((UnionClassFilter) other).filters)));
|
||||
}
|
||||
@@ -142,7 +141,7 @@ public abstract class ClassFilters {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || (other instanceof IntersectionClassFilter &&
|
||||
ObjectUtils.nullSafeEquals(this.filters, ((IntersectionClassFilter) other).filters)));
|
||||
}
|
||||
|
||||
@@ -21,7 +21,6 @@ import java.io.Serializable;
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -181,7 +180,7 @@ public class ComposablePointcut implements Pointcut, Serializable {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,6 @@ package org.springframework.aop.support;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
@@ -44,7 +43,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||
@Nullable
|
||||
private String methodName;
|
||||
|
||||
private final AtomicInteger evaluations = new AtomicInteger(0);
|
||||
private volatile int evaluations;
|
||||
|
||||
|
||||
/**
|
||||
@@ -92,7 +91,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||
|
||||
@Override
|
||||
public boolean matches(Method method, Class<?> targetClass, Object... args) {
|
||||
this.evaluations.incrementAndGet();
|
||||
this.evaluations++;
|
||||
|
||||
for (StackTraceElement element : new Throwable().getStackTrace()) {
|
||||
if (element.getClassName().equals(this.clazz.getName()) &&
|
||||
@@ -107,7 +106,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||
* It's useful to know how many times we've fired, for optimization.
|
||||
*/
|
||||
public int getEvaluations() {
|
||||
return this.evaluations.get();
|
||||
return this.evaluations;
|
||||
}
|
||||
|
||||
|
||||
@@ -123,7 +122,7 @@ public class ControlFlowPointcut implements Pointcut, ClassFilter, MethodMatcher
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-1
@@ -150,7 +150,7 @@ public class DefaultIntroductionAdvisor implements IntroductionAdvisor, ClassFil
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -22,7 +22,6 @@ import java.lang.reflect.Method;
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.IntroductionAwareMethodMatcher;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -141,7 +140,7 @@ public abstract class MethodMatchers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -208,7 +207,7 @@ public abstract class MethodMatchers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -297,7 +296,7 @@ public abstract class MethodMatchers {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+1
-2
@@ -22,7 +22,6 @@ import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
|
||||
/**
|
||||
@@ -99,7 +98,7 @@ public class NameMatchMethodPointcut extends StaticMethodMatcherPointcut impleme
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
return (this == other || (other instanceof NameMatchMethodPointcut &&
|
||||
this.mappedNames.equals(((NameMatchMethodPointcut) other).mappedNames)));
|
||||
}
|
||||
|
||||
+1
-2
@@ -20,7 +20,6 @@ import java.lang.annotation.Annotation;
|
||||
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -68,7 +67,7 @@ public class AnnotationClassFilter implements ClassFilter {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
+3
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,6 @@ import java.lang.annotation.Annotation;
|
||||
import org.springframework.aop.ClassFilter;
|
||||
import org.springframework.aop.MethodMatcher;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.core.annotation.AnnotationUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -97,7 +96,7 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
||||
this.classFilter = new AnnotationClassFilter(classAnnotationType, checkInherited);
|
||||
}
|
||||
else {
|
||||
this.classFilter = new AnnotationCandidateClassFilter(methodAnnotationType);
|
||||
this.classFilter = ClassFilter.TRUE;
|
||||
}
|
||||
|
||||
if (methodAnnotationType != null) {
|
||||
@@ -120,7 +119,7 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
@@ -165,23 +164,4 @@ public class AnnotationMatchingPointcut implements Pointcut {
|
||||
return new AnnotationMatchingPointcut(null, annotationType);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@link ClassFilter} that delegates to {@link AnnotationUtils#isCandidateClass}
|
||||
* for filtering classes whose methods are not worth searching to begin with.
|
||||
*/
|
||||
private static class AnnotationCandidateClassFilter implements ClassFilter {
|
||||
|
||||
private final Class<? extends Annotation> annotationType;
|
||||
|
||||
public AnnotationCandidateClassFilter(Class<? extends Annotation> annotationType) {
|
||||
this.annotationType = annotationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean matches(Class<?> clazz) {
|
||||
return AnnotationUtils.isCandidateClass(clazz, this.annotationType);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+1
-2
@@ -23,7 +23,6 @@ import java.lang.reflect.Proxy;
|
||||
import org.springframework.aop.support.AopUtils;
|
||||
import org.springframework.aop.support.StaticMethodMatcher;
|
||||
import org.springframework.core.annotation.AnnotatedElementUtils;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -87,7 +86,7 @@ public class AnnotationMethodMatcher extends StaticMethodMatcher {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(@Nullable Object other) {
|
||||
public boolean equals(Object other) {
|
||||
if (this == other) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
Spring's proxy-based AOP framework.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
@@ -8,13 +8,3 @@ http\://www.springframework.org/schema/aop/spring-aop-4.1.xsd=org/springframewor
|
||||
http\://www.springframework.org/schema/aop/spring-aop-4.2.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
http\://www.springframework.org/schema/aop/spring-aop-4.3.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
http\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-2.0.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-2.5.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-3.0.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-3.1.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-3.2.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-4.0.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-4.1.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-4.2.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop-4.3.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
https\://www.springframework.org/schema/aop/spring-aop.xsd=org/springframework/aop/config/spring-aop.xsd
|
||||
|
||||
+26
-16
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,8 +23,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
|
||||
@@ -225,7 +224,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
throw new AssertionError("Bad test specification, no method '" + name + "' found in test class");
|
||||
fail("Bad test specification, no method '" + name + "' found in test class");
|
||||
return null;
|
||||
}
|
||||
|
||||
protected void assertParameterNames(Method method, String pointcut, String[] parameterNames) {
|
||||
@@ -235,7 +235,8 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
protected void assertParameterNames(
|
||||
Method method, String pointcut, String returning, String throwing, String[] parameterNames) {
|
||||
|
||||
assertThat(parameterNames.length).as("bad test specification, must have same number of parameter names as method arguments").isEqualTo(method.getParameterCount());
|
||||
assertEquals("bad test specification, must have same number of parameter names as method arguments",
|
||||
method.getParameterCount(), parameterNames.length);
|
||||
|
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
|
||||
discoverer.setRaiseExceptions(true);
|
||||
@@ -246,31 +247,40 @@ public class AspectJAdviceParameterNameDiscovererTests {
|
||||
String formattedExpectedNames = format(parameterNames);
|
||||
String formattedActualNames = format(discoveredNames);
|
||||
|
||||
assertThat(discoveredNames.length).as("Expecting " + parameterNames.length + " parameter names in return set '" +
|
||||
assertEquals("Expecting " + parameterNames.length + " parameter names in return set '" +
|
||||
formattedExpectedNames + "', but found " + discoveredNames.length +
|
||||
" '" + formattedActualNames + "'").isEqualTo(parameterNames.length);
|
||||
" '" + formattedActualNames + "'",
|
||||
parameterNames.length, discoveredNames.length);
|
||||
|
||||
for (int i = 0; i < discoveredNames.length; i++) {
|
||||
assertThat(discoveredNames[i]).as("Parameter names must never be null").isNotNull();
|
||||
assertThat(discoveredNames[i]).as("Expecting parameter " + i + " to be named '" +
|
||||
parameterNames[i] + "' but was '" + discoveredNames[i] + "'").isEqualTo(parameterNames[i]);
|
||||
assertNotNull("Parameter names must never be null", discoveredNames[i]);
|
||||
assertEquals("Expecting parameter " + i + " to be named '" +
|
||||
parameterNames[i] + "' but was '" + discoveredNames[i] + "'",
|
||||
parameterNames[i], discoveredNames[i]);
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertException(Method method, String pointcut, Class<? extends Throwable> exceptionType, String message) {
|
||||
protected void assertException(Method method, String pointcut, Class<?> exceptionType, String message) {
|
||||
assertException(method, pointcut, null, null, exceptionType, message);
|
||||
}
|
||||
|
||||
protected void assertException(Method method, String pointcut, String returning,
|
||||
String throwing, Class<? extends Throwable> exceptionType, String message) {
|
||||
protected void assertException(
|
||||
Method method, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) {
|
||||
|
||||
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut);
|
||||
discoverer.setRaiseExceptions(true);
|
||||
discoverer.setReturningName(returning);
|
||||
discoverer.setThrowingName(throwing);
|
||||
assertThatExceptionOfType(exceptionType).isThrownBy(() ->
|
||||
discoverer.getParameterNames(method))
|
||||
.withMessageContaining(message);
|
||||
|
||||
try {
|
||||
discoverer.getParameterNames(method);
|
||||
fail("Expecting " + exceptionType.getName() + " with message '" + message + "'");
|
||||
}
|
||||
catch (RuntimeException expected) {
|
||||
assertEquals("Expecting exception of type " + exceptionType.getName(),
|
||||
exceptionType, expected.getClass());
|
||||
assertEquals("Exception message does not match expected", message, expected.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
+70
-48
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -36,10 +36,7 @@ import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.subpkg.DeepBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -78,9 +75,9 @@ public class AspectJExpressionPointcutTests {
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
|
||||
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
|
||||
assertMatchesGetAge(methodMatcher);
|
||||
assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge() method").isFalse();
|
||||
assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,9 +93,9 @@ public class AspectJExpressionPointcutTests {
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
|
||||
assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
|
||||
assertMatchesGetAge(methodMatcher);
|
||||
assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge(int) method").isTrue();
|
||||
assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -125,10 +122,10 @@ public class AspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut iOtherPc = new AspectJExpressionPointcut();
|
||||
iOtherPc.setExpression(matchesIOther);
|
||||
|
||||
assertThat(testBeanPc.matches(TestBean.class)).isTrue();
|
||||
assertThat(testBeanPc.matches(getAge, TestBean.class)).isTrue();
|
||||
assertThat(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isTrue();
|
||||
assertThat(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isFalse();
|
||||
assertTrue(testBeanPc.matches(TestBean.class));
|
||||
assertTrue(testBeanPc.matches(getAge, TestBean.class));
|
||||
assertTrue(iOtherPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||
assertFalse(testBeanPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -151,37 +148,49 @@ public class AspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut withinBeansPc = new AspectJExpressionPointcut();
|
||||
withinBeansPc.setExpression(withinBeansPackage);
|
||||
|
||||
assertThat(withinBeansPc.matches(TestBean.class)).isTrue();
|
||||
assertThat(withinBeansPc.matches(getAge, TestBean.class)).isTrue();
|
||||
assertThat(withinBeansPc.matches(DeepBean.class)).isEqualTo(matchSubpackages);
|
||||
assertThat(withinBeansPc.matches(
|
||||
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class)).isEqualTo(matchSubpackages);
|
||||
assertThat(withinBeansPc.matches(String.class)).isFalse();
|
||||
assertThat(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class)).isFalse();
|
||||
assertTrue(withinBeansPc.matches(TestBean.class));
|
||||
assertTrue(withinBeansPc.matches(getAge, TestBean.class));
|
||||
assertEquals(matchSubpackages, withinBeansPc.matches(DeepBean.class));
|
||||
assertEquals(matchSubpackages, withinBeansPc.matches(
|
||||
DeepBean.class.getMethod("aMethod", String.class), DeepBean.class));
|
||||
assertFalse(withinBeansPc.matches(String.class));
|
||||
assertFalse(withinBeansPc.matches(OtherIOther.class.getMethod("absquatulate"), OtherIOther.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocationClassMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
try {
|
||||
pc.matches(ITestBean.class);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
assertTrue(ex.getMessage().contains("expression"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocation2ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class))
|
||||
.withMessageContaining("expression");
|
||||
try {
|
||||
pc.matches(getAge, ITestBean.class);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
assertTrue(ex.getMessage().contains("expression"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFriendlyErrorOnNoLocation3ArgMatching() {
|
||||
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
pc.matches(getAge, ITestBean.class, (Object[]) null))
|
||||
.withMessageContaining("expression");
|
||||
try {
|
||||
pc.matches(getAge, ITestBean.class, (Object[]) null);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
assertTrue(ex.getMessage().contains("expression"));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -198,10 +207,12 @@ public class AspectJExpressionPointcutTests {
|
||||
// not currently testable in a reliable fashion
|
||||
//assertDoesNotMatchStringClass(classFilter);
|
||||
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12))).as("Should match with setSomeNumber with Double input").isTrue();
|
||||
assertThat(methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11))).as("Should not match setSomeNumber with Integer input").isFalse();
|
||||
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
|
||||
assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
|
||||
assertTrue("Should match with setSomeNumber with Double input",
|
||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Double(12)));
|
||||
assertFalse("Should not match setSomeNumber with Integer input",
|
||||
methodMatcher.matches(setSomeNumber, TestBean.class, new Integer(11)));
|
||||
assertFalse("Should not match getAge", methodMatcher.matches(getAge, TestBean.class));
|
||||
assertTrue("Should be a runtime match", methodMatcher.isRuntime());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -210,11 +221,11 @@ public class AspectJExpressionPointcutTests {
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor();
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor);
|
||||
|
||||
assertThat(interceptor.getCount()).as("Calls should be 0").isEqualTo(0);
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount());
|
||||
testBean.getAge();
|
||||
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
testBean.setAge(90);
|
||||
assertThat(interceptor.getCount()).as("Calls should still be 1").isEqualTo(1);
|
||||
assertEquals("Calls should still be 1", 1, interceptor.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -223,19 +234,25 @@ public class AspectJExpressionPointcutTests {
|
||||
CallCountingInterceptor interceptor = new CallCountingInterceptor();
|
||||
TestBean testBean = getAdvisedProxy(expression, interceptor);
|
||||
|
||||
assertThat(interceptor.getCount()).as("Calls should be 0").isEqualTo(0);
|
||||
assertEquals("Calls should be 0", 0, interceptor.getCount());
|
||||
testBean.setSomeNumber(new Double(30));
|
||||
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
|
||||
testBean.setSomeNumber(new Integer(90));
|
||||
assertThat(interceptor.getCount()).as("Calls should be 1").isEqualTo(1);
|
||||
assertEquals("Calls should be 1", 1, interceptor.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInvalidExpression() {
|
||||
String expression = "execution(void org.springframework.tests.sample.beans.TestBean.setSomeNumber(Number) && args(Double)";
|
||||
assertThatIllegalArgumentException().isThrownBy(
|
||||
getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
|
||||
|
||||
try {
|
||||
getPointcut(expression).getClassFilter(); // call to getClassFilter forces resolution
|
||||
fail("Invalid expression should throw IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
assertTrue(true);
|
||||
}
|
||||
}
|
||||
|
||||
private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
|
||||
@@ -255,33 +272,38 @@ public class AspectJExpressionPointcutTests {
|
||||
}
|
||||
|
||||
private void assertMatchesGetAge(MethodMatcher methodMatcher) {
|
||||
assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Expression should match getAge() method").isTrue();
|
||||
assertTrue("Expression should match getAge() method", methodMatcher.matches(getAge, TestBean.class));
|
||||
}
|
||||
|
||||
private void assertMatchesTestBeanClass(ClassFilter classFilter) {
|
||||
assertThat(classFilter.matches(TestBean.class)).as("Expression should match TestBean class").isTrue();
|
||||
assertTrue("Expression should match TestBean class", classFilter.matches(TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithUnsupportedPointcutPrimitive() {
|
||||
String expression = "call(int org.springframework.tests.sample.beans.TestBean.getAge())";
|
||||
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class).isThrownBy(() ->
|
||||
getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
|
||||
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL));
|
||||
|
||||
try {
|
||||
getPointcut(expression).getClassFilter(); // call to getClassFilter forces resolution...
|
||||
fail("Should not support call pointcuts");
|
||||
}
|
||||
catch (UnsupportedPointcutPrimitiveException ex) {
|
||||
assertEquals("Should not support call pointcut", PointcutPrimitive.CALL, ex.getUnsupportedPrimitive());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAndSubstitution() {
|
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
|
||||
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String)");
|
||||
assertEquals("execution(* *(..)) && args(String)",expr.getPointcutExpression());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMultipleAndSubstitutions() {
|
||||
Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
|
||||
PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
|
||||
assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
|
||||
assertEquals("execution(* *(..)) && args(String) && this(Object)",expr.getPointcutExpression());
|
||||
}
|
||||
|
||||
private Pointcut getPointcut(String expression) {
|
||||
|
||||
+6
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests for matching of bean() pointcut designator.
|
||||
@@ -79,11 +79,13 @@ public class BeanNamePointcutMatchingTests {
|
||||
|
||||
|
||||
private void assertMatch(String beanName, String pcExpression) {
|
||||
assertThat(matches(beanName, pcExpression)).as("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"").isTrue();
|
||||
assertTrue("Unexpected mismatch for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"",
|
||||
matches(beanName, pcExpression));
|
||||
}
|
||||
|
||||
private void assertMisMatch(String beanName, String pcExpression) {
|
||||
assertThat(matches(beanName, pcExpression)).as("Unexpected match for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"").isFalse();
|
||||
assertFalse("Unexpected match for bean \"" + beanName + "\" for pcExpression \"" + pcExpression + "\"",
|
||||
matches(beanName, pcExpression));
|
||||
}
|
||||
|
||||
private static boolean matches(final String beanName, String pcExpression) {
|
||||
|
||||
+61
-40
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -37,9 +37,7 @@ import org.springframework.lang.Nullable;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -51,14 +49,24 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
|
||||
@Test
|
||||
public void testingBindingWithJoinPoint() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
AbstractAspectJAdvice::currentJoinPoint);
|
||||
try {
|
||||
AbstractAspectJAdvice.currentJoinPoint();
|
||||
fail("Needs to be bound by interceptor action");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testingBindingWithProceedingJoinPoint() {
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
AbstractAspectJAdvice::currentJoinPoint);
|
||||
try {
|
||||
AbstractAspectJAdvice.currentJoinPoint();
|
||||
fail("Needs to be bound by interceptor action");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -76,21 +84,21 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
|
||||
assertThat(jp.toString().contains(method.getName())).as("Method named in toString").isTrue();
|
||||
assertTrue("Method named in toString", jp.toString().contains(method.getName()));
|
||||
// Ensure that these don't cause problems
|
||||
jp.toShortString();
|
||||
jp.toLongString();
|
||||
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getTarget()).isSameAs(target);
|
||||
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget())).isFalse();
|
||||
assertSame(target, AbstractAspectJAdvice.currentJoinPoint().getTarget());
|
||||
assertFalse(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getTarget()));
|
||||
|
||||
ITestBean thisProxy = (ITestBean) AbstractAspectJAdvice.currentJoinPoint().getThis();
|
||||
assertThat(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis())).isTrue();
|
||||
assertTrue(AopUtils.isAopProxy(AbstractAspectJAdvice.currentJoinPoint().getThis()));
|
||||
|
||||
assertThat(thisProxy).isNotSameAs(target);
|
||||
assertNotSame(target, thisProxy);
|
||||
|
||||
// Check getting again doesn't cause a problem
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getThis()).isSameAs(thisProxy);
|
||||
assertSame(thisProxy, AbstractAspectJAdvice.currentJoinPoint().getThis());
|
||||
|
||||
// Try reentrant call--will go through this advice.
|
||||
// Be sure to increment depth to avoid infinite recursion
|
||||
@@ -99,29 +107,29 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
thisProxy.toString();
|
||||
// Change age, so this will be returned by invocation
|
||||
thisProxy.setAge(newAge);
|
||||
assertThat(thisProxy.getAge()).isEqualTo(newAge);
|
||||
assertEquals(newAge, thisProxy.getAge());
|
||||
}
|
||||
|
||||
assertThat(thisProxy).isSameAs(AopContext.currentProxy());
|
||||
assertThat(raw).isSameAs(target);
|
||||
assertSame(AopContext.currentProxy(), thisProxy);
|
||||
assertSame(target, raw);
|
||||
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getName()).isSameAs(method.getName());
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers()).isEqualTo(method.getModifiers());
|
||||
assertSame(method.getName(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getName());
|
||||
assertEquals(method.getModifiers(), AbstractAspectJAdvice.currentJoinPoint().getSignature().getModifiers());
|
||||
|
||||
MethodSignature msig = (MethodSignature) AbstractAspectJAdvice.currentJoinPoint().getSignature();
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSignature()).as("Return same MethodSignature repeatedly").isSameAs(msig);
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint()).as("Return same JoinPoint repeatedly").isSameAs(AbstractAspectJAdvice.currentJoinPoint());
|
||||
assertThat(msig.getDeclaringType()).isEqualTo(method.getDeclaringClass());
|
||||
assertThat(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes())).isTrue();
|
||||
assertThat(msig.getReturnType()).isEqualTo(method.getReturnType());
|
||||
assertThat(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes())).isTrue();
|
||||
assertSame("Return same MethodSignature repeatedly", msig, AbstractAspectJAdvice.currentJoinPoint().getSignature());
|
||||
assertSame("Return same JoinPoint repeatedly", AbstractAspectJAdvice.currentJoinPoint(), AbstractAspectJAdvice.currentJoinPoint());
|
||||
assertEquals(method.getDeclaringClass(), msig.getDeclaringType());
|
||||
assertTrue(Arrays.equals(method.getParameterTypes(), msig.getParameterTypes()));
|
||||
assertEquals(method.getReturnType(), msig.getReturnType());
|
||||
assertTrue(Arrays.equals(method.getExceptionTypes(), msig.getExceptionTypes()));
|
||||
msig.toLongString();
|
||||
msig.toShortString();
|
||||
}
|
||||
});
|
||||
ITestBean itb = (ITestBean) pf.getProxy();
|
||||
// Any call will do
|
||||
assertThat(itb.getAge()).as("Advice reentrantly set age").isEqualTo(newAge);
|
||||
assertEquals("Advice reentrantly set age", newAge, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,10 +141,23 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
||||
SourceLocation sloc = AbstractAspectJAdvice.currentJoinPoint().getSourceLocation();
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation()).as("Same source location must be returned on subsequent requests").isEqualTo(sloc);
|
||||
assertThat(sloc.getWithinType()).isEqualTo(TestBean.class);
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getLine);
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(sloc::getFileName);
|
||||
assertEquals("Same source location must be returned on subsequent requests", sloc, AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
|
||||
assertEquals(TestBean.class, sloc.getWithinType());
|
||||
try {
|
||||
sloc.getLine();
|
||||
fail("Can't get line number");
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Expected
|
||||
}
|
||||
|
||||
try {
|
||||
sloc.getFileName();
|
||||
fail("Can't get file name");
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Expected
|
||||
}
|
||||
}
|
||||
});
|
||||
ITestBean itb = (ITestBean) pf.getProxy();
|
||||
@@ -153,10 +174,10 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
@Override
|
||||
public void before(Method method, Object[] args, @Nullable Object target) throws Throwable {
|
||||
StaticPart staticPart = AbstractAspectJAdvice.currentJoinPoint().getStaticPart();
|
||||
assertThat(AbstractAspectJAdvice.currentJoinPoint().getStaticPart()).as("Same static part must be returned on subsequent requests").isEqualTo(staticPart);
|
||||
assertThat(staticPart.getKind()).isEqualTo(ProceedingJoinPoint.METHOD_EXECUTION);
|
||||
assertThat(staticPart.getSignature()).isSameAs(AbstractAspectJAdvice.currentJoinPoint().getSignature());
|
||||
assertThat(staticPart.getSourceLocation()).isEqualTo(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation());
|
||||
assertEquals("Same static part must be returned on subsequent requests", staticPart, AbstractAspectJAdvice.currentJoinPoint().getStaticPart());
|
||||
assertEquals(ProceedingJoinPoint.METHOD_EXECUTION, staticPart.getKind());
|
||||
assertSame(AbstractAspectJAdvice.currentJoinPoint().getSignature(), staticPart.getSignature());
|
||||
assertEquals(AbstractAspectJAdvice.currentJoinPoint().getSourceLocation(), staticPart.getSourceLocation());
|
||||
}
|
||||
});
|
||||
ITestBean itb = (ITestBean) pf.getProxy();
|
||||
@@ -177,13 +198,13 @@ public class MethodInvocationProceedingJoinPointTests {
|
||||
JoinPoint.StaticPart aspectJVersionJp = Factory.makeEncSJP(method);
|
||||
JoinPoint jp = AbstractAspectJAdvice.currentJoinPoint();
|
||||
|
||||
assertThat(jp.getSignature().toLongString()).isEqualTo(aspectJVersionJp.getSignature().toLongString());
|
||||
assertThat(jp.getSignature().toShortString()).isEqualTo(aspectJVersionJp.getSignature().toShortString());
|
||||
assertThat(jp.getSignature().toString()).isEqualTo(aspectJVersionJp.getSignature().toString());
|
||||
assertEquals(aspectJVersionJp.getSignature().toLongString(), jp.getSignature().toLongString());
|
||||
assertEquals(aspectJVersionJp.getSignature().toShortString(), jp.getSignature().toShortString());
|
||||
assertEquals(aspectJVersionJp.getSignature().toString(), jp.getSignature().toString());
|
||||
|
||||
assertThat(jp.toLongString()).isEqualTo(aspectJVersionJp.toLongString());
|
||||
assertThat(jp.toShortString()).isEqualTo(aspectJVersionJp.toShortString());
|
||||
assertThat(jp.toString()).isEqualTo(aspectJVersionJp.toString());
|
||||
assertEquals(aspectJVersionJp.toLongString(), jp.toLongString());
|
||||
assertEquals(aspectJVersionJp.toShortString(), jp.toShortString());
|
||||
assertEquals(aspectJVersionJp.toString(), jp.toString());
|
||||
}
|
||||
});
|
||||
ITestBean itb = (ITestBean) pf.getProxy();
|
||||
|
||||
+65
-66
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -29,7 +29,7 @@ import test.annotation.transaction.Tx;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Java 5 specific {@link AspectJExpressionPointcutTests}.
|
||||
@@ -65,12 +65,12 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
//assertFalse(ajexp.matches(TestBean.class));
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(ajexp.matches(takesGenericList, HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isTrue();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
assertTrue(ajexp.matches(takesGenericList, HasGeneric.class));
|
||||
assertTrue(ajexp.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
|
||||
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class));
|
||||
assertFalse(ajexp.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -87,16 +87,16 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut jdbcVarArgs = new AspectJExpressionPointcut();
|
||||
jdbcVarArgs.setExpression(expression);
|
||||
|
||||
assertThat(jdbcVarArgs.matches(
|
||||
assertTrue(jdbcVarArgs.matches(
|
||||
MyTemplate.class.getMethod("queryForInt", String.class, Object[].class),
|
||||
MyTemplate.class)).isTrue();
|
||||
MyTemplate.class));
|
||||
|
||||
Method takesGenericList = methodsOnHasGeneric.get("setFriends");
|
||||
assertThat(jdbcVarArgs.matches(takesGenericList, HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class)).isFalse();
|
||||
assertThat(jdbcVarArgs.matches(getAge, TestBean.class)).isFalse();
|
||||
assertFalse(jdbcVarArgs.matches(takesGenericList, HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setEnemies"), HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPartners"), HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(methodsOnHasGeneric.get("setPhoneNumbers"), HasGeneric.class));
|
||||
assertFalse(jdbcVarArgs.matches(getAge, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -115,12 +115,12 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception {
|
||||
String expression = "within(@(test.annotation..*) *)";
|
||||
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse();
|
||||
assertThat(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isTrue();
|
||||
assertFalse(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class));
|
||||
assertTrue(springAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
|
||||
|
||||
expression = "within(@(test.annotation.transaction..*) *)";
|
||||
AspectJExpressionPointcut springTxAnnotatedPc = testMatchAnnotationOnClass(expression);
|
||||
assertThat(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class)).isFalse();
|
||||
assertFalse(springTxAnnotatedPc.matches(SpringAnnotated.class.getMethod("foo"), SpringAnnotated.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -133,11 +133,11 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertTrue(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertTrue(ajexp.matches(BeanB.class.getMethod("setName", String.class), BeanB.class));
|
||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
return ajexp;
|
||||
}
|
||||
|
||||
@@ -147,12 +147,12 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut();
|
||||
ajexp.setExpression(expression);
|
||||
|
||||
assertThat(ajexp.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertFalse(ajexp.matches(getAge, TestBean.class));
|
||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(ajexp.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(ajexp.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -164,7 +164,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(true);
|
||||
BeanA proxy = (BeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
assertTrue(ajexp.matches(BeanA.class.getMethod("getAge"), proxy.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -176,7 +176,7 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
ProxyFactory factory = new ProxyFactory(new BeanA());
|
||||
factory.setProxyTargetClass(false);
|
||||
IBeanA proxy = (IBeanA) factory.getProxy();
|
||||
assertThat(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass())).isTrue();
|
||||
assertTrue(ajexp.matches(IBeanA.class.getMethod("getAge"), proxy.getClass()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -185,14 +185,14 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut();
|
||||
anySpringMethodAnnotation.setExpression(expression);
|
||||
|
||||
assertThat(anySpringMethodAnnotation.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isTrue();
|
||||
assertThat(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertFalse(anySpringMethodAnnotation.matches(getAge, TestBean.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertTrue(anySpringMethodAnnotation.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(anySpringMethodAnnotation.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -201,27 +201,28 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
|
||||
// True because it maybeMatches with potential argument subtypes
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())).isFalse();
|
||||
ProcessesSpringAnnotatedParameters.class, new TestBean(), new BeanA())
|
||||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,21 +231,21 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
|
||||
takesSpringAnnotatedArgument2.setExpression(expression);
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class));
|
||||
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
assertTrue(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isTrue();
|
||||
assertThat(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
assertFalse(takesSpringAnnotatedArgument2.matches(
|
||||
ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class),
|
||||
ProcessesSpringAnnotatedParameters.class)).isFalse();
|
||||
ProcessesSpringAnnotatedParameters.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -299,7 +300,6 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
|
||||
static class BeanA implements IBeanA {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
private int age;
|
||||
@@ -319,7 +319,6 @@ public class TigerAspectJExpressionPointcutTests {
|
||||
@Tx
|
||||
static class BeanB {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private String name;
|
||||
|
||||
public void setName(String name) {
|
||||
|
||||
+11
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,8 +34,7 @@ import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.core.OverridingClassLoader;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
@@ -111,10 +110,15 @@ public class TrickyAspectJPointcutExpressionTests {
|
||||
factory.addAdvisor(advisor);
|
||||
TestService bean = (TestService) factory.getProxy();
|
||||
|
||||
assertThat(logAdvice.getCountThrows()).isEqualTo(0);
|
||||
assertThatExceptionOfType(TestException.class).isThrownBy(
|
||||
bean::sayHello).withMessageContaining(message);
|
||||
assertThat(logAdvice.getCountThrows()).isEqualTo(1);
|
||||
assertEquals(0, logAdvice.getCountThrows());
|
||||
try {
|
||||
bean.sayHello();
|
||||
fail("Expected exception");
|
||||
}
|
||||
catch (TestException ex) {
|
||||
assertEquals(message, ex.getMessage());
|
||||
}
|
||||
assertEquals(1, logAdvice.getCountThrows());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+26
-31
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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 org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.tests.sample.beans.subpkg.DeepBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link TypePatternClassFilter} class.
|
||||
@@ -39,58 +37,55 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*/
|
||||
public class TypePatternClassFilterTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testInvalidPattern() {
|
||||
// should throw - pattern must be recognized as invalid
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new TypePatternClassFilter("-"));
|
||||
new TypePatternClassFilter("-");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testValidPatternMatching() {
|
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.*");
|
||||
assertThat(tpcf.matches(TestBean.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(ITestBean.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(IOther.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(DeepBean.class)).as("Must be excluded: in wrong package").isFalse();
|
||||
assertThat(tpcf.matches(BeanFactory.class)).as("Must be excluded: in wrong package").isFalse();
|
||||
assertThat(tpcf.matches(DefaultListableBeanFactory.class)).as("Must be excluded: in wrong package").isFalse();
|
||||
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
|
||||
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
|
||||
assertTrue("Must match: in package", tpcf.matches(IOther.class));
|
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(DeepBean.class));
|
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(BeanFactory.class));
|
||||
assertFalse("Must be excluded: in wrong package", tpcf.matches(DefaultListableBeanFactory.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSubclassMatching() {
|
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("org.springframework.tests.sample.beans.ITestBean+");
|
||||
assertThat(tpcf.matches(TestBean.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(ITestBean.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(CountingTestBean.class)).as("Must match: in package").isTrue();
|
||||
assertThat(tpcf.matches(IOther.class)).as("Must be excluded: not subclass").isFalse();
|
||||
assertThat(tpcf.matches(DefaultListableBeanFactory.class)).as("Must be excluded: not subclass").isFalse();
|
||||
assertTrue("Must match: in package", tpcf.matches(TestBean.class));
|
||||
assertTrue("Must match: in package", tpcf.matches(ITestBean.class));
|
||||
assertTrue("Must match: in package", tpcf.matches(CountingTestBean.class));
|
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(IOther.class));
|
||||
assertFalse("Must be excluded: not subclass", tpcf.matches(DefaultListableBeanFactory.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAndOrNotReplacement() {
|
||||
TypePatternClassFilter tpcf = new TypePatternClassFilter("java.lang.Object or java.lang.String");
|
||||
assertThat(tpcf.matches(Number.class)).as("matches Number").isFalse();
|
||||
assertThat(tpcf.matches(Object.class)).as("matches Object").isTrue();
|
||||
assertThat(tpcf.matches(String.class)).as("matchesString").isTrue();
|
||||
assertFalse("matches Number",tpcf.matches(Number.class));
|
||||
assertTrue("matches Object",tpcf.matches(Object.class));
|
||||
assertTrue("matchesString",tpcf.matches(String.class));
|
||||
tpcf = new TypePatternClassFilter("java.lang.Number+ and java.lang.Float");
|
||||
assertThat(tpcf.matches(Float.class)).as("matches Float").isTrue();
|
||||
assertThat(tpcf.matches(Double.class)).as("matches Double").isFalse();
|
||||
assertTrue("matches Float",tpcf.matches(Float.class));
|
||||
assertFalse("matches Double",tpcf.matches(Double.class));
|
||||
tpcf = new TypePatternClassFilter("java.lang.Number+ and not java.lang.Float");
|
||||
assertThat(tpcf.matches(Float.class)).as("matches Float").isFalse();
|
||||
assertThat(tpcf.matches(Double.class)).as("matches Double").isTrue();
|
||||
assertFalse("matches Float",tpcf.matches(Float.class));
|
||||
assertTrue("matches Double",tpcf.matches(Double.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetTypePatternWithNullArgument() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new TypePatternClassFilter(null));
|
||||
new TypePatternClassFilter(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testInvocationOfMatchesMethodBlowsUpWhenNoTypePatternHasBeenSet() throws Exception {
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
new TypePatternClassFilter().matches(String.class));
|
||||
new TypePatternClassFilter().matches(String.class);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+154
-117
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -58,10 +58,8 @@ import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Abstract tests for AspectJAdvisorFactory.
|
||||
@@ -82,18 +80,26 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Test
|
||||
public void testRejectsPerCflowAspect() {
|
||||
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(), "someBean")))
|
||||
.withMessageContaining("PERCFLOW");
|
||||
try {
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowAspect(), "someBean"));
|
||||
fail("Cannot accept cflow");
|
||||
}
|
||||
catch (AopConfigException ex) {
|
||||
assertTrue(ex.getMessage().contains("PERCFLOW"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectsPerCflowBelowAspect() {
|
||||
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(), "someBean")))
|
||||
.withMessageContaining("PERCFLOWBELOW");
|
||||
try {
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerCflowBelowAspect(), "someBean"));
|
||||
fail("Cannot accept cflowbelow");
|
||||
}
|
||||
catch (AopConfigException ex) {
|
||||
assertTrue(ex.getMessage().contains("PERCFLOWBELOW"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,28 +110,28 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean")),
|
||||
TestBean.class);
|
||||
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[3];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
|
||||
assertThat(maaif.isMaterialized()).isFalse();
|
||||
assertFalse(maaif.isMaterialized());
|
||||
|
||||
// Check that the perclause pointcut is valid
|
||||
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
assertThat(maaif.isMaterialized()).isTrue();
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
assertEquals("Around advice must apply", 1, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -147,13 +153,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
Collections.sort(advisors, new OrderComparator());
|
||||
|
||||
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
|
||||
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
assertEquals("Around advice must apply", 1, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -173,13 +179,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
Collections.sort(advisors, new OrderComparator());
|
||||
|
||||
TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
|
||||
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
assertEquals("Around advice must apply", 1, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -190,32 +196,32 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TestBean itb = (TestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(new PerThisAspect(), "someBean")),
|
||||
TestBean.class);
|
||||
assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
|
||||
assertEquals("Around advice must NOT apply", realAge, itb.getAge());
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertThat(advised.getAdvisors().length).isEqualTo(4);
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
|
||||
assertThat(maaif.isMaterialized()).isFalse();
|
||||
assertFalse(maaif.isMaterialized());
|
||||
|
||||
// Check that the perclause pointcut is valid
|
||||
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
assertThat(maaif.isMaterialized()).isTrue();
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)).isTrue();
|
||||
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
|
||||
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
|
||||
assertEquals("Around advice must apply", 0, itb.getAge());
|
||||
assertEquals("Around advice must apply", 1, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -225,38 +231,38 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
target.setAge(realAge);
|
||||
PerTypeWithinAspectInstanceFactory aif = new PerTypeWithinAspectInstanceFactory();
|
||||
TestBean itb = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
|
||||
assertThat(aif.getInstantiationCount()).as("No method calls").isEqualTo(0);
|
||||
assertThat(itb.getAge()).as("Around advice must now apply").isEqualTo(0);
|
||||
assertEquals("No method calls", 0, aif.getInstantiationCount());
|
||||
assertEquals("Around advice must now apply", 0, itb.getAge());
|
||||
|
||||
Advised advised = (Advised) itb;
|
||||
// Will be ExposeInvocationInterceptor, synthetic instantiation advisor, 2 method advisors
|
||||
assertThat(advised.getAdvisors().length).isEqualTo(4);
|
||||
assertEquals(4, advised.getAdvisors().length);
|
||||
ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor sia =
|
||||
(ReflectiveAspectJAdvisorFactory.SyntheticInstantiationAdvisor) advised.getAdvisors()[1];
|
||||
assertThat(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertTrue(sia.getPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
InstantiationModelAwarePointcutAdvisorImpl imapa = (InstantiationModelAwarePointcutAdvisorImpl) advised.getAdvisors()[2];
|
||||
LazySingletonAspectInstanceFactoryDecorator maaif =
|
||||
(LazySingletonAspectInstanceFactoryDecorator) imapa.getAspectInstanceFactory();
|
||||
assertThat(maaif.isMaterialized()).isTrue();
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
// Check that the perclause pointcut is valid
|
||||
assertThat(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null)).isTrue();
|
||||
assertThat(imapa.getPointcut()).isNotSameAs(imapa.getDeclaredPointcut());
|
||||
assertTrue(maaif.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(TestBean.class.getMethod("getSpouse"), null));
|
||||
assertNotSame(imapa.getDeclaredPointcut(), imapa.getPointcut());
|
||||
|
||||
// Hit the method in the per clause to instantiate the aspect
|
||||
itb.getSpouse();
|
||||
|
||||
assertThat(maaif.isMaterialized()).isTrue();
|
||||
assertTrue(maaif.isMaterialized());
|
||||
|
||||
assertThat(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null)).isTrue();
|
||||
assertTrue(imapa.getDeclaredPointcut().getMethodMatcher().matches(TestBean.class.getMethod("getAge"), null));
|
||||
|
||||
assertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(1);
|
||||
assertThat(itb.getAge()).as("Around advice must still apply").isEqualTo(2);
|
||||
assertEquals("Around advice must still apply", 1, itb.getAge());
|
||||
assertEquals("Around advice must still apply", 2, itb.getAge());
|
||||
|
||||
TestBean itb2 = (TestBean) createProxy(target, getFixture().getAdvisors(aif), TestBean.class);
|
||||
assertThat(aif.getInstantiationCount()).isEqualTo(1);
|
||||
assertThat(itb2.getAge()).as("Around advice be independent for second instance").isEqualTo(0);
|
||||
assertThat(aif.getInstantiationCount()).isEqualTo(2);
|
||||
assertEquals(1, aif.getInstantiationCount());
|
||||
assertEquals("Around advice be independent for second instance", 0, itb2.getAge());
|
||||
assertEquals(2, aif.getInstantiationCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -282,8 +288,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
new NamedPointcutAspectFromLibraryWithBinding(), "someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(20);
|
||||
assertThat(target.getAge()).isEqualTo(20);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
assertEquals(20,target.getAge());
|
||||
}
|
||||
|
||||
private void testNamedPointcuts(Object aspectInstance) {
|
||||
@@ -293,8 +299,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
ITestBean itb = (ITestBean) createProxy(target,
|
||||
getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspectInstance, "someBean")),
|
||||
ITestBean.class);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(-1);
|
||||
assertThat(target.getAge()).isEqualTo(realAge);
|
||||
assertEquals("Around advice must apply", -1, itb.getAge());
|
||||
assertEquals(realAge, target.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -305,8 +311,8 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new BindingAspectWithSingleArg(), "someBean")),
|
||||
ITestBean.class);
|
||||
itb.setAge(10);
|
||||
assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(20);
|
||||
assertThat(target.getAge()).isEqualTo(20);
|
||||
assertEquals("Around advice must apply", 20, itb.getAge());
|
||||
assertEquals(20,target.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -323,7 +329,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
String d = "d";
|
||||
StringBuffer e = new StringBuffer("stringbuf");
|
||||
String expectedResult = a + b+ c + d + e;
|
||||
assertThat(mva.mungeArgs(a, b, c, d, e)).isEqualTo(expectedResult);
|
||||
assertEquals(expectedResult, mva.mungeArgs(a, b, c, d, e));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -332,40 +338,44 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Test
|
||||
public void testIntroductionOnTargetNotImplementingInterface() {
|
||||
NotLockable notLockableTarget = new NotLockable();
|
||||
assertThat(notLockableTarget instanceof Lockable).isFalse();
|
||||
assertFalse(notLockableTarget instanceof Lockable);
|
||||
NotLockable notLockable1 = (NotLockable) createProxy(notLockableTarget,
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
NotLockable.class);
|
||||
assertThat(notLockable1 instanceof Lockable).isTrue();
|
||||
assertTrue(notLockable1 instanceof Lockable);
|
||||
Lockable lockable = (Lockable) notLockable1;
|
||||
assertThat(lockable.locked()).isFalse();
|
||||
assertFalse(lockable.locked());
|
||||
lockable.lock();
|
||||
assertThat(lockable.locked()).isTrue();
|
||||
assertTrue(lockable.locked());
|
||||
|
||||
NotLockable notLockable2Target = new NotLockable();
|
||||
NotLockable notLockable2 = (NotLockable) createProxy(notLockable2Target,
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
NotLockable.class);
|
||||
assertThat(notLockable2 instanceof Lockable).isTrue();
|
||||
assertTrue(notLockable2 instanceof Lockable);
|
||||
Lockable lockable2 = (Lockable) notLockable2;
|
||||
assertThat(lockable2.locked()).isFalse();
|
||||
assertFalse(lockable2.locked());
|
||||
notLockable2.setIntValue(1);
|
||||
lockable2.lock();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
notLockable2.setIntValue(32));
|
||||
assertThat(lockable2.locked()).isTrue();
|
||||
try {
|
||||
notLockable2.setIntValue(32);
|
||||
fail();
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
}
|
||||
assertTrue(lockable2.locked());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntroductionAdvisorExcludedFromTargetImplementingInterface() {
|
||||
assertThat(AopUtils.findAdvisorsThatCanApply(
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
CannotBeUnlocked.class).isEmpty()).isTrue();
|
||||
assertThat(AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size()).isEqualTo(2);
|
||||
assertTrue(AopUtils.findAdvisorsThatCanApply(
|
||||
getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")),
|
||||
CannotBeUnlocked.class).isEmpty());
|
||||
assertEquals(2, AopUtils.findAdvisorsThatCanApply(getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(),"someBean")), NotLockable.class).size());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -379,13 +389,18 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
CannotBeUnlocked.class
|
||||
),
|
||||
CannotBeUnlocked.class);
|
||||
assertThat(proxy).isInstanceOf(Lockable.class);
|
||||
assertThat(proxy, instanceOf(Lockable.class));
|
||||
Lockable lockable = proxy;
|
||||
assertThat(lockable.locked()).as("Already locked").isTrue();
|
||||
assertTrue("Already locked", lockable.locked());
|
||||
lockable.lock();
|
||||
assertThat(lockable.locked()).as("Real target ignores locking").isTrue();
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() ->
|
||||
lockable.unlock());
|
||||
assertTrue("Real target ignores locking", lockable.locked());
|
||||
try {
|
||||
lockable.unlock();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
// Ok
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -397,7 +412,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
List.class
|
||||
),
|
||||
List.class);
|
||||
assertThat(proxy instanceof Lockable).as("Type pattern must have excluded mixin").isFalse();
|
||||
assertFalse("Type pattern must have excluded mixin", proxy instanceof Lockable);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -407,7 +422,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeAnnotatedTypeModifiable(), "someBean"));
|
||||
Object proxy = createProxy(target, advisors, AnnotatedTarget.class);
|
||||
System.out.println(advisors.get(1));
|
||||
assertThat(proxy instanceof Lockable).isTrue();
|
||||
assertTrue(proxy instanceof Lockable);
|
||||
Lockable lockable = (Lockable)proxy;
|
||||
lockable.locked();
|
||||
}
|
||||
@@ -424,26 +439,31 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new MakeLockable(), "someBean")));
|
||||
|
||||
Modifiable modifiable = (Modifiable) createProxy(target, advisors, ITestBean.class);
|
||||
assertThat(modifiable).isInstanceOf(Modifiable.class);
|
||||
assertThat(modifiable, instanceOf(Modifiable.class));
|
||||
Lockable lockable = (Lockable) modifiable;
|
||||
assertThat(lockable.locked()).isFalse();
|
||||
assertFalse(lockable.locked());
|
||||
|
||||
ITestBean itb = (ITestBean) modifiable;
|
||||
assertThat(modifiable.isModified()).isFalse();
|
||||
assertFalse(modifiable.isModified());
|
||||
int oldAge = itb.getAge();
|
||||
itb.setAge(oldAge + 1);
|
||||
assertThat(modifiable.isModified()).isTrue();
|
||||
assertTrue(modifiable.isModified());
|
||||
modifiable.acceptChanges();
|
||||
assertThat(modifiable.isModified()).isFalse();
|
||||
assertFalse(modifiable.isModified());
|
||||
itb.setAge(itb.getAge());
|
||||
assertThat(modifiable.isModified()).as("Setting same value does not modify").isFalse();
|
||||
assertFalse("Setting same value does not modify", modifiable.isModified());
|
||||
itb.setName("And now for something completely different");
|
||||
assertThat(modifiable.isModified()).isTrue();
|
||||
assertTrue(modifiable.isModified());
|
||||
|
||||
lockable.lock();
|
||||
assertThat(lockable.locked()).isTrue();
|
||||
assertThatIllegalStateException().as("Should be locked").isThrownBy(() ->
|
||||
itb.setName("Else"));
|
||||
assertTrue(lockable.locked());
|
||||
try {
|
||||
itb.setName("Else");
|
||||
fail("Should be locked");
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
// Ok
|
||||
}
|
||||
lockable.unlock();
|
||||
itb.setName("Tony");
|
||||
}
|
||||
@@ -454,10 +474,16 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
UnsupportedOperationException expectedException = new UnsupportedOperationException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
||||
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(
|
||||
itb::getAge);
|
||||
|
||||
try {
|
||||
itb.getAge();
|
||||
fail();
|
||||
}
|
||||
catch (UnsupportedOperationException ex) {
|
||||
assertSame(expectedException, ex);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO document this behaviour.
|
||||
@@ -468,10 +494,16 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
RemoteException expectedException = new RemoteException();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new ExceptionAspect(expectedException), "someBean"));
|
||||
assertThat(advisors.size()).as("One advice method was found").isEqualTo(1);
|
||||
assertEquals("One advice method was found", 1, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
assertThatExceptionOfType(UndeclaredThrowableException.class).isThrownBy(
|
||||
itb::getAge).withCause(expectedException);
|
||||
|
||||
try {
|
||||
itb.getAge();
|
||||
fail();
|
||||
}
|
||||
catch (UndeclaredThrowableException ex) {
|
||||
assertSame(expectedException, ex.getCause());
|
||||
}
|
||||
}
|
||||
|
||||
protected Object createProxy(Object target, List<Advisor> advisors, Class<?>... interfaces) {
|
||||
@@ -497,13 +529,13 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
|
||||
assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
|
||||
assertEquals("Two advice methods found", 2, advisors.size());
|
||||
ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
|
||||
itb.setName("");
|
||||
assertThat(itb.getAge()).isEqualTo(0);
|
||||
assertEquals(0, itb.getAge());
|
||||
int newAge = 32;
|
||||
itb.setAge(newAge);
|
||||
assertThat(itb.getAge()).isEqualTo(1);
|
||||
assertEquals(1, itb.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -513,15 +545,24 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
List<Advisor> advisors = getFixture().getAdvisors(
|
||||
new SingletonMetadataAwareAspectInstanceFactory(afterReturningAspect, "someBean"));
|
||||
Echo echo = (Echo) createProxy(target, advisors, Echo.class);
|
||||
assertThat(afterReturningAspect.successCount).isEqualTo(0);
|
||||
assertThat(echo.echo("")).isEqualTo("");
|
||||
assertThat(afterReturningAspect.successCount).isEqualTo(1);
|
||||
assertThat(afterReturningAspect.failureCount).isEqualTo(0);
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
|
||||
echo.echo(new FileNotFoundException()));
|
||||
assertThat(afterReturningAspect.successCount).isEqualTo(1);
|
||||
assertThat(afterReturningAspect.failureCount).isEqualTo(1);
|
||||
assertThat(afterReturningAspect.afterCount).isEqualTo(afterReturningAspect.failureCount + afterReturningAspect.successCount);
|
||||
assertEquals(0, afterReturningAspect.successCount);
|
||||
assertEquals("", echo.echo(""));
|
||||
assertEquals(1, afterReturningAspect.successCount);
|
||||
assertEquals(0, afterReturningAspect.failureCount);
|
||||
|
||||
try {
|
||||
echo.echo(new FileNotFoundException());
|
||||
fail();
|
||||
}
|
||||
catch (FileNotFoundException ex) {
|
||||
// Ok
|
||||
}
|
||||
catch (Exception ex) {
|
||||
fail();
|
||||
}
|
||||
assertEquals(1, afterReturningAspect.successCount);
|
||||
assertEquals(1, afterReturningAspect.failureCount);
|
||||
assertEquals(afterReturningAspect.failureCount + afterReturningAspect.successCount, afterReturningAspect.afterCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -534,14 +575,12 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
itb.getAge();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testDeclarePrecedenceNotSupported() {
|
||||
TestBean target = new TestBean();
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> {
|
||||
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new DeclarePrecedenceShouldSucceed(), "someBean");
|
||||
createProxy(target, getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
|
||||
});
|
||||
MetadataAwareAspectInstanceFactory aspectInstanceFactory = new SingletonMetadataAwareAspectInstanceFactory(
|
||||
new DeclarePrecedenceShouldSucceed(), "someBean");
|
||||
createProxy(target, getFixture().getAdvisors(aspectInstanceFactory), ITestBean.class);
|
||||
}
|
||||
|
||||
|
||||
@@ -647,7 +686,6 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
@Aspect
|
||||
public static class NamedPointcutAspectWithFQN {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
||||
|
||||
@Pointcut("execution(* getAge())")
|
||||
@@ -736,7 +774,7 @@ public abstract class AbstractAspectJAdvisorFactoryTests {
|
||||
|
||||
@Around(value="execution(String mungeArgs(..)) && args(a, b, c, d, e)", argNames="b,c,d,e,a")
|
||||
public String reverseAdvice(ProceedingJoinPoint pjp, int b, int c, String d, StringBuffer e, String a) throws Throwable {
|
||||
assertThat(pjp.proceed()).isEqualTo(a + b+ c+ d+ e);
|
||||
assertEquals(a + b+ c+ d+ e, pjp.proceed());
|
||||
return a + b + c + d + e;
|
||||
}
|
||||
}
|
||||
@@ -1050,7 +1088,6 @@ class PerThisAspect {
|
||||
public int count;
|
||||
|
||||
// Just to check that this doesn't cause problems with introduction processing
|
||||
@SuppressWarnings("unused")
|
||||
private ITestBean fieldThatShouldBeIgnoredBySpringAtAspectJProcessing = new TestBean();
|
||||
|
||||
@Around("execution(int *.getAge())")
|
||||
|
||||
+8
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -30,9 +30,7 @@ import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
@@ -41,26 +39,24 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
*/
|
||||
public class ArgumentBindingTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testBindingInPointcutUsedByAdvice() {
|
||||
TestBean tb = new TestBean();
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
|
||||
proxyFactory.addAspect(NamedPointcutWithArgs.class);
|
||||
|
||||
ITestBean proxiedTestBean = proxyFactory.getProxy();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
proxiedTestBean.setName("Supercalifragalisticexpialidocious"));
|
||||
proxiedTestBean.setName("Supercalifragalisticexpialidocious");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalStateException.class)
|
||||
public void testAnnotationArgumentNameBinding() {
|
||||
TransactionalBean tb = new TransactionalBean();
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(tb);
|
||||
proxyFactory.addAspect(PointcutWithAnnotationArgument.class);
|
||||
|
||||
ITransactionalBean proxiedTestBean = proxyFactory.getProxy();
|
||||
assertThatIllegalStateException().isThrownBy(
|
||||
proxiedTestBean::doInTransaction);
|
||||
proxiedTestBean.doInTransaction();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -71,8 +67,8 @@ public class ArgumentBindingTests {
|
||||
Method methodUsedForParameterTypeDiscovery =
|
||||
getClass().getMethod("methodWithOneParam", String.class);
|
||||
String[] pnames = discoverer.getParameterNames(methodUsedForParameterTypeDiscovery);
|
||||
assertThat(pnames.length).as("one parameter name").isEqualTo(1);
|
||||
assertThat(pnames[0]).isEqualTo("formal");
|
||||
assertEquals("one parameter name", 1, pnames.length);
|
||||
assertEquals("formal", pnames[0]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,8 +25,7 @@ import org.springframework.aop.aspectj.AspectJExpressionPointcutTests;
|
||||
import org.springframework.aop.framework.AopConfigException;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -47,8 +46,8 @@ public class AspectJPointcutAdvisorTests {
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new AbstractAspectJAdvisorFactoryTests.ExceptionAspect(null), "someBean"),
|
||||
1, "someBean");
|
||||
|
||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
||||
assertThat(ajpa.isPerInstance()).isFalse();
|
||||
assertSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||
assertFalse(ajpa.isPerInstance());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,29 +60,26 @@ public class AspectJPointcutAdvisorTests {
|
||||
new SingletonMetadataAwareAspectInstanceFactory(new PerTargetAspect(), "someBean"),
|
||||
1, "someBean");
|
||||
|
||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
|
||||
boolean condition = ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(ajpa.isPerInstance()).isTrue();
|
||||
assertNotSame(Pointcut.TRUE, ajpa.getAspectMetadata().getPerClausePointcut());
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut() instanceof AspectJExpressionPointcut);
|
||||
assertTrue(ajpa.isPerInstance());
|
||||
|
||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class)).isTrue();
|
||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getClassFilter().matches(TestBean.class));
|
||||
assertFalse(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getAge"), TestBean.class));
|
||||
|
||||
assertThat(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getSpouse"), TestBean.class)).isTrue();
|
||||
assertTrue(ajpa.getAspectMetadata().getPerClausePointcut().getMethodMatcher().matches(
|
||||
TestBean.class.getMethod("getSpouse"), TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = AopConfigException.class)
|
||||
public void testPerCflowTarget() {
|
||||
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class));
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowAspect.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = AopConfigException.class)
|
||||
public void testPerCflowBelowTarget() {
|
||||
assertThatExceptionOfType(AopConfigException.class).isThrownBy(() ->
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class));
|
||||
testIllegalInstantiationModel(AbstractAspectJAdvisorFactoryTests.PerCflowBelowAspect.class);
|
||||
}
|
||||
|
||||
private void testIllegalInstantiationModel(Class<?> c) throws AopConfigException {
|
||||
|
||||
+13
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -23,8 +23,7 @@ import test.aop.PerTargetAspect;
|
||||
import org.springframework.aop.Pointcut;
|
||||
import org.springframework.aop.aspectj.annotation.AbstractAspectJAdvisorFactoryTests.ExceptionAspect;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @since 2.0
|
||||
@@ -33,33 +32,32 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
public class AspectMetadataTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNotAnAspect() {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new AspectMetadata(String.class,"someBean"));
|
||||
new AspectMetadata(String.class,"someBean");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingletonAspect() {
|
||||
AspectMetadata am = new AspectMetadata(ExceptionAspect.class,"someBean");
|
||||
assertThat(am.isPerThisOrPerTarget()).isFalse();
|
||||
assertThat(am.getPerClausePointcut()).isSameAs(Pointcut.TRUE);
|
||||
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.SINGLETON);
|
||||
assertFalse(am.isPerThisOrPerTarget());
|
||||
assertSame(Pointcut.TRUE, am.getPerClausePointcut());
|
||||
assertEquals(PerClauseKind.SINGLETON, am.getAjType().getPerClause().getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerTargetAspect() {
|
||||
AspectMetadata am = new AspectMetadata(PerTargetAspect.class,"someBean");
|
||||
assertThat(am.isPerThisOrPerTarget()).isTrue();
|
||||
assertThat(am.getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
|
||||
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.PERTARGET);
|
||||
assertTrue(am.isPerThisOrPerTarget());
|
||||
assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
|
||||
assertEquals(PerClauseKind.PERTARGET, am.getAjType().getPerClause().getKind());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPerThisAspect() {
|
||||
AspectMetadata am = new AspectMetadata(PerThisAspect.class,"someBean");
|
||||
assertThat(am.isPerThisOrPerTarget()).isTrue();
|
||||
assertThat(am.getPerClausePointcut()).isNotSameAs(Pointcut.TRUE);
|
||||
assertThat(am.getAjType().getPerClause().getKind()).isEqualTo(PerClauseKind.PERTHIS);
|
||||
assertTrue(am.isPerThisOrPerTarget());
|
||||
assertNotSame(Pointcut.TRUE, am.getPerClausePointcut());
|
||||
assertEquals(PerClauseKind.PERTHIS, am.getAjType().getPerClause().getKind());
|
||||
}
|
||||
}
|
||||
|
||||
+20
-23
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,8 +28,7 @@ import test.aop.PerThisAspect;
|
||||
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -38,11 +37,10 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
*/
|
||||
public class AspectProxyFactoryTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithNonAspect() {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
proxyFactory.addAspect(TestBean.class));
|
||||
proxyFactory.addAspect(TestBean.class);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -52,7 +50,7 @@ public class AspectProxyFactoryTests {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(bean);
|
||||
proxyFactory.addAspect(MultiplyReturnValue.class);
|
||||
ITestBean proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy.getAge()).as("Multiplication did not occur").isEqualTo((bean.getAge() * 2));
|
||||
assertEquals("Multiplication did not occur", bean.getAge() * 2, proxy.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,17 +67,16 @@ public class AspectProxyFactoryTests {
|
||||
ITestBean proxy1 = pf1.getProxy();
|
||||
ITestBean proxy2 = pf2.getProxy();
|
||||
|
||||
assertThat(proxy1.getAge()).isEqualTo(0);
|
||||
assertThat(proxy1.getAge()).isEqualTo(1);
|
||||
assertThat(proxy2.getAge()).isEqualTo(0);
|
||||
assertThat(proxy1.getAge()).isEqualTo(2);
|
||||
assertEquals(0, proxy1.getAge());
|
||||
assertEquals(1, proxy1.getAge());
|
||||
assertEquals(0, proxy2.getAge());
|
||||
assertEquals(2, proxy1.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithInstanceWithNonAspect() throws Exception {
|
||||
AspectJProxyFactory pf = new AspectJProxyFactory();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
pf.addAspect(new TestBean()));
|
||||
pf.addAspect(new TestBean());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -88,12 +85,13 @@ public class AspectProxyFactoryTests {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
|
||||
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
|
||||
ITestBean proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
|
||||
ITestBean tb = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
|
||||
assertThat(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
assertTrue(tb.doWithVarargs(MyEnum.A, MyOtherEnum.C));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testWithInstance() throws Exception {
|
||||
MultiplyReturnValue aspect = new MultiplyReturnValue();
|
||||
int multiple = 3;
|
||||
@@ -106,17 +104,16 @@ public class AspectProxyFactoryTests {
|
||||
proxyFactory.addAspect(aspect);
|
||||
|
||||
ITestBean proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy.getAge()).isEqualTo((target.getAge() * multiple));
|
||||
assertEquals(target.getAge() * multiple, proxy.getAge());
|
||||
|
||||
ITestBean serializedProxy = (ITestBean) SerializationTestUtils.serializeAndDeserialize(proxy);
|
||||
assertThat(serializedProxy.getAge()).isEqualTo((target.getAge() * multiple));
|
||||
assertEquals(target.getAge() * multiple, serializedProxy.getAge());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testWithNonSingletonAspectInstance() throws Exception {
|
||||
AspectJProxyFactory pf = new AspectJProxyFactory();
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
pf.addAspect(new PerThisAspect()));
|
||||
pf.addAspect(new PerThisAspect());
|
||||
}
|
||||
|
||||
@Test // SPR-13328
|
||||
@@ -125,7 +122,7 @@ public class AspectProxyFactoryTests {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
|
||||
proxyFactory.addAspect(LoggingAspectOnVarargs.class);
|
||||
ITestBean proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
|
||||
}
|
||||
|
||||
@Test // SPR-13328
|
||||
@@ -134,7 +131,7 @@ public class AspectProxyFactoryTests {
|
||||
AspectJProxyFactory proxyFactory = new AspectJProxyFactory(new TestBean());
|
||||
proxyFactory.addAspect(LoggingAspectOnSetter.class);
|
||||
ITestBean proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C)).isTrue();
|
||||
assertTrue(proxy.doWithVarargs(MyEnum.A, MyOtherEnum.C));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+16
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -31,7 +31,7 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.beans.factory.xml.XmlReaderContext;
|
||||
import org.springframework.tests.beans.CollectingReaderEventListener;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -58,46 +58,49 @@ public class AspectJNamespaceHandlerTests {
|
||||
@Test
|
||||
public void testRegisterAutoProxyCreator() throws Exception {
|
||||
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
|
||||
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
|
||||
|
||||
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
|
||||
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterAspectJAutoProxyCreator() throws Exception {
|
||||
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
|
||||
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
|
||||
|
||||
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect number of definitions registered").isEqualTo(1);
|
||||
assertEquals("Incorrect number of definitions registered", 1, registry.getBeanDefinitionCount());
|
||||
|
||||
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
assertThat(definition.getBeanClassName()).as("Incorrect APC class").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
|
||||
assertEquals("Incorrect APC class",
|
||||
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterAspectJAutoProxyCreatorWithExistingAutoProxyCreator() throws Exception {
|
||||
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);
|
||||
assertEquals(1, registry.getBeanDefinitionCount());
|
||||
|
||||
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect definition count").isEqualTo(1);
|
||||
assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount());
|
||||
|
||||
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
assertThat(definition.getBeanClassName()).as("APC class not switched").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
|
||||
assertEquals("APC class not switched",
|
||||
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRegisterAutoProxyCreatorWhenAspectJAutoProxyCreatorAlreadyExists() throws Exception {
|
||||
AopNamespaceUtils.registerAspectJAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).isEqualTo(1);
|
||||
assertEquals(1, registry.getBeanDefinitionCount());
|
||||
|
||||
AopNamespaceUtils.registerAutoProxyCreatorIfNecessary(this.parserContext, null);
|
||||
assertThat(registry.getBeanDefinitionCount()).as("Incorrect definition count").isEqualTo(1);
|
||||
assertEquals("Incorrect definition count", 1, registry.getBeanDefinitionCount());
|
||||
|
||||
BeanDefinition definition = registry.getBeanDefinition(AopConfigUtils.AUTO_PROXY_CREATOR_BEAN_NAME);
|
||||
assertThat(definition.getBeanClassName()).as("Incorrect APC class").isEqualTo(AspectJAwareAdvisorAutoProxyCreator.class.getName());
|
||||
assertEquals("Incorrect APC class",
|
||||
AspectJAwareAdvisorAutoProxyCreator.class.getName(), definition.getBeanClassName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+19
-19
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -35,7 +35,7 @@ import org.springframework.aop.aspectj.AspectJPointcutAdvisor;
|
||||
import org.springframework.aop.support.DefaultPointcutAdvisor;
|
||||
import org.springframework.lang.Nullable;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Adrian Colyer
|
||||
@@ -69,95 +69,95 @@ public class AspectJPrecedenceComparatorTests {
|
||||
public void testSameAspectNoAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
|
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1);
|
||||
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameAspectAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before advisor1").isEqualTo(1);
|
||||
assertEquals("advisor2 sorted before advisor1", 1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
|
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameAspectOneOfEach() {
|
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 and advisor2 not comparable").isEqualTo(1);
|
||||
assertEquals("advisor1 and advisor2 not comparable", 1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameAdvisorPrecedenceDifferentAspectNoAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
|
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
|
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
|
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
|
||||
assertEquals("nothing to say about order here", 0, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHigherAdvisorPrecedenceNoAfterAdvice() {
|
||||
Advisor advisor1 = createSpringAOPBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER);
|
||||
Advisor advisor2 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
|
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
|
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHigherAdvisorPrecedenceAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
|
||||
assertEquals("advisor1 sorted before advisor2", -1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAfterThrowingAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted after advisor1").isEqualTo(-1);
|
||||
assertEquals("advisor2 sorted after advisor1", -1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerAdvisorPrecedenceNoAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
|
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
|
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLowerAdvisorPrecedenceAfterAdvice() {
|
||||
Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
|
||||
Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
|
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
|
||||
|
||||
advisor1 = createSpringAOPAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER);
|
||||
advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
|
||||
assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
|
||||
assertEquals("advisor1 sorted after advisor2", 1, this.comparator.compare(advisor1, advisor2));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+39
-47
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,8 +32,8 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.beans.CollectingReaderEventListener;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -67,15 +67,14 @@ public class AopNamespaceHandlerEventTests {
|
||||
public void testPointcutEvents() {
|
||||
this.reader.loadBeanDefinitions(POINTCUT_EVENTS_CONTEXT);
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(1);
|
||||
boolean condition = componentDefinitions[0] instanceof CompositeComponentDefinition;
|
||||
assertThat(condition).as("No holder with nested components").isTrue();
|
||||
assertEquals("Incorrect number of events fired", 1, componentDefinitions.length);
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertThat(compositeDef.getName()).isEqualTo("aop:config");
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
PointcutComponentDefinition pcd = null;
|
||||
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
|
||||
if (componentDefinition instanceof PointcutComponentDefinition) {
|
||||
@@ -83,23 +82,22 @@ public class AopNamespaceHandlerEventTests {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(pcd).as("PointcutComponentDefinition not found").isNotNull();
|
||||
assertThat(pcd.getBeanDefinitions().length).as("Incorrect number of BeanDefinitions").isEqualTo(1);
|
||||
assertNotNull("PointcutComponentDefinition not found", pcd);
|
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvisorEventsWithPointcutRef() {
|
||||
this.reader.loadBeanDefinitions(POINTCUT_REF_CONTEXT);
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(2);
|
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||
|
||||
boolean condition1 = componentDefinitions[0] instanceof CompositeComponentDefinition;
|
||||
assertThat(condition1).as("No holder with nested components").isTrue();
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertThat(compositeDef.getName()).isEqualTo("aop:config");
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(3);
|
||||
assertEquals("Incorrect number of inner components", 3, nestedComponentDefs.length);
|
||||
AdvisorComponentDefinition acd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
@@ -108,29 +106,27 @@ public class AopNamespaceHandlerEventTests {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(acd).as("AdvisorComponentDefinition not found").isNotNull();
|
||||
assertThat(acd.getBeanDefinitions().length).isEqualTo(1);
|
||||
assertThat(acd.getBeanReferences().length).isEqualTo(2);
|
||||
assertNotNull("AdvisorComponentDefinition not found", acd);
|
||||
assertEquals(1, acd.getBeanDefinitions().length);
|
||||
assertEquals(2, acd.getBeanReferences().length);
|
||||
|
||||
boolean condition = componentDefinitions[1] instanceof BeanComponentDefinition;
|
||||
assertThat(condition).as("No advice bean found").isTrue();
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
|
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
|
||||
assertThat(adviceDef.getBeanName()).isEqualTo("countingAdvice");
|
||||
assertEquals("countingAdvice", adviceDef.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAdvisorEventsWithDirectPointcut() {
|
||||
this.reader.loadBeanDefinitions(DIRECT_POINTCUT_EVENTS_CONTEXT);
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(2);
|
||||
assertEquals("Incorrect number of events fired", 2, componentDefinitions.length);
|
||||
|
||||
boolean condition1 = componentDefinitions[0] instanceof CompositeComponentDefinition;
|
||||
assertThat(condition1).as("No holder with nested components").isTrue();
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertThat(compositeDef.getName()).isEqualTo("aop:config");
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
AdvisorComponentDefinition acd = null;
|
||||
for (int i = 0; i < nestedComponentDefs.length; i++) {
|
||||
ComponentDefinition componentDefinition = nestedComponentDefs[i];
|
||||
@@ -139,29 +135,27 @@ public class AopNamespaceHandlerEventTests {
|
||||
break;
|
||||
}
|
||||
}
|
||||
assertThat(acd).as("AdvisorComponentDefinition not found").isNotNull();
|
||||
assertThat(acd.getBeanDefinitions().length).isEqualTo(2);
|
||||
assertThat(acd.getBeanReferences().length).isEqualTo(1);
|
||||
assertNotNull("AdvisorComponentDefinition not found", acd);
|
||||
assertEquals(2, acd.getBeanDefinitions().length);
|
||||
assertEquals(1, acd.getBeanReferences().length);
|
||||
|
||||
boolean condition = componentDefinitions[1] instanceof BeanComponentDefinition;
|
||||
assertThat(condition).as("No advice bean found").isTrue();
|
||||
assertTrue("No advice bean found", componentDefinitions[1] instanceof BeanComponentDefinition);
|
||||
BeanComponentDefinition adviceDef = (BeanComponentDefinition) componentDefinitions[1];
|
||||
assertThat(adviceDef.getBeanName()).isEqualTo("countingAdvice");
|
||||
assertEquals("countingAdvice", adviceDef.getBeanName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAspectEvent() {
|
||||
this.reader.loadBeanDefinitions(CONTEXT);
|
||||
ComponentDefinition[] componentDefinitions = this.eventListener.getComponentDefinitions();
|
||||
assertThat(componentDefinitions.length).as("Incorrect number of events fired").isEqualTo(5);
|
||||
assertEquals("Incorrect number of events fired", 5, componentDefinitions.length);
|
||||
|
||||
boolean condition = componentDefinitions[0] instanceof CompositeComponentDefinition;
|
||||
assertThat(condition).as("No holder with nested components").isTrue();
|
||||
assertTrue("No holder with nested components", componentDefinitions[0] instanceof CompositeComponentDefinition);
|
||||
CompositeComponentDefinition compositeDef = (CompositeComponentDefinition) componentDefinitions[0];
|
||||
assertThat(compositeDef.getName()).isEqualTo("aop:config");
|
||||
assertEquals("aop:config", compositeDef.getName());
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs = compositeDef.getNestedComponents();
|
||||
assertThat(nestedComponentDefs.length).as("Incorrect number of inner components").isEqualTo(2);
|
||||
assertEquals("Incorrect number of inner components", 2, nestedComponentDefs.length);
|
||||
AspectComponentDefinition acd = null;
|
||||
for (ComponentDefinition componentDefinition : nestedComponentDefs) {
|
||||
if (componentDefinition instanceof AspectComponentDefinition) {
|
||||
@@ -170,11 +164,11 @@ public class AopNamespaceHandlerEventTests {
|
||||
}
|
||||
}
|
||||
|
||||
assertThat(acd).as("AspectComponentDefinition not found").isNotNull();
|
||||
assertNotNull("AspectComponentDefinition not found", acd);
|
||||
BeanDefinition[] beanDefinitions = acd.getBeanDefinitions();
|
||||
assertThat(beanDefinitions.length).isEqualTo(5);
|
||||
assertEquals(5, beanDefinitions.length);
|
||||
BeanReference[] beanReferences = acd.getBeanReferences();
|
||||
assertThat(beanReferences.length).isEqualTo(6);
|
||||
assertEquals(6, beanReferences.length);
|
||||
|
||||
Set<String> expectedReferences = new HashSet<>();
|
||||
expectedReferences.add("pc");
|
||||
@@ -182,19 +176,17 @@ public class AopNamespaceHandlerEventTests {
|
||||
for (BeanReference beanReference : beanReferences) {
|
||||
expectedReferences.remove(beanReference.getBeanName());
|
||||
}
|
||||
assertThat(expectedReferences.size()).as("Incorrect references found").isEqualTo(0);
|
||||
assertEquals("Incorrect references found", 0, expectedReferences.size());
|
||||
|
||||
for (int i = 1; i < componentDefinitions.length; i++) {
|
||||
boolean condition1 = componentDefinitions[i] instanceof BeanComponentDefinition;
|
||||
assertThat(condition1).isTrue();
|
||||
assertTrue(componentDefinitions[i] instanceof BeanComponentDefinition);
|
||||
}
|
||||
|
||||
ComponentDefinition[] nestedComponentDefs2 = acd.getNestedComponents();
|
||||
assertThat(nestedComponentDefs2.length).as("Inner PointcutComponentDefinition not found").isEqualTo(1);
|
||||
boolean condition1 = nestedComponentDefs2[0] instanceof PointcutComponentDefinition;
|
||||
assertThat(condition1).isTrue();
|
||||
assertEquals("Inner PointcutComponentDefinition not found", 1, nestedComponentDefs2.length);
|
||||
assertTrue(nestedComponentDefs2[0] instanceof PointcutComponentDefinition);
|
||||
PointcutComponentDefinition pcd = (PointcutComponentDefinition) nestedComponentDefs2[0];
|
||||
assertThat(pcd.getBeanDefinitions().length).as("Incorrect number of BeanDefinitions").isEqualTo(1);
|
||||
assertEquals("Incorrect number of BeanDefinitions", 1, pcd.getBeanDefinitions().length);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+21
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,8 +23,8 @@ import org.springframework.beans.factory.parsing.BeanDefinitionParsingException;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -34,20 +34,28 @@ public class AopNamespaceHandlerPointcutErrorTests {
|
||||
|
||||
@Test
|
||||
public void testDuplicatePointcutConfig() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() ->
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(getClass(), "pointcutDuplication.xml")))
|
||||
.satisfies(ex -> ex.contains(BeanDefinitionParsingException.class));
|
||||
try {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(getClass(), "pointcutDuplication.xml"));
|
||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMissingPointcutConfig() {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(() ->
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(getClass(), "pointcutMissing.xml")))
|
||||
.satisfies(ex -> ex.contains(BeanDefinitionParsingException.class));
|
||||
try {
|
||||
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(getClass(), "pointcutMissing.xml"));
|
||||
fail("parsing should have caused a BeanDefinitionStoreException");
|
||||
}
|
||||
catch (BeanDefinitionStoreException ex) {
|
||||
assertTrue(ex.contains(BeanDefinitionParsingException.class));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -21,8 +21,8 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* Tests that the <aop:config/> element can be used as a top level element.
|
||||
@@ -38,7 +38,7 @@ public class TopLevelAopTagTests {
|
||||
new XmlBeanDefinitionReader(beanFactory).loadBeanDefinitions(
|
||||
qualifiedResource(TopLevelAopTagTests.class, "context.xml"));
|
||||
|
||||
assertThat(beanFactory.containsBeanDefinition("testPointcut")).isTrue();
|
||||
assertTrue(beanFactory.containsBeanDefinition("testPointcut"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+25
-27
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,8 +26,7 @@ import org.springframework.aop.SpringProxy;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -39,10 +38,10 @@ public class AopProxyUtilsTests {
|
||||
public void testCompleteProxiedInterfacesWorksWithNull() {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertThat(completedInterfaces.length).isEqualTo(2);
|
||||
assertEquals(2, completedInterfaces.length);
|
||||
List<?> ifaces = Arrays.asList(completedInterfaces);
|
||||
assertThat(ifaces.contains(Advised.class)).isTrue();
|
||||
assertThat(ifaces.contains(SpringProxy.class)).isTrue();
|
||||
assertTrue(ifaces.contains(Advised.class));
|
||||
assertTrue(ifaces.contains(SpringProxy.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -50,7 +49,7 @@ public class AopProxyUtilsTests {
|
||||
AdvisedSupport as = new AdvisedSupport();
|
||||
as.setOpaque(true);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertThat(completedInterfaces.length).isEqualTo(1);
|
||||
assertEquals(1, completedInterfaces.length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,13 +58,13 @@ public class AopProxyUtilsTests {
|
||||
as.addInterface(ITestBean.class);
|
||||
as.addInterface(Comparable.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertThat(completedInterfaces.length).isEqualTo(4);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertThat(l.contains(Advised.class)).isTrue();
|
||||
assertThat(l.contains(ITestBean.class)).isTrue();
|
||||
assertThat(l.contains(Comparable.class)).isTrue();
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -75,13 +74,13 @@ public class AopProxyUtilsTests {
|
||||
as.addInterface(Comparable.class);
|
||||
as.addInterface(Advised.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertThat(completedInterfaces.length).isEqualTo(4);
|
||||
assertEquals(4, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertThat(l.contains(Advised.class)).isTrue();
|
||||
assertThat(l.contains(ITestBean.class)).isTrue();
|
||||
assertThat(l.contains(Comparable.class)).isTrue();
|
||||
assertTrue(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -91,13 +90,13 @@ public class AopProxyUtilsTests {
|
||||
as.addInterface(ITestBean.class);
|
||||
as.addInterface(Comparable.class);
|
||||
Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
|
||||
assertThat(completedInterfaces.length).isEqualTo(3);
|
||||
assertEquals(3, completedInterfaces.length);
|
||||
|
||||
// Can't assume ordering for others, so use a list
|
||||
List<?> l = Arrays.asList(completedInterfaces);
|
||||
assertThat(l.contains(Advised.class)).isFalse();
|
||||
assertThat(l.contains(ITestBean.class)).isTrue();
|
||||
assertThat(l.contains(Comparable.class)).isTrue();
|
||||
assertFalse(l.contains(Advised.class));
|
||||
assertTrue(l.contains(ITestBean.class));
|
||||
assertTrue(l.contains(Comparable.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -107,8 +106,8 @@ public class AopProxyUtilsTests {
|
||||
pf.addInterface(ITestBean.class);
|
||||
Object proxy = pf.getProxy();
|
||||
Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
assertThat(userInterfaces.length).isEqualTo(1);
|
||||
assertThat(userInterfaces[0]).isEqualTo(ITestBean.class);
|
||||
assertEquals(1, userInterfaces.length);
|
||||
assertEquals(ITestBean.class, userInterfaces[0]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -119,17 +118,16 @@ public class AopProxyUtilsTests {
|
||||
pf.addInterface(Comparable.class);
|
||||
Object proxy = pf.getProxy();
|
||||
Class<?>[] userInterfaces = AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
assertThat(userInterfaces.length).isEqualTo(2);
|
||||
assertThat(userInterfaces[0]).isEqualTo(ITestBean.class);
|
||||
assertThat(userInterfaces[1]).isEqualTo(Comparable.class);
|
||||
assertEquals(2, userInterfaces.length);
|
||||
assertEquals(ITestBean.class, userInterfaces[0]);
|
||||
assertEquals(Comparable.class, userInterfaces[1]);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testProxiedUserInterfacesWithNoInterface() {
|
||||
Object proxy = Proxy.newProxyInstance(getClass().getClassLoader(), new Class[0],
|
||||
(proxy1, method, args) -> null);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
AopProxyUtils.proxiedUserInterfaces(proxy));
|
||||
AopProxyUtils.proxiedUserInterfaces(proxy);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -26,7 +26,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -51,7 +51,7 @@ public class MethodInvocationTests {
|
||||
m, null, null, is // list
|
||||
);
|
||||
Object rv = invocation.proceed();
|
||||
assertThat(rv == returnValue).as("correct response").isTrue();
|
||||
assertTrue("correct response", rv == returnValue);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2012 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.
|
||||
@@ -18,11 +18,13 @@ package org.springframework.aop.framework;
|
||||
|
||||
import org.aopalliance.intercept.MethodInterceptor;
|
||||
import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.aop.AopInvocationException;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test for SPR-4675. A null value returned from around advice is very hard to debug if
|
||||
@@ -32,6 +34,9 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
*/
|
||||
public class NullPrimitiveTests {
|
||||
|
||||
@Rule
|
||||
public ExpectedException thrown = ExpectedException.none();
|
||||
|
||||
static interface Foo {
|
||||
int getValue();
|
||||
}
|
||||
@@ -57,9 +62,9 @@ public class NullPrimitiveTests {
|
||||
|
||||
Foo foo = (Foo) factory.getProxy();
|
||||
|
||||
assertThatExceptionOfType(AopInvocationException.class).isThrownBy(() ->
|
||||
foo.getValue())
|
||||
.withMessageContaining("Foo.getValue()");
|
||||
thrown.expect(AopInvocationException.class);
|
||||
thrown.expectMessage("Foo.getValue()");
|
||||
assertEquals(0, foo.getValue());
|
||||
}
|
||||
|
||||
public static class Bar {
|
||||
@@ -82,9 +87,9 @@ public class NullPrimitiveTests {
|
||||
|
||||
Bar bar = (Bar) factory.getProxy();
|
||||
|
||||
assertThatExceptionOfType(AopInvocationException.class).isThrownBy(() ->
|
||||
bar.getValue())
|
||||
.withMessageContaining("Bar.getValue()");
|
||||
thrown.expect(AopInvocationException.class);
|
||||
thrown.expectMessage("Bar.getValue()");
|
||||
assertEquals(0, bar.getValue());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-6
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -47,8 +47,8 @@ public class PrototypeTargetTests {
|
||||
tb.doSomething();
|
||||
}
|
||||
TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
|
||||
assertThat(TestBeanImpl.constructionCount).isEqualTo(10);
|
||||
assertThat(interceptor.invocationCount).isEqualTo(10);
|
||||
assertEquals(10, TestBeanImpl.constructionCount);
|
||||
assertEquals(10, interceptor.invocationCount);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,8 +61,8 @@ public class PrototypeTargetTests {
|
||||
tb.doSomething();
|
||||
}
|
||||
TestInterceptor interceptor = (TestInterceptor) bf.getBean("testInterceptor");
|
||||
assertThat(TestBeanImpl.constructionCount).isEqualTo(1);
|
||||
assertThat(interceptor.invocationCount).isEqualTo(10);
|
||||
assertEquals(1, TestBeanImpl.constructionCount);
|
||||
assertEquals(10, interceptor.invocationCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -42,8 +42,8 @@ import org.springframework.tests.sample.beans.IOther;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.hamcrest.CoreMatchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Also tests AdvisedSupport and ProxyCreatorSupport superclasses.
|
||||
@@ -65,10 +65,10 @@ public class ProxyFactoryTests {
|
||||
// Can use advised and ProxyFactory interchangeably
|
||||
advised.addAdvice(nop);
|
||||
pf.addAdvisor(advisor);
|
||||
assertThat(pf.indexOf(new NopInterceptor())).isEqualTo(-1);
|
||||
assertThat(pf.indexOf(nop)).isEqualTo(0);
|
||||
assertThat(pf.indexOf(advisor)).isEqualTo(1);
|
||||
assertThat(advised.indexOf(new DefaultPointcutAdvisor(null))).isEqualTo(-1);
|
||||
assertEquals(-1, pf.indexOf(new NopInterceptor()));
|
||||
assertEquals(0, pf.indexOf(nop));
|
||||
assertEquals(1, pf.indexOf(advisor));
|
||||
assertEquals(-1, advised.indexOf(new DefaultPointcutAdvisor(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,13 +82,13 @@ public class ProxyFactoryTests {
|
||||
pf.addAdvisor(advisor);
|
||||
ITestBean proxied = (ITestBean) pf.getProxy();
|
||||
proxied.setAge(5);
|
||||
assertThat(cba.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertThat(pf.removeAdvisor(advisor)).isTrue();
|
||||
assertThat(proxied.getAge()).isEqualTo(5);
|
||||
assertThat(cba.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertThat(pf.removeAdvisor(new DefaultPointcutAdvisor(null))).isFalse();
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(1, nop.getCount());
|
||||
assertTrue(pf.removeAdvisor(advisor));
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(2, nop.getCount());
|
||||
assertFalse(pf.removeAdvisor(new DefaultPointcutAdvisor(null)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -104,21 +104,21 @@ public class ProxyFactoryTests {
|
||||
pf.addAdvice(nop2);
|
||||
ITestBean proxied = (ITestBean) pf.getProxy();
|
||||
proxied.setAge(5);
|
||||
assertThat(cba.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertThat(nop2.getCount()).isEqualTo(1);
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(1, nop.getCount());
|
||||
assertEquals(1, nop2.getCount());
|
||||
// Removes counting before advisor
|
||||
pf.removeAdvisor(1);
|
||||
assertThat(proxied.getAge()).isEqualTo(5);
|
||||
assertThat(cba.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertThat(nop2.getCount()).isEqualTo(2);
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(2, nop.getCount());
|
||||
assertEquals(2, nop2.getCount());
|
||||
// Removes Nop1
|
||||
pf.removeAdvisor(0);
|
||||
assertThat(proxied.getAge()).isEqualTo(5);
|
||||
assertThat(cba.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertThat(nop2.getCount()).isEqualTo(3);
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(1, cba.getCalls());
|
||||
assertEquals(2, nop.getCount());
|
||||
assertEquals(3, nop2.getCount());
|
||||
|
||||
// Check out of bounds
|
||||
try {
|
||||
@@ -135,8 +135,8 @@ public class ProxyFactoryTests {
|
||||
// Ok
|
||||
}
|
||||
|
||||
assertThat(proxied.getAge()).isEqualTo(5);
|
||||
assertThat(nop2.getCount()).isEqualTo(4);
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(4, nop2.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -155,17 +155,17 @@ public class ProxyFactoryTests {
|
||||
// Replace etc methods on advised should be same as on ProxyFactory
|
||||
Advised advised = (Advised) proxied;
|
||||
proxied.setAge(5);
|
||||
assertThat(cba1.getCalls()).isEqualTo(1);
|
||||
assertThat(cba2.getCalls()).isEqualTo(0);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertThat(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2)).isFalse();
|
||||
assertThat(advised.replaceAdvisor(advisor1, advisor2)).isTrue();
|
||||
assertThat(pf.getAdvisors()[0]).isEqualTo(advisor2);
|
||||
assertThat(proxied.getAge()).isEqualTo(5);
|
||||
assertThat(cba1.getCalls()).isEqualTo(1);
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertThat(cba2.getCalls()).isEqualTo(1);
|
||||
assertThat(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1)).isFalse();
|
||||
assertEquals(1, cba1.getCalls());
|
||||
assertEquals(0, cba2.getCalls());
|
||||
assertEquals(1, nop.getCount());
|
||||
assertFalse(advised.replaceAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()), advisor2));
|
||||
assertTrue(advised.replaceAdvisor(advisor1, advisor2));
|
||||
assertEquals(advisor2, pf.getAdvisors()[0]);
|
||||
assertEquals(5, proxied.getAge());
|
||||
assertEquals(1, cba1.getCalls());
|
||||
assertEquals(2, nop.getCount());
|
||||
assertEquals(1, cba2.getCalls());
|
||||
assertFalse(pf.replaceAdvisor(new DefaultPointcutAdvisor(null), advisor1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -181,7 +181,7 @@ public class ProxyFactoryTests {
|
||||
// This call should be ignored without error
|
||||
pf.addInterface(TimeStamped.class);
|
||||
// All cool
|
||||
assertThat(pf.getProxy()).isInstanceOf(TimeStamped.class);
|
||||
assertThat(pf.getProxy(), instanceOf(TimeStamped.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,11 +196,12 @@ public class ProxyFactoryTests {
|
||||
TestBeanSubclass raw = new TestBeanSubclass();
|
||||
ProxyFactory factory = new ProxyFactory(raw);
|
||||
//System.out.println("Proxied interfaces are " + StringUtils.arrayToDelimitedString(factory.getProxiedInterfaces(), ","));
|
||||
assertThat(factory.getProxiedInterfaces().length).as("Found correct number of interfaces").isEqualTo(5);
|
||||
assertEquals("Found correct number of interfaces", 5, factory.getProxiedInterfaces().length);
|
||||
ITestBean tb = (ITestBean) factory.getProxy();
|
||||
assertThat(tb).as("Picked up secondary interface").isInstanceOf(IOther.class);
|
||||
assertThat("Picked up secondary interface", tb, instanceOf(IOther.class));
|
||||
|
||||
raw.setAge(25);
|
||||
assertThat(tb.getAge() == raw.getAge()).isTrue();
|
||||
assertTrue(tb.getAge() == raw.getAge());
|
||||
|
||||
long t = 555555L;
|
||||
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor(t);
|
||||
@@ -210,10 +211,10 @@ public class ProxyFactoryTests {
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
|
||||
|
||||
Class<?>[] newProxiedInterfaces = factory.getProxiedInterfaces();
|
||||
assertThat(newProxiedInterfaces.length).as("Advisor proxies one more interface after introduction").isEqualTo(oldProxiedInterfaces.length + 1);
|
||||
assertEquals("Advisor proxies one more interface after introduction", oldProxiedInterfaces.length + 1, newProxiedInterfaces.length);
|
||||
|
||||
TimeStamped ts = (TimeStamped) factory.getProxy();
|
||||
assertThat(ts.getTimeStamp() == t).isTrue();
|
||||
assertTrue(ts.getTimeStamp() == t);
|
||||
// Shouldn't fail;
|
||||
((IOther) ts).absquatulate();
|
||||
}
|
||||
@@ -231,15 +232,15 @@ public class ProxyFactoryTests {
|
||||
NopInterceptor diUnused = new NopInterceptor();
|
||||
ProxyFactory factory = new ProxyFactory(new TestBean());
|
||||
factory.addAdvice(0, di);
|
||||
assertThat(factory.getProxy()).isInstanceOf(ITestBean.class);
|
||||
assertThat(factory.adviceIncluded(di)).isTrue();
|
||||
assertThat(!factory.adviceIncluded(diUnused)).isTrue();
|
||||
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 1).isTrue();
|
||||
assertThat(factory.countAdvicesOfType(MyInterceptor.class) == 0).isTrue();
|
||||
assertThat(factory.getProxy(), instanceOf(ITestBean.class));
|
||||
assertTrue(factory.adviceIncluded(di));
|
||||
assertTrue(!factory.adviceIncluded(diUnused));
|
||||
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 1);
|
||||
assertTrue(factory.countAdvicesOfType(MyInterceptor.class) == 0);
|
||||
|
||||
factory.addAdvice(0, diUnused);
|
||||
assertThat(factory.adviceIncluded(diUnused)).isTrue();
|
||||
assertThat(factory.countAdvicesOfType(NopInterceptor.class) == 2).isTrue();
|
||||
assertTrue(factory.adviceIncluded(diUnused));
|
||||
assertTrue(factory.countAdvicesOfType(NopInterceptor.class) == 2);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -249,7 +250,8 @@ public class ProxyFactoryTests {
|
||||
public void testCanAddAndRemoveAspectInterfacesOnSingleton() {
|
||||
ProxyFactory config = new ProxyFactory(new TestBean());
|
||||
|
||||
assertThat(config.getProxy() instanceof TimeStamped).as("Shouldn't implement TimeStamped before manipulation").isFalse();
|
||||
assertFalse("Shouldn't implement TimeStamped before manipulation",
|
||||
config.getProxy() instanceof TimeStamped);
|
||||
|
||||
long time = 666L;
|
||||
TimestampIntroductionInterceptor ti = new TimestampIntroductionInterceptor();
|
||||
@@ -259,36 +261,41 @@ public class ProxyFactoryTests {
|
||||
int oldCount = config.getAdvisors().length;
|
||||
config.addAdvisor(0, new DefaultIntroductionAdvisor(ti, TimeStamped.class));
|
||||
|
||||
assertThat(config.getAdvisors().length == oldCount + 1).isTrue();
|
||||
assertTrue(config.getAdvisors().length == oldCount + 1);
|
||||
|
||||
TimeStamped ts = (TimeStamped) config.getProxy();
|
||||
assertThat(ts.getTimeStamp() == time).isTrue();
|
||||
assertTrue(ts.getTimeStamp() == time);
|
||||
|
||||
// Can remove
|
||||
config.removeAdvice(ti);
|
||||
|
||||
assertThat(config.getAdvisors().length == oldCount).isTrue();
|
||||
assertTrue(config.getAdvisors().length == oldCount);
|
||||
|
||||
assertThatExceptionOfType(RuntimeException.class)
|
||||
.as("Existing object won't implement this interface any more")
|
||||
.isThrownBy(ts::getTimeStamp); // Existing reference will fail
|
||||
try {
|
||||
// Existing reference will fail
|
||||
ts.getTimeStamp();
|
||||
fail("Existing object won't implement this interface any more");
|
||||
}
|
||||
catch (RuntimeException ex) {
|
||||
}
|
||||
|
||||
assertThat(config.getProxy() instanceof TimeStamped).as("Should no longer implement TimeStamped").isFalse();
|
||||
assertFalse("Should no longer implement TimeStamped",
|
||||
config.getProxy() instanceof TimeStamped);
|
||||
|
||||
// Now check non-effect of removing interceptor that isn't there
|
||||
config.removeAdvice(new DebugInterceptor());
|
||||
|
||||
assertThat(config.getAdvisors().length == oldCount).isTrue();
|
||||
assertTrue(config.getAdvisors().length == oldCount);
|
||||
|
||||
ITestBean it = (ITestBean) ts;
|
||||
DebugInterceptor debugInterceptor = new DebugInterceptor();
|
||||
config.addAdvice(0, debugInterceptor);
|
||||
it.getSpouse();
|
||||
assertThat(debugInterceptor.getCount()).isEqualTo(1);
|
||||
assertEquals(1, debugInterceptor.getCount());
|
||||
config.removeAdvice(debugInterceptor);
|
||||
it.getSpouse();
|
||||
// not invoked again
|
||||
assertThat(debugInterceptor.getCount() == 1).isTrue();
|
||||
assertTrue(debugInterceptor.getCount() == 1);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -296,15 +303,15 @@ public class ProxyFactoryTests {
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.setTargetClass(ITestBean.class);
|
||||
Object proxy = pf.getProxy();
|
||||
assertThat(AopUtils.isJdkDynamicProxy(proxy)).as("Proxy is a JDK proxy").isTrue();
|
||||
assertThat(proxy instanceof ITestBean).isTrue();
|
||||
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(ITestBean.class);
|
||||
assertTrue("Proxy is a JDK proxy", AopUtils.isJdkDynamicProxy(proxy));
|
||||
assertTrue(proxy instanceof ITestBean);
|
||||
assertEquals(ITestBean.class, AopProxyUtils.ultimateTargetClass(proxy));
|
||||
|
||||
ProxyFactory pf2 = new ProxyFactory(proxy);
|
||||
Object proxy2 = pf2.getProxy();
|
||||
assertThat(AopUtils.isJdkDynamicProxy(proxy2)).as("Proxy is a JDK proxy").isTrue();
|
||||
assertThat(proxy2 instanceof ITestBean).isTrue();
|
||||
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(ITestBean.class);
|
||||
assertTrue("Proxy is a JDK proxy", AopUtils.isJdkDynamicProxy(proxy2));
|
||||
assertTrue(proxy2 instanceof ITestBean);
|
||||
assertEquals(ITestBean.class, AopProxyUtils.ultimateTargetClass(proxy2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,16 +319,16 @@ public class ProxyFactoryTests {
|
||||
ProxyFactory pf = new ProxyFactory();
|
||||
pf.setTargetClass(TestBean.class);
|
||||
Object proxy = pf.getProxy();
|
||||
assertThat(AopUtils.isCglibProxy(proxy)).as("Proxy is a CGLIB proxy").isTrue();
|
||||
assertThat(proxy instanceof TestBean).isTrue();
|
||||
assertThat(AopProxyUtils.ultimateTargetClass(proxy)).isEqualTo(TestBean.class);
|
||||
assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy));
|
||||
assertTrue(proxy instanceof TestBean);
|
||||
assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy));
|
||||
|
||||
ProxyFactory pf2 = new ProxyFactory(proxy);
|
||||
pf2.setProxyTargetClass(true);
|
||||
Object proxy2 = pf2.getProxy();
|
||||
assertThat(AopUtils.isCglibProxy(proxy2)).as("Proxy is a CGLIB proxy").isTrue();
|
||||
assertThat(proxy2 instanceof TestBean).isTrue();
|
||||
assertThat(AopProxyUtils.ultimateTargetClass(proxy2)).isEqualTo(TestBean.class);
|
||||
assertTrue("Proxy is a CGLIB proxy", AopUtils.isCglibProxy(proxy2));
|
||||
assertTrue(proxy2 instanceof TestBean);
|
||||
assertEquals(TestBean.class, AopProxyUtils.ultimateTargetClass(proxy2));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -330,8 +337,8 @@ public class ProxyFactoryTests {
|
||||
JFrame frame = new JFrame();
|
||||
ProxyFactory proxyFactory = new ProxyFactory(frame);
|
||||
Object proxy = proxyFactory.getProxy();
|
||||
assertThat(proxy instanceof RootPaneContainer).isTrue();
|
||||
assertThat(proxy instanceof Accessible).isTrue();
|
||||
assertTrue(proxy instanceof RootPaneContainer);
|
||||
assertTrue(proxy instanceof Accessible);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -342,8 +349,8 @@ public class ProxyFactoryTests {
|
||||
list.add(proxy1);
|
||||
list.add(proxy2);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0)).isSameAs(proxy2);
|
||||
assertThat(list.get(1)).isSameAs(proxy1);
|
||||
assertSame(proxy2, list.get(0));
|
||||
assertSame(proxy1, list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -358,18 +365,18 @@ public class ProxyFactoryTests {
|
||||
list.add(proxy1);
|
||||
list.add(proxy2);
|
||||
AnnotationAwareOrderComparator.sort(list);
|
||||
assertThat(list.get(0)).isSameAs(proxy2);
|
||||
assertThat(list.get(1)).isSameAs(proxy1);
|
||||
assertSame(proxy2, list.get(0));
|
||||
assertSame(proxy1, list.get(1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testInterceptorWithoutJoinpoint() {
|
||||
final TestBean target = new TestBean("tb");
|
||||
ITestBean proxy = ProxyFactory.getProxy(ITestBean.class, (MethodInterceptor) invocation -> {
|
||||
assertThat(invocation.getThis()).isNull();
|
||||
assertNull(invocation.getThis());
|
||||
return invocation.getMethod().invoke(target, invocation.getArguments());
|
||||
});
|
||||
assertThat(proxy.getName()).isEqualTo("tb");
|
||||
assertEquals("tb", proxy.getName());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+43
-31
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -28,11 +28,8 @@ import org.junit.Test;
|
||||
import org.springframework.aop.ThrowsAdvice;
|
||||
import org.springframework.tests.aop.advice.MethodCounter;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -40,11 +37,10 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class ThrowsAdviceInterceptorTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNoHandlerMethods() {
|
||||
// should require one handler method at least
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new ThrowsAdviceInterceptor(new Object()));
|
||||
new ThrowsAdviceInterceptor(new Object());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -54,22 +50,26 @@ public class ThrowsAdviceInterceptorTests {
|
||||
Object ret = new Object();
|
||||
MethodInvocation mi = mock(MethodInvocation.class);
|
||||
given(mi.proceed()).willReturn(ret);
|
||||
assertThat(ti.invoke(mi)).isEqualTo(ret);
|
||||
assertThat(th.getCalls()).isEqualTo(0);
|
||||
assertEquals(ret, ti.invoke(mi));
|
||||
assertEquals(0, th.getCalls());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNoHandlerMethodForThrowable() throws Throwable {
|
||||
MyThrowsHandler th = new MyThrowsHandler();
|
||||
ThrowsAdviceInterceptor ti = new ThrowsAdviceInterceptor(th);
|
||||
assertThat(ti.getHandlerMethodCount()).isEqualTo(2);
|
||||
assertEquals(2, ti.getHandlerMethodCount());
|
||||
Exception ex = new Exception();
|
||||
MethodInvocation mi = mock(MethodInvocation.class);
|
||||
given(mi.proceed()).willThrow(ex);
|
||||
assertThatExceptionOfType(Exception.class).isThrownBy(() ->
|
||||
ti.invoke(mi))
|
||||
.isSameAs(ex);
|
||||
assertThat(th.getCalls()).isEqualTo(0);
|
||||
try {
|
||||
ti.invoke(mi);
|
||||
fail();
|
||||
}
|
||||
catch (Exception caught) {
|
||||
assertEquals(ex, caught);
|
||||
}
|
||||
assertEquals(0, th.getCalls());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -81,11 +81,15 @@ public class ThrowsAdviceInterceptorTests {
|
||||
given(mi.getMethod()).willReturn(Object.class.getMethod("hashCode"));
|
||||
given(mi.getThis()).willReturn(new Object());
|
||||
given(mi.proceed()).willThrow(ex);
|
||||
assertThatExceptionOfType(FileNotFoundException.class).isThrownBy(() ->
|
||||
ti.invoke(mi))
|
||||
.isSameAs(ex);
|
||||
assertThat(th.getCalls()).isEqualTo(1);
|
||||
assertThat(th.getCalls("ioException")).isEqualTo(1);
|
||||
try {
|
||||
ti.invoke(mi);
|
||||
fail();
|
||||
}
|
||||
catch (Exception caught) {
|
||||
assertEquals(ex, caught);
|
||||
}
|
||||
assertEquals(1, th.getCalls());
|
||||
assertEquals(1, th.getCalls("ioException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -96,11 +100,15 @@ public class ThrowsAdviceInterceptorTests {
|
||||
ConnectException ex = new ConnectException("");
|
||||
MethodInvocation mi = mock(MethodInvocation.class);
|
||||
given(mi.proceed()).willThrow(ex);
|
||||
assertThatExceptionOfType(ConnectException.class).isThrownBy(() ->
|
||||
ti.invoke(mi))
|
||||
.isSameAs(ex);
|
||||
assertThat(th.getCalls()).isEqualTo(1);
|
||||
assertThat(th.getCalls("remoteException")).isEqualTo(1);
|
||||
try {
|
||||
ti.invoke(mi);
|
||||
fail();
|
||||
}
|
||||
catch (Exception caught) {
|
||||
assertEquals(ex, caught);
|
||||
}
|
||||
assertEquals(1, th.getCalls());
|
||||
assertEquals(1, th.getCalls("remoteException"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -121,11 +129,15 @@ public class ThrowsAdviceInterceptorTests {
|
||||
ConnectException ex = new ConnectException("");
|
||||
MethodInvocation mi = mock(MethodInvocation.class);
|
||||
given(mi.proceed()).willThrow(ex);
|
||||
assertThatExceptionOfType(Throwable.class).isThrownBy(() ->
|
||||
ti.invoke(mi))
|
||||
.isSameAs(t);
|
||||
assertThat(th.getCalls()).isEqualTo(1);
|
||||
assertThat(th.getCalls("remoteException")).isEqualTo(1);
|
||||
try {
|
||||
ti.invoke(mi);
|
||||
fail();
|
||||
}
|
||||
catch (Throwable caught) {
|
||||
assertEquals(t, caught);
|
||||
}
|
||||
assertEquals(1, th.getCalls());
|
||||
assertEquals(1, th.getCalls("remoteException"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -58,7 +58,7 @@ public class ConcurrencyThrottleInterceptorTests {
|
||||
Advised advised = (Advised) serializedProxy;
|
||||
ConcurrencyThrottleInterceptor serializedCti =
|
||||
(ConcurrencyThrottleInterceptor) advised.getAdvisors()[0].getAdvice();
|
||||
assertThat(serializedCti.getConcurrencyLimit()).isEqualTo(cti.getConcurrencyLimit());
|
||||
assertEquals(cti.getConcurrencyLimit(), serializedCti.getConcurrencyLimit());
|
||||
serializedProxy.getAge();
|
||||
}
|
||||
|
||||
|
||||
+25
-34
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,13 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -36,60 +31,52 @@ import static org.mockito.Mockito.verify;
|
||||
*/
|
||||
public class CustomizableTraceInterceptorTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEmptyEnterMessage() {
|
||||
// Must not be able to set empty enter message
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setEnterMessage(""));
|
||||
new CustomizableTraceInterceptor().setEnterMessage("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEnterMessageWithReturnValuePlaceholder() {
|
||||
// Must not be able to set enter message with return value placeholder
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE));
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEnterMessageWithExceptionPlaceholder() {
|
||||
// Must not be able to set enter message with exception placeholder
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION));
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEnterMessageWithInvocationTimePlaceholder() {
|
||||
// Must not be able to set enter message with invocation time placeholder
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_INVOCATION_TIME));
|
||||
new CustomizableTraceInterceptor().setEnterMessage(CustomizableTraceInterceptor.PLACEHOLDER_INVOCATION_TIME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEmptyExitMessage() {
|
||||
// Must not be able to set empty exit message
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setExitMessage(""));
|
||||
new CustomizableTraceInterceptor().setExitMessage("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetExitMessageWithExceptionPlaceholder() {
|
||||
// Must not be able to set exit message with exception placeholder
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setExitMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION));
|
||||
new CustomizableTraceInterceptor().setExitMessage(CustomizableTraceInterceptor.PLACEHOLDER_EXCEPTION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetEmptyExceptionMessage() {
|
||||
// Must not be able to set empty exception message
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setExceptionMessage(""));
|
||||
new CustomizableTraceInterceptor().setExceptionMessage("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testSetExceptionMethodWithReturnValuePlaceholder() {
|
||||
// Must not be able to set exception message with return value placeholder
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new CustomizableTraceInterceptor().setExceptionMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE));
|
||||
new CustomizableTraceInterceptor().setExceptionMessage(CustomizableTraceInterceptor.PLACEHOLDER_RETURN_VALUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -122,8 +109,12 @@ public class CustomizableTraceInterceptorTests {
|
||||
given(log.isTraceEnabled()).willReturn(true);
|
||||
|
||||
CustomizableTraceInterceptor interceptor = new StubCustomizableTraceInterceptor(log);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
interceptor.invoke(methodInvocation));
|
||||
try {
|
||||
interceptor.invoke(methodInvocation);
|
||||
fail("Must have propagated the IllegalArgumentException.");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
|
||||
verify(log).trace(anyString());
|
||||
verify(log).trace(anyString(), eq(exception));
|
||||
|
||||
+10
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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,14 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link DebugInterceptor} class.
|
||||
@@ -64,8 +58,12 @@ public class DebugInterceptorTests {
|
||||
given(log.isTraceEnabled()).willReturn(true);
|
||||
|
||||
DebugInterceptor interceptor = new StubDebugInterceptor(log);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
interceptor.invoke(methodInvocation));
|
||||
try {
|
||||
interceptor.invoke(methodInvocation);
|
||||
fail("Must have propagated the IllegalArgumentException.");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
checkCallCountTotal(interceptor);
|
||||
|
||||
verify(log).trace(anyString());
|
||||
@@ -73,7 +71,7 @@ public class DebugInterceptorTests {
|
||||
}
|
||||
|
||||
private void checkCallCountTotal(DebugInterceptor interceptor) {
|
||||
assertThat(interceptor.getCount()).as("Intercepted call count not being incremented correctly").isEqualTo(1);
|
||||
assertEquals("Intercepted call count not being incremented correctly", 1, interceptor.getCount());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+6
-8
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,7 +23,7 @@ import org.springframework.beans.factory.NamedBean;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -40,7 +40,7 @@ public class ExposeBeanNameAdvisorsTests {
|
||||
|
||||
@Override
|
||||
public int getAge() {
|
||||
assertThat(ExposeBeanNameAdvisors.getBeanName()).isEqualTo(beanName);
|
||||
assertEquals(beanName, ExposeBeanNameAdvisors.getBeanName());
|
||||
return super.getAge();
|
||||
}
|
||||
}
|
||||
@@ -54,8 +54,7 @@ public class ExposeBeanNameAdvisorsTests {
|
||||
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorWithoutIntroduction(beanName));
|
||||
ITestBean proxy = (ITestBean) pf.getProxy();
|
||||
|
||||
boolean condition = proxy instanceof NamedBean;
|
||||
assertThat(condition).as("No introduction").isFalse();
|
||||
assertFalse("No introduction", proxy instanceof NamedBean);
|
||||
// Requires binding
|
||||
proxy.getAge();
|
||||
}
|
||||
@@ -69,13 +68,12 @@ public class ExposeBeanNameAdvisorsTests {
|
||||
pf.addAdvisor(ExposeBeanNameAdvisors.createAdvisorIntroducingNamedBean(beanName));
|
||||
ITestBean proxy = (ITestBean) pf.getProxy();
|
||||
|
||||
boolean condition = proxy instanceof NamedBean;
|
||||
assertThat(condition).as("Introduction was made").isTrue();
|
||||
assertTrue("Introduction was made", proxy instanceof NamedBean);
|
||||
// Requires binding
|
||||
proxy.getAge();
|
||||
|
||||
NamedBean nb = (NamedBean) proxy;
|
||||
assertThat(nb.getBeanName()).as("Name returned correctly").isEqualTo(beanName);
|
||||
assertEquals("Name returned correctly", beanName, nb.getBeanName());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+6
-5
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* Non-XML tests are in AbstractAopProxyTests
|
||||
@@ -44,7 +44,7 @@ public class ExposeInvocationInterceptorTests {
|
||||
String name = "tony";
|
||||
tb.setName(name);
|
||||
// Fires context checks
|
||||
assertThat(tb.getName()).isEqualTo(name);
|
||||
assertEquals(name, tb.getName());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -74,7 +74,8 @@ class InvocationCheckExposedInvocationTestBean extends ExposedInvocationTestBean
|
||||
|
||||
@Override
|
||||
protected void assertions(MethodInvocation invocation) {
|
||||
assertThat(invocation.getThis() == this).isTrue();
|
||||
assertThat(ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass())).as("Invocation should be on ITestBean: " + invocation.getMethod()).isTrue();
|
||||
assertTrue(invocation.getThis() == this);
|
||||
assertTrue("Invocation should be on ITestBean: " + invocation.getMethod(),
|
||||
ITestBean.class.isAssignableFrom(invocation.getMethod().getDeclaringClass()));
|
||||
}
|
||||
}
|
||||
|
||||
+20
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,10 +23,8 @@ import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Steve Souza
|
||||
@@ -58,8 +56,9 @@ public class JamonPerformanceMonitorInterceptorTests {
|
||||
|
||||
interceptor.invokeUnderTrace(mi, log);
|
||||
|
||||
assertThat(MonitorFactory.getNumRows() > 0).as("jamon must track the method being invoked").isTrue();
|
||||
assertThat(MonitorFactory.getReport().contains("toString")).as("The jamon report must contain the toString method that was invoked").isTrue();
|
||||
assertTrue("jamon must track the method being invoked", MonitorFactory.getNumRows() > 0);
|
||||
assertTrue("The jamon report must contain the toString method that was invoked",
|
||||
MonitorFactory.getReport().contains("toString"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,13 +66,21 @@ public class JamonPerformanceMonitorInterceptorTests {
|
||||
given(mi.getMethod()).willReturn(String.class.getMethod("toString"));
|
||||
given(mi.proceed()).willThrow(new IllegalArgumentException());
|
||||
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
interceptor.invokeUnderTrace(mi, log));
|
||||
try {
|
||||
interceptor.invokeUnderTrace(mi, log);
|
||||
fail("Must have propagated the IllegalArgumentException");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
|
||||
assertThat(MonitorFactory.getNumRows()).as("Monitors must exist for the method invocation and 2 exceptions").isEqualTo(3);
|
||||
assertThat(MonitorFactory.getReport().contains("toString")).as("The jamon report must contain the toString method that was invoked").isTrue();
|
||||
assertThat(MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL)).as("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL).isTrue();
|
||||
assertThat(MonitorFactory.getReport().contains("IllegalArgumentException")).as("The jamon report must contain the specific exception: IllegalArgumentException'").isTrue();
|
||||
assertEquals("Monitors must exist for the method invocation and 2 exceptions",
|
||||
3, MonitorFactory.getNumRows());
|
||||
assertTrue("The jamon report must contain the toString method that was invoked",
|
||||
MonitorFactory.getReport().contains("toString"));
|
||||
assertTrue("The jamon report must contain the generic exception: " + MonitorFactory.EXCEPTIONS_LABEL,
|
||||
MonitorFactory.getReport().contains(MonitorFactory.EXCEPTIONS_LABEL));
|
||||
assertTrue("The jamon report must contain the specific exception: IllegalArgumentException'",
|
||||
MonitorFactory.getReport().contains("IllegalArgumentException"));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+13
-13
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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,12 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -38,14 +34,14 @@ public class PerformanceMonitorInterceptorTests {
|
||||
public void testSuffixAndPrefixAssignment() {
|
||||
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor();
|
||||
|
||||
assertThat(interceptor.getPrefix()).isNotNull();
|
||||
assertThat(interceptor.getSuffix()).isNotNull();
|
||||
assertNotNull(interceptor.getPrefix());
|
||||
assertNotNull(interceptor.getSuffix());
|
||||
|
||||
interceptor.setPrefix(null);
|
||||
interceptor.setSuffix(null);
|
||||
|
||||
assertThat(interceptor.getPrefix()).isNotNull();
|
||||
assertThat(interceptor.getSuffix()).isNotNull();
|
||||
assertNotNull(interceptor.getPrefix());
|
||||
assertNotNull(interceptor.getSuffix());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,8 +66,12 @@ public class PerformanceMonitorInterceptorTests {
|
||||
Log log = mock(Log.class);
|
||||
|
||||
PerformanceMonitorInterceptor interceptor = new PerformanceMonitorInterceptor(true);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
interceptor.invokeUnderTrace(mi, log));
|
||||
try {
|
||||
interceptor.invokeUnderTrace(mi, log);
|
||||
fail("Must have propagated the IllegalArgumentException.");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
|
||||
verify(log).trace(anyString());
|
||||
}
|
||||
|
||||
+10
-10
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,13 +20,8 @@ import org.aopalliance.intercept.MethodInvocation;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link SimpleTraceInterceptor} class.
|
||||
@@ -61,8 +56,13 @@ public class SimpleTraceInterceptorTests {
|
||||
Log log = mock(Log.class);
|
||||
|
||||
final SimpleTraceInterceptor interceptor = new SimpleTraceInterceptor(true);
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
interceptor.invokeUnderTrace(mi, log));
|
||||
|
||||
try {
|
||||
interceptor.invokeUnderTrace(mi, log);
|
||||
fail("Must have propagated the IllegalArgumentException.");
|
||||
}
|
||||
catch (IllegalArgumentException expected) {
|
||||
}
|
||||
|
||||
verify(log).trace(anyString());
|
||||
verify(log).trace(anyString(), eq(exception));
|
||||
|
||||
+10
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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,8 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* Unit tests for the {@link DefaultScopedObject} class.
|
||||
@@ -34,28 +33,24 @@ public class DefaultScopedObjectTests {
|
||||
private static final String GOOD_BEAN_NAME = "foo";
|
||||
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCtorWithNullBeanFactory() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new DefaultScopedObject(null, GOOD_BEAN_NAME));
|
||||
new DefaultScopedObject(null, GOOD_BEAN_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCtorWithNullTargetBeanName() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
testBadTargetBeanName(null));
|
||||
testBadTargetBeanName(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCtorWithEmptyTargetBeanName() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
testBadTargetBeanName(""));
|
||||
testBadTargetBeanName("");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testCtorWithJustWhitespacedTargetBeanName() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
testBadTargetBeanName(" "));
|
||||
testBadTargetBeanName(" ");
|
||||
}
|
||||
|
||||
private static void testBadTargetBeanName(final String badTargetBeanName) {
|
||||
|
||||
+10
-10
@@ -23,8 +23,8 @@ import org.junit.Test;
|
||||
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -39,12 +39,12 @@ public class ScopedProxyAutowireTests {
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireFalse.xml"));
|
||||
|
||||
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")).isTrue();
|
||||
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")).isTrue();
|
||||
assertThat(bf.containsSingleton("scoped")).isFalse();
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
|
||||
assertFalse(bf.containsSingleton("scoped"));
|
||||
TestBean autowired = (TestBean) bf.getBean("autowired");
|
||||
TestBean unscoped = (TestBean) bf.getBean("unscoped");
|
||||
assertThat(autowired.getChild()).isSameAs(unscoped);
|
||||
assertSame(unscoped, autowired.getChild());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -53,12 +53,12 @@ public class ScopedProxyAutowireTests {
|
||||
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(
|
||||
qualifiedResource(ScopedProxyAutowireTests.class, "scopedAutowireTrue.xml"));
|
||||
|
||||
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped")).isTrue();
|
||||
assertThat(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped")).isTrue();
|
||||
assertThat(bf.containsSingleton("scoped")).isFalse();
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, true, false)).contains("scoped"));
|
||||
assertTrue(Arrays.asList(bf.getBeanNamesForType(TestBean.class, false, false)).contains("scoped"));
|
||||
assertFalse(bf.containsSingleton("scoped"));
|
||||
TestBean autowired = (TestBean) bf.getBean("autowired");
|
||||
TestBean scoped = (TestBean) bf.getBean("scoped");
|
||||
assertThat(autowired.getChild()).isSameAs(scoped);
|
||||
assertSame(scoped, autowired.getChild());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+18
-18
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,7 +24,7 @@ import org.junit.Test;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -54,9 +54,9 @@ public abstract class AbstractRegexpMethodPointcutTests {
|
||||
}
|
||||
|
||||
protected void noPatternSuppliedTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isFalse();
|
||||
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
|
||||
assertThat(rpc.getPatterns().length).isEqualTo(0);
|
||||
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||
assertEquals(0, rpc.getPatterns().length);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,46 +69,46 @@ public abstract class AbstractRegexpMethodPointcutTests {
|
||||
|
||||
protected void exactMatchTests(AbstractRegexpMethodPointcut rpc) throws Exception {
|
||||
// assumes rpc.setPattern("java.lang.Object.hashCode");
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
|
||||
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
|
||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSpecificMatch() throws Exception {
|
||||
rpc.setPattern("java.lang.String.hashCode");
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isFalse();
|
||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||
assertFalse(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcard() throws Exception {
|
||||
rpc.setPattern(".*Object.hashCode");
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), Object.class)).isTrue();
|
||||
assertThat(rpc.matches(Object.class.getMethod("wait"), Object.class)).isFalse();
|
||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), Object.class));
|
||||
assertFalse(rpc.matches(Object.class.getMethod("wait"), Object.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWildcardForOneClass() throws Exception {
|
||||
rpc.setPattern("java.lang.Object.*");
|
||||
assertThat(rpc.matches(Object.class.getMethod("hashCode"), String.class)).isTrue();
|
||||
assertThat(rpc.matches(Object.class.getMethod("wait"), String.class)).isTrue();
|
||||
assertTrue(rpc.matches(Object.class.getMethod("hashCode"), String.class));
|
||||
assertTrue(rpc.matches(Object.class.getMethod("wait"), String.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatchesObjectClass() throws Exception {
|
||||
rpc.setPattern("java.lang.Object.*");
|
||||
assertThat(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class)).isTrue();
|
||||
assertTrue(rpc.matches(Exception.class.getMethod("hashCode"), IOException.class));
|
||||
// Doesn't match a method from Throwable
|
||||
assertThat(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class)).isFalse();
|
||||
assertFalse(rpc.matches(Exception.class.getMethod("getMessage"), Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testWithExclusion() throws Exception {
|
||||
this.rpc.setPattern(".*get.*");
|
||||
this.rpc.setExcludedPattern(".*Age.*");
|
||||
assertThat(this.rpc.matches(TestBean.class.getMethod("getName"), TestBean.class)).isTrue();
|
||||
assertThat(this.rpc.matches(TestBean.class.getMethod("getAge"), TestBean.class)).isFalse();
|
||||
assertTrue(this.rpc.matches(TestBean.class.getMethod("getName"), TestBean.class));
|
||||
assertFalse(this.rpc.matches(TestBean.class.getMethod("getAge"), TestBean.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -30,7 +30,7 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -48,13 +48,13 @@ public class AopUtilsTests {
|
||||
}
|
||||
|
||||
Pointcut no = new TestPointcut();
|
||||
assertThat(AopUtils.canApply(no, Object.class)).isFalse();
|
||||
assertFalse(AopUtils.canApply(no, Object.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPointcutAlwaysApplies() {
|
||||
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class)).isTrue();
|
||||
assertThat(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class)).isTrue();
|
||||
assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), Object.class));
|
||||
assertTrue(AopUtils.canApply(new DefaultPointcutAdvisor(new NopInterceptor()), TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,7 +69,7 @@ public class AopUtilsTests {
|
||||
Pointcut pc = new TestPointcut();
|
||||
|
||||
// will return true if we're not proxying interfaces
|
||||
assertThat(AopUtils.canApply(pc, Object.class)).isTrue();
|
||||
assertTrue(AopUtils.canApply(pc, Object.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -79,13 +79,14 @@ public class AopUtilsTests {
|
||||
*/
|
||||
@Test
|
||||
public void testCanonicalFrameworkClassesStillCanonicalOnDeserialization() throws Exception {
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE)).isSameAs(MethodMatcher.TRUE);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE)).isSameAs(ClassFilter.TRUE);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE)).isSameAs(Pointcut.TRUE);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE)).isSameAs(EmptyTargetSource.INSTANCE);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS)).isSameAs(Pointcuts.SETTERS);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS)).isSameAs(Pointcuts.GETTERS);
|
||||
assertThat(SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE)).isSameAs(ExposeInvocationInterceptor.INSTANCE);
|
||||
assertSame(MethodMatcher.TRUE, SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
|
||||
assertSame(ClassFilter.TRUE, SerializationTestUtils.serializeAndDeserialize(ClassFilter.TRUE));
|
||||
assertSame(Pointcut.TRUE, SerializationTestUtils.serializeAndDeserialize(Pointcut.TRUE));
|
||||
assertSame(EmptyTargetSource.INSTANCE, SerializationTestUtils.serializeAndDeserialize(EmptyTargetSource.INSTANCE));
|
||||
assertSame(Pointcuts.SETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.SETTERS));
|
||||
assertSame(Pointcuts.GETTERS, SerializationTestUtils.serializeAndDeserialize(Pointcuts.GETTERS));
|
||||
assertSame(ExposeInvocationInterceptor.INSTANCE,
|
||||
SerializationTestUtils.serializeAndDeserialize(ExposeInvocationInterceptor.INSTANCE));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -23,7 +23,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -39,23 +39,23 @@ public class ClassFiltersTests {
|
||||
|
||||
@Test
|
||||
public void testUnion() {
|
||||
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
|
||||
assertThat(exceptionFilter.matches(TestBean.class)).isFalse();
|
||||
assertThat(itbFilter.matches(Exception.class)).isFalse();
|
||||
assertThat(itbFilter.matches(TestBean.class)).isTrue();
|
||||
assertTrue(exceptionFilter.matches(RuntimeException.class));
|
||||
assertFalse(exceptionFilter.matches(TestBean.class));
|
||||
assertFalse(itbFilter.matches(Exception.class));
|
||||
assertTrue(itbFilter.matches(TestBean.class));
|
||||
ClassFilter union = ClassFilters.union(exceptionFilter, itbFilter);
|
||||
assertThat(union.matches(RuntimeException.class)).isTrue();
|
||||
assertThat(union.matches(TestBean.class)).isTrue();
|
||||
assertTrue(union.matches(RuntimeException.class));
|
||||
assertTrue(union.matches(TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersection() {
|
||||
assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
|
||||
assertThat(hasRootCauseFilter.matches(NestedRuntimeException.class)).isTrue();
|
||||
assertTrue(exceptionFilter.matches(RuntimeException.class));
|
||||
assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class));
|
||||
ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
|
||||
assertThat(intersection.matches(RuntimeException.class)).isFalse();
|
||||
assertThat(intersection.matches(TestBean.class)).isFalse();
|
||||
assertThat(intersection.matches(NestedRuntimeException.class)).isTrue();
|
||||
assertFalse(intersection.matches(RuntimeException.class));
|
||||
assertFalse(intersection.matches(TestBean.class));
|
||||
assertTrue(intersection.matches(NestedRuntimeException.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import org.springframework.aop.framework.ProxyFactory;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.ClassUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Colin Sampaleanu
|
||||
@@ -39,6 +39,6 @@ public class ClassUtilsTests {
|
||||
pf.setProxyTargetClass(true);
|
||||
TestBean proxy = (TestBean) pf.getProxy();
|
||||
String className = ClassUtils.getShortName(proxy.getClass());
|
||||
assertThat(className).as("Class name did not match").isEqualTo("TestBean");
|
||||
assertEquals("Class name did not match", "TestBean", className);
|
||||
}
|
||||
}
|
||||
|
||||
+40
-40
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.core.NestedRuntimeException;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -67,68 +67,68 @@ public class ComposablePointcutTests {
|
||||
@Test
|
||||
public void testMatchAll() throws NoSuchMethodException {
|
||||
Pointcut pc = new ComposablePointcut();
|
||||
assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
|
||||
assertThat(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class)).isTrue();
|
||||
assertTrue(pc.getClassFilter().matches(Object.class));
|
||||
assertTrue(pc.getMethodMatcher().matches(Object.class.getMethod("hashCode"), Exception.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterByClass() throws NoSuchMethodException {
|
||||
ComposablePointcut pc = new ComposablePointcut();
|
||||
|
||||
assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
|
||||
assertTrue(pc.getClassFilter().matches(Object.class));
|
||||
|
||||
ClassFilter cf = new RootClassFilter(Exception.class);
|
||||
pc.intersection(cf);
|
||||
assertThat(pc.getClassFilter().matches(Object.class)).isFalse();
|
||||
assertThat(pc.getClassFilter().matches(Exception.class)).isTrue();
|
||||
assertFalse(pc.getClassFilter().matches(Object.class));
|
||||
assertTrue(pc.getClassFilter().matches(Exception.class));
|
||||
pc.intersection(new RootClassFilter(NestedRuntimeException.class));
|
||||
assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
|
||||
assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
|
||||
assertThat(pc.getClassFilter().matches(String.class)).isFalse();
|
||||
assertFalse(pc.getClassFilter().matches(Exception.class));
|
||||
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
|
||||
assertFalse(pc.getClassFilter().matches(String.class));
|
||||
pc.union(new RootClassFilter(String.class));
|
||||
assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
|
||||
assertThat(pc.getClassFilter().matches(String.class)).isTrue();
|
||||
assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
|
||||
assertFalse(pc.getClassFilter().matches(Exception.class));
|
||||
assertTrue(pc.getClassFilter().matches(String.class));
|
||||
assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionMethodMatcher() {
|
||||
// Matches the getAge() method in any class
|
||||
ComposablePointcut pc = new ComposablePointcut(ClassFilter.TRUE, GET_AGE_METHOD_MATCHER);
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
|
||||
pc.union(GETTER_METHOD_MATCHER);
|
||||
// Should now match all getter methods
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
|
||||
pc.union(ABSQUATULATE_METHOD_MATCHER);
|
||||
// Should now match absquatulate() as well
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
// But it doesn't match everything
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_SET_AGE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntersectionMethodMatcher() {
|
||||
ComposablePointcut pc = new ComposablePointcut();
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
pc.intersection(GETTER_METHOD_MATCHER);
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertFalse(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(pc.getMethodMatcher().matches(PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
pc.intersection(GET_AGE_METHOD_MATCHER);
|
||||
// Use the Pointcuts matches method
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(pc, PointcutsTests.TEST_BEAN_GET_NAME, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -136,24 +136,24 @@ public class ComposablePointcutTests {
|
||||
ComposablePointcut pc1 = new ComposablePointcut();
|
||||
ComposablePointcut pc2 = new ComposablePointcut();
|
||||
|
||||
assertThat(pc2).isEqualTo(pc1);
|
||||
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
|
||||
assertEquals(pc1, pc2);
|
||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||
|
||||
pc1.intersection(GETTER_METHOD_MATCHER);
|
||||
|
||||
assertThat(pc1.equals(pc2)).isFalse();
|
||||
assertThat(pc1.hashCode() == pc2.hashCode()).isFalse();
|
||||
assertFalse(pc1.equals(pc2));
|
||||
assertFalse(pc1.hashCode() == pc2.hashCode());
|
||||
|
||||
pc2.intersection(GETTER_METHOD_MATCHER);
|
||||
|
||||
assertThat(pc2).isEqualTo(pc1);
|
||||
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
|
||||
assertEquals(pc1, pc2);
|
||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||
|
||||
pc1.union(GET_AGE_METHOD_MATCHER);
|
||||
pc2.union(GET_AGE_METHOD_MATCHER);
|
||||
|
||||
assertThat(pc2).isEqualTo(pc1);
|
||||
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
|
||||
assertEquals(pc1, pc2);
|
||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+20
-20
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.
|
||||
@@ -24,7 +24,7 @@ import org.springframework.tests.aop.interceptor.NopInterceptor;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -43,17 +43,17 @@ public class ControlFlowPointcutTests {
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(cflow, nop));
|
||||
|
||||
// Not advised, not under One
|
||||
assertThat(proxied.getAge()).isEqualTo(target.getAge());
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(target.getAge(), proxied.getAge());
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
// Will be advised
|
||||
assertThat(new One().getAge(proxied)).isEqualTo(target.getAge());
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(target.getAge(), new One().getAge(proxied));
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
// Won't be advised
|
||||
assertThat(new One().nomatch(proxied)).isEqualTo(target.getAge());
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertThat(cflow.getEvaluations()).isEqualTo(3);
|
||||
assertEquals(target.getAge(), new One().nomatch(proxied));
|
||||
assertEquals(1, nop.getCount());
|
||||
assertEquals(3, cflow.getEvaluations());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -76,28 +76,28 @@ public class ControlFlowPointcutTests {
|
||||
|
||||
// Not advised, not under One
|
||||
target.setAge(16);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
// Not advised; under One but not a setter
|
||||
assertThat(new One().getAge(proxied)).isEqualTo(16);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(16, new One().getAge(proxied));
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
// Won't be advised
|
||||
new One().set(proxied);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
// We saved most evaluations
|
||||
assertThat(cflow.getEvaluations()).isEqualTo(1);
|
||||
assertEquals(1, cflow.getEvaluations());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsAndHashCode() throws Exception {
|
||||
assertThat(new ControlFlowPointcut(One.class)).isEqualTo(new ControlFlowPointcut(One.class));
|
||||
assertThat(new ControlFlowPointcut(One.class, "getAge")).isEqualTo(new ControlFlowPointcut(One.class, "getAge"));
|
||||
assertThat(new ControlFlowPointcut(One.class, "getAge").equals(new ControlFlowPointcut(One.class))).isFalse();
|
||||
assertThat(new ControlFlowPointcut(One.class).hashCode()).isEqualTo(new ControlFlowPointcut(One.class).hashCode());
|
||||
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode()).isEqualTo(new ControlFlowPointcut(One.class, "getAge").hashCode());
|
||||
assertThat(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode()).isFalse();
|
||||
assertEquals(new ControlFlowPointcut(One.class), new ControlFlowPointcut(One.class));
|
||||
assertEquals(new ControlFlowPointcut(One.class, "getAge"), new ControlFlowPointcut(One.class, "getAge"));
|
||||
assertFalse(new ControlFlowPointcut(One.class, "getAge").equals(new ControlFlowPointcut(One.class)));
|
||||
assertEquals(new ControlFlowPointcut(One.class).hashCode(), new ControlFlowPointcut(One.class).hashCode());
|
||||
assertEquals(new ControlFlowPointcut(One.class, "getAge").hashCode(), new ControlFlowPointcut(One.class, "getAge").hashCode());
|
||||
assertFalse(new ControlFlowPointcut(One.class, "getAge").hashCode() == new ControlFlowPointcut(One.class).hashCode());
|
||||
}
|
||||
|
||||
public class One {
|
||||
|
||||
+31
-33
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -34,10 +34,9 @@ import org.springframework.tests.sample.beans.SerializablePerson;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.hamcrest.Matchers.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.BDDMockito.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -46,17 +45,16 @@ import static org.mockito.Mockito.mock;
|
||||
*/
|
||||
public class DelegatingIntroductionInterceptorTests {
|
||||
|
||||
@Test
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void testNullTarget() throws Exception {
|
||||
// Shouldn't accept null target
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
new DelegatingIntroductionInterceptor(null));
|
||||
new DelegatingIntroductionInterceptor(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntroductionInterceptorWithDelegation() throws Exception {
|
||||
TestBean raw = new TestBean();
|
||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||
assertTrue(! (raw instanceof TimeStamped));
|
||||
ProxyFactory factory = new ProxyFactory(raw);
|
||||
|
||||
TimeStamped ts = mock(TimeStamped.class);
|
||||
@@ -66,13 +64,13 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts)));
|
||||
|
||||
TimeStamped tsp = (TimeStamped) factory.getProxy();
|
||||
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
|
||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntroductionInterceptorWithInterfaceHierarchy() throws Exception {
|
||||
TestBean raw = new TestBean();
|
||||
assertThat(! (raw instanceof SubTimeStamped)).isTrue();
|
||||
assertTrue(! (raw instanceof SubTimeStamped));
|
||||
ProxyFactory factory = new ProxyFactory(raw);
|
||||
|
||||
TimeStamped ts = mock(SubTimeStamped.class);
|
||||
@@ -82,13 +80,13 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), SubTimeStamped.class));
|
||||
|
||||
SubTimeStamped tsp = (SubTimeStamped) factory.getProxy();
|
||||
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
|
||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIntroductionInterceptorWithSuperInterface() throws Exception {
|
||||
TestBean raw = new TestBean();
|
||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||
assertTrue(! (raw instanceof TimeStamped));
|
||||
ProxyFactory factory = new ProxyFactory(raw);
|
||||
|
||||
TimeStamped ts = mock(SubTimeStamped.class);
|
||||
@@ -98,8 +96,8 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
factory.addAdvisor(0, new DefaultIntroductionAdvisor(new DelegatingIntroductionInterceptor(ts), TimeStamped.class));
|
||||
|
||||
TimeStamped tsp = (TimeStamped) factory.getProxy();
|
||||
assertThat(!(tsp instanceof SubTimeStamped)).isTrue();
|
||||
assertThat(tsp.getTimeStamp() == timestamp).isTrue();
|
||||
assertTrue(!(tsp instanceof SubTimeStamped));
|
||||
assertTrue(tsp.getTimeStamp() == timestamp);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -125,7 +123,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
|
||||
TimeStamped ts = (TimeStamped) pf.getProxy();
|
||||
|
||||
assertThat(ts.getTimeStamp() == t).isTrue();
|
||||
assertTrue(ts.getTimeStamp() == t);
|
||||
((ITester) ts).foo();
|
||||
|
||||
((ITestBean) ts).getAge();
|
||||
@@ -152,18 +150,18 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
|
||||
ProxyFactory pf = new ProxyFactory(target);
|
||||
IntroductionAdvisor ia = new DefaultIntroductionAdvisor(ii);
|
||||
assertThat(ia.isPerInstance()).isTrue();
|
||||
assertTrue(ia.isPerInstance());
|
||||
pf.addAdvisor(0, ia);
|
||||
|
||||
//assertTrue(Arrays.binarySearch(pf.getProxiedInterfaces(), TimeStamped.class) != -1);
|
||||
TimeStamped ts = (TimeStamped) pf.getProxy();
|
||||
|
||||
assertThat(ts).isInstanceOf(TimeStamped.class);
|
||||
assertThat(ts, instanceOf(TimeStamped.class));
|
||||
// Shouldn't proxy framework interfaces
|
||||
assertThat(!(ts instanceof MethodInterceptor)).isTrue();
|
||||
assertThat(!(ts instanceof IntroductionInterceptor)).isTrue();
|
||||
assertTrue(!(ts instanceof MethodInterceptor));
|
||||
assertTrue(!(ts instanceof IntroductionInterceptor));
|
||||
|
||||
assertThat(ts.getTimeStamp() == t).isTrue();
|
||||
assertTrue(ts.getTimeStamp() == t);
|
||||
((ITester) ts).foo();
|
||||
((ITestBean) ts).getAge();
|
||||
|
||||
@@ -174,14 +172,14 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
pf = new ProxyFactory(target);
|
||||
pf.addAdvisor(0, new DefaultIntroductionAdvisor(ii));
|
||||
Object o = pf.getProxy();
|
||||
assertThat(!(o instanceof TimeStamped)).isTrue();
|
||||
assertTrue(!(o instanceof TimeStamped));
|
||||
}
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@Test
|
||||
public void testIntroductionInterceptorDoesntReplaceToString() throws Exception {
|
||||
TestBean raw = new TestBean();
|
||||
assertThat(! (raw instanceof TimeStamped)).isTrue();
|
||||
assertTrue(! (raw instanceof TimeStamped));
|
||||
ProxyFactory factory = new ProxyFactory(raw);
|
||||
|
||||
TimeStamped ts = new SerializableTimeStamped(0);
|
||||
@@ -194,9 +192,9 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
}));
|
||||
|
||||
TimeStamped tsp = (TimeStamped) factory.getProxy();
|
||||
assertThat(tsp.getTimeStamp()).isEqualTo(0);
|
||||
assertEquals(0, tsp.getTimeStamp());
|
||||
|
||||
assertThat(tsp.toString()).isEqualTo(raw.toString());
|
||||
assertEquals(raw.toString(), tsp.toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -214,10 +212,10 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
pf.addAdvice(new DelegatingIntroductionInterceptor(delegate));
|
||||
INestedTestBean proxy = (INestedTestBean) pf.getProxy();
|
||||
|
||||
assertThat(proxy.getCompany()).isEqualTo(company);
|
||||
assertEquals(company, proxy.getCompany());
|
||||
ITestBean introduction = (ITestBean) proxy;
|
||||
assertThat(introduction.getSpouse()).as("Introduced method returning delegate returns proxy").isSameAs(introduction);
|
||||
assertThat(AopUtils.isAopProxy(introduction.getSpouse())).as("Introduced method returning delegate returns proxy").isTrue();
|
||||
assertSame("Introduced method returning delegate returns proxy", introduction, introduction.getSpouse());
|
||||
assertTrue("Introduced method returning delegate returns proxy", AopUtils.isAopProxy(introduction.getSpouse()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -236,12 +234,12 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
|
||||
Person p = (Person) factory.getProxy();
|
||||
|
||||
assertThat(p.getName()).isEqualTo(name);
|
||||
assertThat(((TimeStamped) p).getTimeStamp()).isEqualTo(time);
|
||||
assertEquals(name, p.getName());
|
||||
assertEquals(time, ((TimeStamped) p).getTimeStamp());
|
||||
|
||||
Person p1 = (Person) SerializationTestUtils.serializeAndDeserialize(p);
|
||||
assertThat(p1.getName()).isEqualTo(name);
|
||||
assertThat(((TimeStamped) p1).getTimeStamp()).isEqualTo(time);
|
||||
assertEquals(name, p1.getName());
|
||||
assertEquals(time, ((TimeStamped) p1).getTimeStamp());
|
||||
}
|
||||
|
||||
// Test when target implements the interface: should get interceptor by preference.
|
||||
@@ -266,7 +264,7 @@ public class DelegatingIntroductionInterceptorTests {
|
||||
|
||||
TimeStamped ts = (TimeStamped) pf.getProxy();
|
||||
// From introduction interceptor, not target
|
||||
assertThat(ts.getTimeStamp() == t).isTrue();
|
||||
assertTrue(ts.getTimeStamp() == t);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -55,24 +55,24 @@ public class MethodMatchersTests {
|
||||
@Test
|
||||
public void testDefaultMatchesAll() throws Exception {
|
||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
|
||||
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
|
||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMethodMatcherTrueSerializable() throws Exception {
|
||||
assertThat(MethodMatcher.TRUE).isSameAs(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE));
|
||||
assertSame(SerializationTestUtils.serializeAndDeserialize(MethodMatcher.TRUE), MethodMatcher.TRUE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSingle() throws Exception {
|
||||
MethodMatcher defaultMm = MethodMatcher.TRUE;
|
||||
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
|
||||
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
|
||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||
assertTrue(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
defaultMm = MethodMatchers.intersection(defaultMm, new StartsWithMatcher("get"));
|
||||
|
||||
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
|
||||
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isFalse();
|
||||
assertTrue(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class));
|
||||
assertFalse(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -81,14 +81,14 @@ public class MethodMatchersTests {
|
||||
MethodMatcher mm1 = MethodMatcher.TRUE;
|
||||
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
|
||||
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
|
||||
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
|
||||
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
|
||||
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))).as("3Matched setAge method").isTrue();
|
||||
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
||||
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertTrue("3Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
|
||||
// Knock out dynamic part
|
||||
intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
|
||||
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
|
||||
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
|
||||
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5))).as("3 - not Matched setAge method").isFalse();
|
||||
assertTrue("Intersection is a dynamic matcher", intersection.isRuntime());
|
||||
assertTrue("2Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertFalse("3 - not Matched setAge method", intersection.matches(ITESTBEAN_SETAGE, TestBean.class, new Integer(5)));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,18 +97,18 @@ public class MethodMatchersTests {
|
||||
MethodMatcher setterMatcher = new StartsWithMatcher("set");
|
||||
MethodMatcher union = MethodMatchers.union(getterMatcher, setterMatcher);
|
||||
|
||||
assertThat(union.isRuntime()).as("Union is a static matcher").isFalse();
|
||||
assertThat(union.matches(ITESTBEAN_SETAGE, TestBean.class)).as("Matched setAge method").isTrue();
|
||||
assertThat(union.matches(ITESTBEAN_GETAGE, TestBean.class)).as("Matched getAge method").isTrue();
|
||||
assertThat(union.matches(IOTHER_ABSQUATULATE, TestBean.class)).as("Didn't matched absquatulate method").isFalse();
|
||||
assertFalse("Union is a static matcher", union.isRuntime());
|
||||
assertTrue("Matched setAge method", union.matches(ITESTBEAN_SETAGE, TestBean.class));
|
||||
assertTrue("Matched getAge method", union.matches(ITESTBEAN_GETAGE, TestBean.class));
|
||||
assertFalse("Didn't matched absquatulate method", union.matches(IOTHER_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionEquals() {
|
||||
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
|
||||
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
|
||||
assertThat(first.equals(second)).isTrue();
|
||||
assertThat(second.equals(first)).isTrue();
|
||||
assertTrue(first.equals(second));
|
||||
assertTrue(second.equals(first));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+27
-27
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.tests.sample.beans.Person;
|
||||
import org.springframework.tests.sample.beans.SerializablePerson;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -58,21 +58,21 @@ public class NameMatchMethodPointcutTests {
|
||||
@Test
|
||||
public void testMatchingOnly() {
|
||||
// Can't do exact matching through isMatch
|
||||
assertThat(pc.isMatch("echo", "ech*")).isTrue();
|
||||
assertThat(pc.isMatch("setName", "setN*")).isTrue();
|
||||
assertThat(pc.isMatch("setName", "set*")).isTrue();
|
||||
assertThat(pc.isMatch("getName", "set*")).isFalse();
|
||||
assertThat(pc.isMatch("setName", "set")).isFalse();
|
||||
assertThat(pc.isMatch("testing", "*ing")).isTrue();
|
||||
assertTrue(pc.isMatch("echo", "ech*"));
|
||||
assertTrue(pc.isMatch("setName", "setN*"));
|
||||
assertTrue(pc.isMatch("setName", "set*"));
|
||||
assertFalse(pc.isMatch("getName", "set*"));
|
||||
assertFalse(pc.isMatch("setName", "set"));
|
||||
assertTrue(pc.isMatch("testing", "*ing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEmpty() throws Throwable {
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.getName();
|
||||
proxied.setName("");
|
||||
proxied.echo(null);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
}
|
||||
|
||||
|
||||
@@ -80,29 +80,29 @@ public class NameMatchMethodPointcutTests {
|
||||
public void testMatchOneMethod() throws Throwable {
|
||||
pc.addMethodName("echo");
|
||||
pc.addMethodName("set*");
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.getName();
|
||||
proxied.getName();
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.echo(null);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
|
||||
proxied.setName("");
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertEquals(2, nop.getCount());
|
||||
proxied.setAge(25);
|
||||
assertThat(proxied.getAge()).isEqualTo(25);
|
||||
assertThat(nop.getCount()).isEqualTo(3);
|
||||
assertEquals(25, proxied.getAge());
|
||||
assertEquals(3, nop.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSets() throws Throwable {
|
||||
pc.setMappedNames("set*", "echo");
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
proxied.getName();
|
||||
proxied.setName("");
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
proxied.echo(null);
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertEquals(2, nop.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -112,9 +112,9 @@ public class NameMatchMethodPointcutTests {
|
||||
Person p2 = (Person) SerializationTestUtils.serializeAndDeserialize(proxied);
|
||||
NopInterceptor nop2 = (NopInterceptor) ((Advised) p2).getAdvisors()[0].getAdvice();
|
||||
p2.getName();
|
||||
assertThat(nop2.getCount()).isEqualTo(2);
|
||||
assertEquals(2, nop2.getCount());
|
||||
p2.echo(null);
|
||||
assertThat(nop2.getCount()).isEqualTo(3);
|
||||
assertEquals(3, nop2.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -124,16 +124,16 @@ public class NameMatchMethodPointcutTests {
|
||||
|
||||
String foo = "foo";
|
||||
|
||||
assertThat(pc2).isEqualTo(pc1);
|
||||
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
|
||||
assertEquals(pc1, pc2);
|
||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||
|
||||
pc1.setMappedName(foo);
|
||||
assertThat(pc1.equals(pc2)).isFalse();
|
||||
assertThat(pc1.hashCode() != pc2.hashCode()).isTrue();
|
||||
assertFalse(pc1.equals(pc2));
|
||||
assertTrue(pc1.hashCode() != pc2.hashCode());
|
||||
|
||||
pc2.setMappedName(foo);
|
||||
assertThat(pc2).isEqualTo(pc1);
|
||||
assertThat(pc2.hashCode()).isEqualTo(pc1.hashCode());
|
||||
assertEquals(pc1, pc2);
|
||||
assertEquals(pc1.hashCode(), pc2.hashCode());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -25,7 +25,7 @@ import org.springframework.aop.Pointcut;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -126,22 +126,22 @@ public class PointcutsTests {
|
||||
|
||||
@Test
|
||||
public void testTrue() {
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(Pointcut.TRUE, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMatches() {
|
||||
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
|
||||
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertTrue(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(allClassSetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(allClassGetterPointcut, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -150,29 +150,29 @@ public class PointcutsTests {
|
||||
@Test
|
||||
public void testUnionOfSettersAndGetters() {
|
||||
Pointcut union = Pointcuts.union(allClassGetterPointcut, allClassSetterPointcut);
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUnionOfSpecificGetters() {
|
||||
Pointcut union = Pointcuts.union(allClassGetAgePointcut, allClassGetNamePointcut);
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
|
||||
// Union with all setters
|
||||
union = Pointcuts.union(union, allClassSetterPointcut);
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isTrue();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -181,16 +181,16 @@ public class PointcutsTests {
|
||||
*/
|
||||
@Test
|
||||
public void testUnionOfAllSettersAndSubclassSetters() {
|
||||
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
|
||||
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertTrue(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
|
||||
assertFalse(Pointcuts.matches(myTestBeanSetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
|
||||
Pointcut union = Pointcuts.union(myTestBeanSetterPointcut, allClassGetterPointcut);
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
// Still doesn't match superclass setter
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6))).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_SET_AGE, MyTestBean.class, new Integer(6)));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -199,44 +199,44 @@ public class PointcutsTests {
|
||||
*/
|
||||
@Test
|
||||
public void testIntersectionOfSpecificGettersAndSubclassGetters() {
|
||||
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
|
||||
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(allClassGetAgePointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||
assertTrue(Pointcuts.matches(myTestBeanGetterPointcut, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
|
||||
Pointcut intersection = Pointcuts.intersection(allClassGetAgePointcut, myTestBeanGetterPointcut);
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)).isTrue();
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
// Matches subclass of MyTestBean
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||
|
||||
// Now intersection with MyTestBeanSubclass getters should eliminate MyTestBean target
|
||||
intersection = Pointcuts.intersection(intersection, myTestBeanSubclassGetterPointcut);
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
// Still matches subclass of MyTestBean
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||
assertTrue(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||
|
||||
// Now union with all TestBean methods
|
||||
Pointcut union = Pointcuts.union(intersection, allTestBeanMethodsPointcut);
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class)).isFalse();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_NAME, TestBean.class));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBean.class));
|
||||
// Still matches subclass of MyTestBean
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class)).isTrue();
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_GET_NAME, MyTestBeanSubclass.class));
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_GET_AGE, MyTestBeanSubclass.class));
|
||||
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class)).isTrue();
|
||||
assertThat(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class)).isFalse();
|
||||
assertTrue(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(union, TEST_BEAN_ABSQUATULATE, MyTestBean.class));
|
||||
}
|
||||
|
||||
|
||||
@@ -246,9 +246,9 @@ public class PointcutsTests {
|
||||
@Test
|
||||
public void testSimpleIntersection() {
|
||||
Pointcut intersection = Pointcuts.intersection(allClassGetterPointcut, allClassSetterPointcut);
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6))).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class)).isFalse();
|
||||
assertThat(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class)).isFalse();
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_SET_AGE, TestBean.class, new Integer(6)));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_GET_AGE, TestBean.class));
|
||||
assertFalse(Pointcuts.matches(intersection, TEST_BEAN_ABSQUATULATE, TestBean.class));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+22
-22
@@ -29,8 +29,8 @@ import org.springframework.tests.sample.beans.Person;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -49,16 +49,16 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
ITestBean advised = (ITestBean) bf.getBean("settersAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
advised.exceptional(null);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
advised.setAge(newAge);
|
||||
assertThat(advised.getAge()).isEqualTo(newAge);
|
||||
assertEquals(newAge, advised.getAge());
|
||||
// Only setter fired
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,20 +69,20 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
TestBean advised = (TestBean) bf.getBean("settersAndAbsquatulateAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
advised.exceptional(null);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
// This is proxied
|
||||
advised.absquatulate();
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
advised.setAge(newAge);
|
||||
assertThat(advised.getAge()).isEqualTo(newAge);
|
||||
assertEquals(newAge, advised.getAge());
|
||||
// Only setter fired
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertEquals(2, nop.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -93,31 +93,31 @@ public class RegexpMethodPointcutAdvisorIntegrationTests {
|
||||
Person p = (Person) bf.getBean("serializableSettersAdvised");
|
||||
// Interceptor behind regexp advisor
|
||||
NopInterceptor nop = (NopInterceptor) bf.getBean("nopInterceptor");
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
int newAge = 12;
|
||||
// Not advised
|
||||
assertThat(p.getAge()).isEqualTo(0);
|
||||
assertThat(nop.getCount()).isEqualTo(0);
|
||||
assertEquals(0, p.getAge());
|
||||
assertEquals(0, nop.getCount());
|
||||
|
||||
// This is proxied
|
||||
p.setAge(newAge);
|
||||
assertThat(nop.getCount()).isEqualTo(1);
|
||||
assertEquals(1, nop.getCount());
|
||||
p.setAge(newAge);
|
||||
assertThat(p.getAge()).isEqualTo(newAge);
|
||||
assertEquals(newAge, p.getAge());
|
||||
// Only setter fired
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertEquals(2, nop.getCount());
|
||||
|
||||
// Serialize and continue...
|
||||
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
|
||||
assertThat(p.getAge()).isEqualTo(newAge);
|
||||
assertEquals(newAge, p.getAge());
|
||||
// Remembers count, but we need to get a new reference to nop...
|
||||
nop = (SerializableNopInterceptor) ((Advised) p).getAdvisors()[0].getAdvice();
|
||||
assertThat(nop.getCount()).isEqualTo(2);
|
||||
assertThat(p.getName()).isEqualTo("serializableSettersAdvised");
|
||||
assertEquals(2, nop.getCount());
|
||||
assertEquals("serializableSettersAdvised", p.getName());
|
||||
p.setAge(newAge + 1);
|
||||
assertThat(nop.getCount()).isEqualTo(3);
|
||||
assertThat(p.getAge()).isEqualTo((newAge + 1));
|
||||
assertEquals(3, nop.getCount());
|
||||
assertEquals(newAge + 1, p.getAge());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+4
-4
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -42,6 +42,6 @@ public class CommonsPool2TargetSourceProxyTests {
|
||||
reader.loadBeanDefinitions(CONTEXT);
|
||||
beanFactory.preInstantiateSingletons();
|
||||
ITestBean bean = (ITestBean)beanFactory.getBean("testBean");
|
||||
assertThat(AopUtils.isAopProxy(bean)).isTrue();
|
||||
assertTrue(AopUtils.isAopProxy(bean));
|
||||
}
|
||||
}
|
||||
|
||||
+26
-19
@@ -31,9 +31,8 @@ import org.springframework.tests.sample.beans.SerializablePerson;
|
||||
import org.springframework.tests.sample.beans.SideEffectBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -70,13 +69,13 @@ public class HotSwappableTargetSourceTests {
|
||||
@Test
|
||||
public void testBasicFunctionality() {
|
||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
assertThat(proxied.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
|
||||
|
||||
proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
proxied.doWork();
|
||||
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 2));
|
||||
assertEquals(INITIAL_COUNT + 2, proxied.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,35 +84,43 @@ public class HotSwappableTargetSourceTests {
|
||||
SideEffectBean target2 = (SideEffectBean) beanFactory.getBean("target2");
|
||||
|
||||
SideEffectBean proxied = (SideEffectBean) beanFactory.getBean("swappable");
|
||||
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
|
||||
assertEquals(target1.getCount(), proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertThat(proxied.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, proxied.getCount());
|
||||
|
||||
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
|
||||
Object old = swapper.swap(target2);
|
||||
assertThat(old).as("Correct old target was returned").isEqualTo(target1);
|
||||
assertEquals("Correct old target was returned", target1, old);
|
||||
|
||||
// TODO should be able to make this assertion: need to fix target handling
|
||||
// in AdvisedSupport
|
||||
//assertEquals(target2, ((Advised) proxied).getTarget());
|
||||
|
||||
assertThat(proxied.getCount()).isEqualTo(20);
|
||||
assertEquals(20, proxied.getCount());
|
||||
proxied.doWork();
|
||||
assertThat(target2.getCount()).isEqualTo(21);
|
||||
assertEquals(21, target2.getCount());
|
||||
|
||||
// Swap it back
|
||||
swapper.swap(target1);
|
||||
assertThat(proxied.getCount()).isEqualTo(target1.getCount());
|
||||
assertEquals(target1.getCount(), proxied.getCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRejectsSwapToNull() {
|
||||
HotSwappableTargetSource swapper = (HotSwappableTargetSource) beanFactory.getBean("swapper");
|
||||
assertThatIllegalArgumentException().as("Shouldn't be able to swap to invalid value").isThrownBy(() ->
|
||||
swapper.swap(null))
|
||||
.withMessageContaining("null");
|
||||
IllegalArgumentException aopex = null;
|
||||
try {
|
||||
swapper.swap(null);
|
||||
fail("Shouldn't be able to swap to invalid value");
|
||||
}
|
||||
catch (IllegalArgumentException ex) {
|
||||
// Ok
|
||||
aopex = ex;
|
||||
}
|
||||
|
||||
// It shouldn't be corrupted, it should still work
|
||||
testBasicFunctionality();
|
||||
assertTrue(aopex.getMessage().contains("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -130,16 +137,16 @@ public class HotSwappableTargetSourceTests {
|
||||
pf.addAdvisor(new DefaultPointcutAdvisor(new SerializableNopInterceptor()));
|
||||
Person p = (Person) pf.getProxy();
|
||||
|
||||
assertThat(p.getName()).isEqualTo(sp1.getName());
|
||||
assertEquals(sp1.getName(), p.getName());
|
||||
hts.swap(sp2);
|
||||
assertThat(p.getName()).isEqualTo(sp2.getName());
|
||||
assertEquals(sp2.getName(), p.getName());
|
||||
|
||||
p = (Person) SerializationTestUtils.serializeAndDeserialize(p);
|
||||
// We need to get a reference to the client-side targetsource
|
||||
hts = (HotSwappableTargetSource) ((Advised) p).getTargetSource();
|
||||
assertThat(p.getName()).isEqualTo(sp2.getName());
|
||||
assertEquals(sp2.getName(), p.getName());
|
||||
hts.swap(sp1);
|
||||
assertThat(p.getName()).isEqualTo(sp1.getName());
|
||||
assertEquals(sp1.getName(), p.getName());
|
||||
|
||||
}
|
||||
|
||||
|
||||
+7
-7
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.aop.TargetSource;
|
||||
import org.springframework.aop.framework.ProxyFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -44,15 +44,15 @@ public class LazyCreationTargetSourceTests {
|
||||
};
|
||||
|
||||
InitCountingBean proxy = (InitCountingBean) ProxyFactory.getProxy(targetSource);
|
||||
assertThat(InitCountingBean.initCount).as("Init count should be 0").isEqualTo(0);
|
||||
assertThat(targetSource.getTargetClass()).as("Target class incorrect").isEqualTo(InitCountingBean.class);
|
||||
assertThat(InitCountingBean.initCount).as("Init count should still be 0 after getTargetClass()").isEqualTo(0);
|
||||
assertEquals("Init count should be 0", 0, InitCountingBean.initCount);
|
||||
assertEquals("Target class incorrect", InitCountingBean.class, targetSource.getTargetClass());
|
||||
assertEquals("Init count should still be 0 after getTargetClass()", 0, InitCountingBean.initCount);
|
||||
|
||||
proxy.doSomething();
|
||||
assertThat(InitCountingBean.initCount).as("Init count should now be 1").isEqualTo(1);
|
||||
assertEquals("Init count should now be 1", 1, InitCountingBean.initCount);
|
||||
|
||||
proxy.doSomething();
|
||||
assertThat(InitCountingBean.initCount).as("Init count should still be 1").isEqualTo(1);
|
||||
assertEquals("Init count should still be 1", 1, InitCountingBean.initCount);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+15
-15
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Juergen Hoeller
|
||||
@@ -49,9 +49,9 @@ public class LazyInitTargetSourceTests {
|
||||
bf.preInstantiateSingletons();
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("proxy");
|
||||
assertThat(bf.containsSingleton("target")).isFalse();
|
||||
assertThat(tb.getAge()).isEqualTo(10);
|
||||
assertThat(bf.containsSingleton("target")).isTrue();
|
||||
assertFalse(bf.containsSingleton("target"));
|
||||
assertEquals(10, tb.getAge());
|
||||
assertTrue(bf.containsSingleton("target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -61,9 +61,9 @@ public class LazyInitTargetSourceTests {
|
||||
bf.preInstantiateSingletons();
|
||||
|
||||
ITestBean tb = (ITestBean) bf.getBean("proxy");
|
||||
assertThat(bf.containsSingleton("target")).isFalse();
|
||||
assertThat(tb.getName()).isEqualTo("Rob Harrop");
|
||||
assertThat(bf.containsSingleton("target")).isTrue();
|
||||
assertFalse(bf.containsSingleton("target"));
|
||||
assertEquals("Rob Harrop", tb.getName());
|
||||
assertTrue(bf.containsSingleton("target"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -73,14 +73,14 @@ public class LazyInitTargetSourceTests {
|
||||
bf.preInstantiateSingletons();
|
||||
|
||||
Set<?> set1 = (Set<?>) bf.getBean("proxy1");
|
||||
assertThat(bf.containsSingleton("target1")).isFalse();
|
||||
assertThat(set1.contains("10")).isTrue();
|
||||
assertThat(bf.containsSingleton("target1")).isTrue();
|
||||
assertFalse(bf.containsSingleton("target1"));
|
||||
assertTrue(set1.contains("10"));
|
||||
assertTrue(bf.containsSingleton("target1"));
|
||||
|
||||
Set<?> set2 = (Set<?>) bf.getBean("proxy2");
|
||||
assertThat(bf.containsSingleton("target2")).isFalse();
|
||||
assertThat(set2.contains("20")).isTrue();
|
||||
assertThat(bf.containsSingleton("target2")).isTrue();
|
||||
assertFalse(bf.containsSingleton("target2"));
|
||||
assertTrue(set2.contains("20"));
|
||||
assertTrue(bf.containsSingleton("target2"));
|
||||
}
|
||||
|
||||
|
||||
|
||||
+5
-6
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2013 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.tests.sample.beans.SerializablePerson;
|
||||
import org.springframework.tests.sample.beans.TestBean;
|
||||
import org.springframework.util.SerializationTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests relating to the abstract {@link AbstractPrototypeBasedTargetSource}
|
||||
@@ -55,10 +55,10 @@ public class PrototypeBasedTargetSourceTests {
|
||||
|
||||
TestTargetSource cpts = (TestTargetSource) bf.getBean("ts");
|
||||
TargetSource serialized = (TargetSource) SerializationTestUtils.serializeAndDeserialize(cpts);
|
||||
boolean condition = serialized instanceof SingletonTargetSource;
|
||||
assertThat(condition).as("Changed to SingletonTargetSource on deserialization").isTrue();
|
||||
assertTrue("Changed to SingletonTargetSource on deserialization",
|
||||
serialized instanceof SingletonTargetSource);
|
||||
SingletonTargetSource sts = (SingletonTargetSource) serialized;
|
||||
assertThat(sts.getTarget()).isNotNull();
|
||||
assertNotNull(sts.getTarget());
|
||||
}
|
||||
|
||||
|
||||
@@ -70,7 +70,6 @@ public class PrototypeBasedTargetSourceTests {
|
||||
* Nonserializable test field to check that subclass
|
||||
* state can't prevent serialization from working
|
||||
*/
|
||||
@SuppressWarnings("unused")
|
||||
private TestBean thisFieldIsNotSerializable = new TestBean();
|
||||
|
||||
@Override
|
||||
|
||||
+6
-6
@@ -23,8 +23,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
|
||||
import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.tests.sample.beans.SideEffectBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -54,14 +54,14 @@ public class PrototypeTargetSourceTests {
|
||||
@Test
|
||||
public void testPrototypeAndSingletonBehaveDifferently() {
|
||||
SideEffectBean singleton = (SideEffectBean) beanFactory.getBean("singleton");
|
||||
assertThat(singleton.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, singleton.getCount());
|
||||
singleton.doWork();
|
||||
assertThat(singleton.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, singleton.getCount());
|
||||
|
||||
SideEffectBean prototype = (SideEffectBean) beanFactory.getBean("prototype");
|
||||
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount());
|
||||
prototype.doWork();
|
||||
assertThat(prototype.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, prototype.getCount());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+29
-24
@@ -24,8 +24,8 @@ import org.springframework.beans.factory.xml.XmlBeanDefinitionReader;
|
||||
import org.springframework.tests.sample.beans.ITestBean;
|
||||
import org.springframework.tests.sample.beans.SideEffectBean;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestResourceUtils.qualifiedResource;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.springframework.tests.TestResourceUtils.*;
|
||||
|
||||
/**
|
||||
* @author Rod Johnson
|
||||
@@ -62,24 +62,24 @@ public class ThreadLocalTargetSourceTests {
|
||||
@Test
|
||||
public void testUseDifferentManagedInstancesInSameThread() {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
|
||||
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
|
||||
assertThat(test.getName()).isEqualTo("Rod");
|
||||
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
|
||||
assertEquals("Rod", test.getName());
|
||||
assertEquals("Kerry", test.getSpouse().getName());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReuseInSameThread() {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
|
||||
apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, apartment.getCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,37 +89,37 @@ public class ThreadLocalTargetSourceTests {
|
||||
public void testCanGetStatsViaMixin() {
|
||||
ThreadLocalTargetSourceStats stats = (ThreadLocalTargetSourceStats) beanFactory.getBean("apartment");
|
||||
// +1 because creating target for stats call counts
|
||||
assertThat(stats.getInvocationCount()).isEqualTo(1);
|
||||
assertEquals(1, stats.getInvocationCount());
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
apartment.doWork();
|
||||
// +1 again
|
||||
assertThat(stats.getInvocationCount()).isEqualTo(3);
|
||||
assertEquals(3, stats.getInvocationCount());
|
||||
// + 1 for states call!
|
||||
assertThat(stats.getHitCount()).isEqualTo(3);
|
||||
assertEquals(3, stats.getHitCount());
|
||||
apartment.doWork();
|
||||
assertThat(stats.getInvocationCount()).isEqualTo(6);
|
||||
assertThat(stats.getHitCount()).isEqualTo(6);
|
||||
assertEquals(6, stats.getInvocationCount());
|
||||
assertEquals(6, stats.getHitCount());
|
||||
// Only one thread so only one object can have been bound
|
||||
assertThat(stats.getObjectCount()).isEqualTo(1);
|
||||
assertEquals(1, stats.getObjectCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNewThreadHasOwnInstance() throws InterruptedException {
|
||||
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, apartment.getCount());
|
||||
apartment.doWork();
|
||||
apartment.doWork();
|
||||
apartment.doWork();
|
||||
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 3));
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
|
||||
|
||||
class Runner implements Runnable {
|
||||
public SideEffectBean mine;
|
||||
@Override
|
||||
public void run() {
|
||||
this.mine = (SideEffectBean) beanFactory.getBean("apartment");
|
||||
assertThat(mine.getCount()).isEqualTo(INITIAL_COUNT);
|
||||
assertEquals(INITIAL_COUNT, mine.getCount());
|
||||
mine.doWork();
|
||||
assertThat(mine.getCount()).isEqualTo((INITIAL_COUNT + 1));
|
||||
assertEquals(INITIAL_COUNT + 1, mine.getCount());
|
||||
}
|
||||
}
|
||||
Runner r = new Runner();
|
||||
@@ -127,17 +127,17 @@ public class ThreadLocalTargetSourceTests {
|
||||
t.start();
|
||||
t.join();
|
||||
|
||||
assertThat(r).isNotNull();
|
||||
assertNotNull(r);
|
||||
|
||||
// Check it didn't affect the other thread's copy
|
||||
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 3));
|
||||
assertEquals(INITIAL_COUNT + 3, apartment.getCount());
|
||||
|
||||
// When we use other thread's copy in this thread
|
||||
// it should behave like ours
|
||||
assertThat(r.mine.getCount()).isEqualTo((INITIAL_COUNT + 3));
|
||||
assertEquals(INITIAL_COUNT + 3, r.mine.getCount());
|
||||
|
||||
// Bound to two threads
|
||||
assertThat(((ThreadLocalTargetSourceStats) apartment).getObjectCount()).isEqualTo(2);
|
||||
assertEquals(2, ((ThreadLocalTargetSourceStats) apartment).getObjectCount());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -152,7 +152,12 @@ public class ThreadLocalTargetSourceTests {
|
||||
source.destroy();
|
||||
|
||||
// try second time
|
||||
source.getTarget(); // Should not throw NPE
|
||||
try {
|
||||
source.getTarget();
|
||||
}
|
||||
catch (NullPointerException ex) {
|
||||
fail("Should not throw NPE");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,7 +21,7 @@ import org.junit.Test;
|
||||
import org.springframework.tests.Assume;
|
||||
import org.springframework.tests.TestGroup;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
@@ -41,8 +41,8 @@ public class RefreshableTargetSourceTests {
|
||||
Thread.sleep(1);
|
||||
Object b = ts.getTarget();
|
||||
|
||||
assertThat(ts.getCallCount()).as("Should be one call to freshTarget to get initial target").isEqualTo(1);
|
||||
assertThat(b).as("Returned objects should be the same - no refresh should occur").isSameAs(a);
|
||||
assertEquals("Should be one call to freshTarget to get initial target", 1, ts.getCallCount());
|
||||
assertSame("Returned objects should be the same - no refresh should occur", a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,8 +57,8 @@ public class RefreshableTargetSourceTests {
|
||||
Thread.sleep(100);
|
||||
Object b = ts.getTarget();
|
||||
|
||||
assertThat(ts.getCallCount()).as("Should have called freshTarget twice").isEqualTo(2);
|
||||
assertThat(b).as("Should be different objects").isNotSameAs(a);
|
||||
assertEquals("Should have called freshTarget twice", 2, ts.getCallCount());
|
||||
assertNotSame("Should be different objects", a, b);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -72,8 +72,8 @@ public class RefreshableTargetSourceTests {
|
||||
Object a = ts.getTarget();
|
||||
Object b = ts.getTarget();
|
||||
|
||||
assertThat(ts.getCallCount()).as("Refresh target should only be called once").isEqualTo(1);
|
||||
assertThat(b).as("Objects should be the same - refresh check delay not elapsed").isSameAs(a);
|
||||
assertEquals("Refresh target should only be called once", 1, ts.getCallCount());
|
||||
assertSame("Objects should be the same - refresh check delay not elapsed", a, b);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -85,26 +85,26 @@ public class RefreshableTargetSourceTests {
|
||||
|
||||
Object a = ts.getTarget();
|
||||
Object b = ts.getTarget();
|
||||
assertThat(b).as("Objects should be same").isEqualTo(a);
|
||||
assertEquals("Objects should be same", a, b);
|
||||
|
||||
Thread.sleep(50);
|
||||
|
||||
Object c = ts.getTarget();
|
||||
assertThat(c).as("A and C should be same").isEqualTo(a);
|
||||
assertEquals("A and C should be same", a, c);
|
||||
|
||||
Thread.sleep(60);
|
||||
|
||||
Object d = ts.getTarget();
|
||||
assertThat(d).as("D should not be null").isNotNull();
|
||||
assertThat(a.equals(d)).as("A and D should not be equal").isFalse();
|
||||
assertNotNull("D should not be null", d);
|
||||
assertFalse("A and D should not be equal", a.equals(d));
|
||||
|
||||
Object e = ts.getTarget();
|
||||
assertThat(e).as("D and E should be equal").isEqualTo(d);
|
||||
assertEquals("D and E should be equal", d, e);
|
||||
|
||||
Thread.sleep(110);
|
||||
|
||||
Object f = ts.getTarget();
|
||||
assertThat(e.equals(f)).as("E and F should be different").isFalse();
|
||||
assertFalse("E and F should be different", e.equals(f));
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,19 +1,6 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
/**
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests.aop.advice;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
+5
-1
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,11 +21,15 @@ import org.springframework.aop.support.DelegatingIntroductionInterceptor;
|
||||
import org.springframework.tests.aop.interceptor.TimestampIntroductionInterceptor;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author Rod Johnson
|
||||
*/
|
||||
@SuppressWarnings("serial")
|
||||
public class TimestampIntroductionAdvisor extends DefaultIntroductionAdvisor {
|
||||
|
||||
/**
|
||||
* @param dii
|
||||
*/
|
||||
public TimestampIntroductionAdvisor() {
|
||||
super(new DelegatingIntroductionInterceptor(new TimestampIntroductionInterceptor()));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,7 @@
|
||||
<html>
|
||||
<body>
|
||||
<p>
|
||||
Spring's AspectJ-based aspects.
|
||||
</p>
|
||||
</body>
|
||||
</html>
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -20,7 +20,7 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Chris Beams
|
||||
@@ -33,7 +33,7 @@ public class XmlBeanConfigurerTests {
|
||||
"org/springframework/beans/factory/aspectj/beanConfigurerTests.xml")) {
|
||||
|
||||
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
|
||||
assertThat(myObject.getName()).isEqualTo("Rod");
|
||||
assertEquals("Rod", myObject.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Vendored
+13
-12
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.cache.aspectj;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.cache.Cache;
|
||||
@@ -24,7 +25,7 @@ import org.springframework.cache.config.CacheableService;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.GenericXmlApplicationContext;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Costin Leau
|
||||
@@ -41,7 +42,7 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
|
||||
public void testKeyStrategy() throws Exception {
|
||||
AnnotationCacheAspect aspect = ctx.getBean(
|
||||
"org.springframework.cache.config.internalCacheAspect", AnnotationCacheAspect.class);
|
||||
assertThat(aspect.getKeyGenerator()).isSameAs(ctx.getBean("keyGenerator"));
|
||||
Assert.assertSame(ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -54,21 +55,21 @@ public class AspectJCacheAnnotationTests extends AbstractCacheAnnotationTests {
|
||||
Cache primary = cm.getCache("primary");
|
||||
Cache secondary = cm.getCache("secondary");
|
||||
|
||||
assertThat(r2).isSameAs(r1);
|
||||
assertThat(primary.get(o1).get()).isSameAs(r1);
|
||||
assertThat(secondary.get(o1).get()).isSameAs(r1);
|
||||
assertSame(r1, r2);
|
||||
assertSame(r1, primary.get(o1).get());
|
||||
assertSame(r1, secondary.get(o1).get());
|
||||
|
||||
service.multiEvict(o1);
|
||||
assertThat(primary.get(o1)).isNull();
|
||||
assertThat(secondary.get(o1)).isNull();
|
||||
assertNull(primary.get(o1));
|
||||
assertNull(secondary.get(o1));
|
||||
|
||||
Object r3 = service.multiCache(o1);
|
||||
Object r4 = service.multiCache(o1);
|
||||
assertThat(r3).isNotSameAs(r1);
|
||||
assertThat(r4).isSameAs(r3);
|
||||
assertNotSame(r1, r3);
|
||||
assertSame(r3, r4);
|
||||
|
||||
assertThat(primary.get(o1).get()).isSameAs(r3);
|
||||
assertThat(secondary.get(o1).get()).isSameAs(r4);
|
||||
assertSame(r3, primary.get(o1).get());
|
||||
assertSame(r4, secondary.get(o1).get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
+14
-14
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -43,7 +43,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -69,14 +69,14 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
public void testKeyStrategy() {
|
||||
load(EnableCachingConfig.class);
|
||||
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
|
||||
assertThat(aspect.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator", KeyGenerator.class));
|
||||
assertSame(this.ctx.getBean("keyGenerator", KeyGenerator.class), aspect.getKeyGenerator());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCacheErrorHandler() {
|
||||
load(EnableCachingConfig.class);
|
||||
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
|
||||
assertThat(aspect.getErrorHandler()).isSameAs(this.ctx.getBean("errorHandler", CacheErrorHandler.class));
|
||||
assertSame(this.ctx.getBean("errorHandler", CacheErrorHandler.class), aspect.getErrorHandler());
|
||||
}
|
||||
|
||||
|
||||
@@ -93,7 +93,7 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
load(MultiCacheManagerConfig.class);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
assertThat(ex.getMessage().contains("bean of type CacheManager")).isTrue();
|
||||
assertTrue(ex.getMessage().contains("bean of type CacheManager"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -109,9 +109,8 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
}
|
||||
catch (BeanCreationException ex) {
|
||||
Throwable root = ex.getRootCause();
|
||||
boolean condition = root instanceof IllegalStateException;
|
||||
assertThat(condition).isTrue();
|
||||
assertThat(ex.getMessage().contains("implementations of CachingConfigurer")).isTrue();
|
||||
assertTrue(root instanceof IllegalStateException);
|
||||
assertTrue(ex.getMessage().contains("implementations of CachingConfigurer"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -121,7 +120,7 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
load(EmptyConfig.class);
|
||||
}
|
||||
catch (IllegalStateException ex) {
|
||||
assertThat(ex.getMessage().contains("no bean of type CacheManager")).isTrue();
|
||||
assertTrue(ex.getMessage().contains("no bean of type CacheManager"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,9 +129,10 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
public void emptyConfigSupport() {
|
||||
load(EmptyConfigSupportConfig.class);
|
||||
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
|
||||
assertThat(aspect.getCacheResolver()).isNotNull();
|
||||
assertThat(aspect.getCacheResolver().getClass()).isEqualTo(SimpleCacheResolver.class);
|
||||
assertThat(((SimpleCacheResolver) aspect.getCacheResolver()).getCacheManager()).isSameAs(this.ctx.getBean(CacheManager.class));
|
||||
assertNotNull(aspect.getCacheResolver());
|
||||
assertEquals(SimpleCacheResolver.class, aspect.getCacheResolver().getClass());
|
||||
assertSame(this.ctx.getBean(CacheManager.class),
|
||||
((SimpleCacheResolver) aspect.getCacheResolver()).getCacheManager());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,8 +140,8 @@ public class AspectJEnableCachingIsolatedTests {
|
||||
load(FullCachingConfig.class);
|
||||
|
||||
AnnotationCacheAspect aspect = this.ctx.getBean(AnnotationCacheAspect.class);
|
||||
assertThat(aspect.getCacheResolver()).isSameAs(this.ctx.getBean("cacheResolver"));
|
||||
assertThat(aspect.getKeyGenerator()).isSameAs(this.ctx.getBean("keyGenerator"));
|
||||
assertSame(this.ctx.getBean("cacheResolver"), aspect.getCacheResolver());
|
||||
assertSame(this.ctx.getBean("keyGenerator"), aspect.getKeyGenerator());
|
||||
}
|
||||
|
||||
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2017 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,7 +23,7 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.context.annotation.ImportResource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Tests that @EnableSpringConfigured properly registers an
|
||||
@@ -39,7 +39,7 @@ public class AnnotationBeanConfigurerTests {
|
||||
public void injection() {
|
||||
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class)) {
|
||||
ShouldBeConfiguredBySpring myObject = new ShouldBeConfiguredBySpring();
|
||||
assertThat(myObject.getName()).isEqualTo("Rod");
|
||||
assertEquals("Rod", myObject.getName());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+37
-29
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,9 @@ import org.springframework.tests.TestGroup;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
import org.springframework.util.concurrent.ListenableFuture;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.hamcrest.CoreMatchers.startsWith;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link AnnotationAsyncExecutionAspect}.
|
||||
@@ -69,9 +71,9 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
|
||||
obj.incrementAsync();
|
||||
executor.waitForCompletion();
|
||||
assertThat(obj.counter).isEqualTo(1);
|
||||
assertThat(executor.submitStartCounter).isEqualTo(1);
|
||||
assertThat(executor.submitCompleteCounter).isEqualTo(1);
|
||||
assertEquals(1, obj.counter);
|
||||
assertEquals(1, executor.submitStartCounter);
|
||||
assertEquals(1, executor.submitCompleteCounter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -79,19 +81,19 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
|
||||
Future<Integer> future = obj.incrementReturningAFuture();
|
||||
// No need to executor.waitForCompletion() as future.get() will have the same effect
|
||||
assertThat(future.get().intValue()).isEqualTo(5);
|
||||
assertThat(obj.counter).isEqualTo(1);
|
||||
assertThat(executor.submitStartCounter).isEqualTo(1);
|
||||
assertThat(executor.submitCompleteCounter).isEqualTo(1);
|
||||
assertEquals(5, future.get().intValue());
|
||||
assertEquals(1, obj.counter);
|
||||
assertEquals(1, executor.submitStartCounter);
|
||||
assertEquals(1, executor.submitCompleteCounter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void syncMethodGetsRoutedSynchronously() {
|
||||
ClassWithoutAsyncAnnotation obj = new ClassWithoutAsyncAnnotation();
|
||||
obj.increment();
|
||||
assertThat(obj.counter).isEqualTo(1);
|
||||
assertThat(executor.submitStartCounter).isEqualTo(0);
|
||||
assertThat(executor.submitCompleteCounter).isEqualTo(0);
|
||||
assertEquals(1, obj.counter);
|
||||
assertEquals(0, executor.submitStartCounter);
|
||||
assertEquals(0, executor.submitCompleteCounter);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -101,19 +103,19 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
|
||||
obj.increment();
|
||||
executor.waitForCompletion();
|
||||
assertThat(obj.counter).isEqualTo(1);
|
||||
assertThat(executor.submitStartCounter).isEqualTo(1);
|
||||
assertThat(executor.submitCompleteCounter).isEqualTo(1);
|
||||
assertEquals(1, obj.counter);
|
||||
assertEquals(1, executor.submitStartCounter);
|
||||
assertEquals(1, executor.submitCompleteCounter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void methodReturningFutureInAsyncClassGetsRoutedAsynchronouslyAndReturnsAFuture() throws InterruptedException, ExecutionException {
|
||||
ClassWithAsyncAnnotation obj = new ClassWithAsyncAnnotation();
|
||||
Future<Integer> future = obj.incrementReturningAFuture();
|
||||
assertThat(future.get().intValue()).isEqualTo(5);
|
||||
assertThat(obj.counter).isEqualTo(1);
|
||||
assertThat(executor.submitStartCounter).isEqualTo(1);
|
||||
assertThat(executor.submitCompleteCounter).isEqualTo(1);
|
||||
assertEquals(5, future.get().intValue());
|
||||
assertEquals(1, obj.counter);
|
||||
assertEquals(1, executor.submitStartCounter);
|
||||
assertEquals(1, executor.submitCompleteCounter);
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -136,14 +138,14 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
ClassWithQualifiedAsyncMethods obj = new ClassWithQualifiedAsyncMethods();
|
||||
|
||||
Future<Thread> defaultThread = obj.defaultWork();
|
||||
assertThat(defaultThread.get()).isNotEqualTo(Thread.currentThread());
|
||||
assertThat(defaultThread.get().getName()).doesNotStartWith("e1-");
|
||||
assertThat(defaultThread.get(), not(Thread.currentThread()));
|
||||
assertThat(defaultThread.get().getName(), not(startsWith("e1-")));
|
||||
|
||||
ListenableFuture<Thread> e1Thread = obj.e1Work();
|
||||
assertThat(e1Thread.get().getName()).startsWith("e1-");
|
||||
assertThat(e1Thread.get().getName(), startsWith("e1-"));
|
||||
|
||||
CompletableFuture<Thread> e1OtherThread = obj.e1OtherWork();
|
||||
assertThat(e1OtherThread.get().getName()).startsWith("e1-");
|
||||
assertThat(e1OtherThread.get().getName(), startsWith("e1-"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -152,7 +154,7 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler();
|
||||
AnnotationAsyncExecutionAspect.aspectOf().setExceptionHandler(exceptionHandler);
|
||||
try {
|
||||
assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
|
||||
assertFalse("Handler should not have been called", exceptionHandler.isCalled());
|
||||
ClassWithException obj = new ClassWithException();
|
||||
obj.failWithVoid();
|
||||
exceptionHandler.await(3000);
|
||||
@@ -169,14 +171,20 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
TestableAsyncUncaughtExceptionHandler exceptionHandler = new TestableAsyncUncaughtExceptionHandler(true);
|
||||
AnnotationAsyncExecutionAspect.aspectOf().setExceptionHandler(exceptionHandler);
|
||||
try {
|
||||
assertThat(exceptionHandler.isCalled()).as("Handler should not have been called").isFalse();
|
||||
assertFalse("Handler should not have been called", exceptionHandler.isCalled());
|
||||
ClassWithException obj = new ClassWithException();
|
||||
obj.failWithVoid();
|
||||
exceptionHandler.await(3000);
|
||||
exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
|
||||
try {
|
||||
obj.failWithVoid();
|
||||
exceptionHandler.await(3000);
|
||||
exceptionHandler.assertCalledWith(m, UnsupportedOperationException.class);
|
||||
}
|
||||
catch (Exception ex) {
|
||||
fail("No unexpected exception should have been received but got " + ex.getMessage());
|
||||
}
|
||||
}
|
||||
finally {
|
||||
AnnotationAsyncExecutionAspect.aspectOf().setExceptionHandler(defaultExceptionHandler);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -204,7 +212,7 @@ public class AnnotationAsyncExecutionAspectTests {
|
||||
wait(WAIT_TIME);
|
||||
}
|
||||
catch (InterruptedException ex) {
|
||||
throw new AssertionError("Didn't finish the async job in " + WAIT_TIME + " milliseconds");
|
||||
fail("Didn't finish the async job in " + WAIT_TIME + " milliseconds");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-5
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -27,7 +27,7 @@ import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.scheduling.config.TaskManagementConfigUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Stephane Nicoll
|
||||
@@ -51,7 +51,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||
|
||||
@Test
|
||||
public void asyncAspectRegistered() {
|
||||
assertThat(context.containsBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME)).isTrue();
|
||||
assertTrue(context.containsBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -59,7 +59,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||
public void asyncPostProcessorExecutorReference() {
|
||||
Object executor = context.getBean("testExecutor");
|
||||
Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
|
||||
assertThat(((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("defaultExecutor")).get()).isSameAs(executor);
|
||||
assertSame(executor, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("defaultExecutor")).get());
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -67,7 +67,7 @@ public class AnnotationDrivenBeanDefinitionParserTests {
|
||||
public void asyncPostProcessorExceptionHandlerReference() {
|
||||
Object exceptionHandler = context.getBean("testExceptionHandler");
|
||||
Object aspect = context.getBean(TaskManagementConfigUtils.ASYNC_EXECUTION_ASPECT_BEAN_NAME);
|
||||
assertThat(((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("exceptionHandler")).get()).isSameAs(exceptionHandler);
|
||||
assertSame(exceptionHandler, ((Supplier) new DirectFieldAccessor(aspect).getPropertyValue("exceptionHandler")).get());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user