Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Sign in / Register
Toggle navigation
S
spring-boot
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
DEMO
spring-boot
Commits
45d672f5
Commit
45d672f5
authored
Nov 30, 2016
by
Andy Wilkinson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Ignore Spock annotations when creating test context cache key
Closes gh-7524
parent
c51d836a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
90 additions
and
19 deletions
+90
-19
pom.xml
spring-boot-test/pom.xml
+14
-10
ImportsContextCustomizer.java
...framework/boot/test/context/ImportsContextCustomizer.java
+58
-9
ImportsContextCustomizerTests.java
...work/boot/test/context/ImportsContextCustomizerTests.java
+18
-0
No files found.
spring-boot-test/pom.xml
View file @
45d672f5
...
@@ -112,21 +112,11 @@
...
@@ -112,21 +112,11 @@
<optional>
true
</optional>
<optional>
true
</optional>
</dependency>
</dependency>
<!-- Test -->
<!-- Test -->
<dependency>
<groupId>
org.jetbrains.kotlin
</groupId>
<artifactId>
kotlin-runtime
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.apache.tomcat.embed
</groupId>
<groupId>
org.apache.tomcat.embed
</groupId>
<artifactId>
tomcat-embed-core
</artifactId>
<artifactId>
tomcat-embed-core
</artifactId>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<dependency>
<groupId>
org.codehaus.groovy
</groupId>
<groupId>
org.codehaus.groovy
</groupId>
<artifactId>
groovy
</artifactId>
<artifactId>
groovy
</artifactId>
...
@@ -138,6 +128,20 @@
...
@@ -138,6 +128,20 @@
<optional>
true
</optional>
<optional>
true
</optional>
<scope>
test
</scope>
<scope>
test
</scope>
</dependency>
</dependency>
<dependency>
<groupId>
org.jetbrains.kotlin
</groupId>
<artifactId>
kotlin-runtime
</artifactId>
<scope>
test
</scope>
</dependency>
<dependency>
<groupId>
org.spockframework
</groupId>
<artifactId>
spock-core
</artifactId>
</dependency>
<dependency>
<groupId>
org.springframework
</groupId>
<artifactId>
spring-webmvc
</artifactId>
<scope>
test
</scope>
</dependency>
</dependencies>
</dependencies>
<build>
<build>
<plugins>
<plugins>
...
...
spring-boot-test/src/main/java/org/springframework/boot/test/context/ImportsContextCustomizer.java
View file @
45d672f5
...
@@ -214,6 +214,16 @@ class ImportsContextCustomizer implements ContextCustomizer {
...
@@ -214,6 +214,16 @@ class ImportsContextCustomizer implements ContextCustomizer {
*/
*/
static
class
ContextCustomizerKey
{
static
class
ContextCustomizerKey
{
private
static
final
Set
<
AnnotationFilter
>
ANNOTATION_FILTERS
;
static
{
Set
<
AnnotationFilter
>
filters
=
new
HashSet
<
AnnotationFilter
>();
filters
.
add
(
new
JavaLangAnnotationFilter
());
filters
.
add
(
new
KotlinAnnotationFilter
());
filters
.
add
(
new
SpockAnnotationFilter
());
ANNOTATION_FILTERS
=
Collections
.
unmodifiableSet
(
filters
);
}
private
final
Set
<
Annotation
>
annotations
;
private
final
Set
<
Annotation
>
annotations
;
ContextCustomizerKey
(
Class
<?>
testClass
)
{
ContextCustomizerKey
(
Class
<?>
testClass
)
{
...
@@ -239,8 +249,7 @@ class ImportsContextCustomizer implements ContextCustomizer {
...
@@ -239,8 +249,7 @@ class ImportsContextCustomizer implements ContextCustomizer {
private
void
collectElementAnnotations
(
AnnotatedElement
element
,
private
void
collectElementAnnotations
(
AnnotatedElement
element
,
Set
<
Annotation
>
annotations
,
Set
<
Class
<?>>
seen
)
{
Set
<
Annotation
>
annotations
,
Set
<
Class
<?>>
seen
)
{
for
(
Annotation
annotation
:
element
.
getDeclaredAnnotations
())
{
for
(
Annotation
annotation
:
element
.
getDeclaredAnnotations
())
{
if
(!
AnnotationUtils
.
isInJavaLangAnnotationPackage
(
annotation
)
if
(!
isIgnoredAnnotation
(
annotation
))
{
&&
!
isIgnoredKotlinAnnotation
(
annotation
))
{
annotations
.
add
(
annotation
);
annotations
.
add
(
annotation
);
collectClassAnnotations
(
annotation
.
annotationType
(),
annotations
,
collectClassAnnotations
(
annotation
.
annotationType
(),
annotations
,
seen
);
seen
);
...
@@ -248,13 +257,13 @@ class ImportsContextCustomizer implements ContextCustomizer {
...
@@ -248,13 +257,13 @@ class ImportsContextCustomizer implements ContextCustomizer {
}
}
}
}
private
boolean
isIgnored
Kotlin
Annotation
(
Annotation
annotation
)
{
private
boolean
isIgnoredAnnotation
(
Annotation
annotation
)
{
return
"kotlin.Metadata"
.
equals
(
annotation
.
annotationType
().
getName
())
for
(
AnnotationFilter
annotationFilter
:
ANNOTATION_FILTERS
)
{
||
isInKotlinAnnotationPackage
(
annotation
);
if
(
annotationFilter
.
isIgnored
(
annotation
))
{
}
return
true
;
}
private
boolean
isInKotlinAnnotationPackage
(
Annotation
annotation
)
{
}
return
annotation
.
annotationType
().
getName
().
startsWith
(
"kotlin.annotation."
)
;
return
false
;
}
}
@Override
@Override
...
@@ -268,6 +277,46 @@ class ImportsContextCustomizer implements ContextCustomizer {
...
@@ -268,6 +277,46 @@ class ImportsContextCustomizer implements ContextCustomizer {
&&
this
.
annotations
.
equals
(((
ContextCustomizerKey
)
obj
).
annotations
));
&&
this
.
annotations
.
equals
(((
ContextCustomizerKey
)
obj
).
annotations
));
}
}
private
interface
AnnotationFilter
{
boolean
isIgnored
(
Annotation
annotation
);
}
private
static
final
class
JavaLangAnnotationFilter
implements
AnnotationFilter
{
@Override
public
boolean
isIgnored
(
Annotation
annotation
)
{
return
AnnotationUtils
.
isInJavaLangAnnotationPackage
(
annotation
);
}
}
private
static
final
class
KotlinAnnotationFilter
implements
AnnotationFilter
{
@Override
public
boolean
isIgnored
(
Annotation
annotation
)
{
return
"kotlin.Metadata"
.
equals
(
annotation
.
annotationType
().
getName
())
||
isInKotlinAnnotationPackage
(
annotation
);
}
private
boolean
isInKotlinAnnotationPackage
(
Annotation
annotation
)
{
return
annotation
.
annotationType
().
getName
()
.
startsWith
(
"kotlin.annotation."
);
}
}
private
static
final
class
SpockAnnotationFilter
implements
AnnotationFilter
{
@Override
public
boolean
isIgnored
(
Annotation
annotation
)
{
return
annotation
.
annotationType
().
getName
()
.
startsWith
(
"org.spockframework."
);
}
}
}
}
}
}
spring-boot-test/src/test/java/org/springframework/boot/test/context/ImportsContextCustomizerTests.java
View file @
45d672f5
...
@@ -18,6 +18,7 @@ package org.springframework.boot.test.context;
...
@@ -18,6 +18,7 @@ package org.springframework.boot.test.context;
import
kotlin.Metadata
;
import
kotlin.Metadata
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.spockframework.runtime.model.SpecMetadata
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -35,6 +36,13 @@ public class ImportsContextCustomizerTests {
...
@@ -35,6 +36,13 @@ public class ImportsContextCustomizerTests {
SecondKotlinAnnotatedTestClass
.
class
));
SecondKotlinAnnotatedTestClass
.
class
));
}
}
@Test
public
void
customizersForTestClassesWithDifferentSpockMetadataAreEqual
()
{
assertThat
(
new
ImportsContextCustomizer
(
FirstSpockAnnotatedTestClass
.
class
))
.
isEqualTo
(
new
ImportsContextCustomizer
(
SecondSpockAnnotatedTestClass
.
class
));
}
@Metadata
(
d2
=
"foo"
)
@Metadata
(
d2
=
"foo"
)
static
class
FirstKotlinAnnotatedTestClass
{
static
class
FirstKotlinAnnotatedTestClass
{
...
@@ -45,4 +53,14 @@ public class ImportsContextCustomizerTests {
...
@@ -45,4 +53,14 @@ public class ImportsContextCustomizerTests {
}
}
@SpecMetadata
(
filename
=
"foo"
,
line
=
10
)
static
class
FirstSpockAnnotatedTestClass
{
}
@SpecMetadata
(
filename
=
"bar"
,
line
=
10
)
static
class
SecondSpockAnnotatedTestClass
{
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment