Skip to content

Commit b005008

Browse files
eddumelendezwilkinsona
authored andcommitted
Add TestNG support in TestTypeExcludeFilter
See gh-7630
1 parent 4d95134 commit b005008

File tree

5 files changed

+59
-3
lines changed

5 files changed

+59
-3
lines changed

spring-boot-project/spring-boot-dependencies/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@
182182
<statsd-client.version>3.1.0</statsd-client.version>
183183
<sun-mail.version>${javax-mail.version}</sun-mail.version>
184184
<saaj-impl.version>1.5.0</saaj-impl.version>
185+
<testng.version>6.10</testng.version>
185186
<thymeleaf.version>3.0.11.RELEASE</thymeleaf.version>
186187
<thymeleaf-extras-springsecurity.version>3.0.4.RELEASE</thymeleaf-extras-springsecurity.version>
187188
<thymeleaf-layout-dialect.version>2.3.0</thymeleaf-layout-dialect.version>
@@ -2965,6 +2966,11 @@
29652966
<artifactId>nio-multipart-parser</artifactId>
29662967
<version>${nio-multipart-parser.version}</version>
29672968
</dependency>
2969+
<dependency>
2970+
<groupId>org.testng</groupId>
2971+
<artifactId>testng</artifactId>
2972+
<version>${testng.version}</version>
2973+
</dependency>
29682974
<dependency>
29692975
<groupId>org.thymeleaf</groupId>
29702976
<artifactId>thymeleaf</artifactId>

spring-boot-project/spring-boot-test/pom.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,11 @@
192192
<artifactId>mockito-kotlin</artifactId>
193193
<scope>test</scope>
194194
</dependency>
195+
<dependency>
196+
<groupId>org.testng</groupId>
197+
<artifactId>testng</artifactId>
198+
<scope>test</scope>
199+
</dependency>
195200
</dependencies>
196201
<build>
197202
<plugins>

spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilter.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2018 the original author or authors.
2+
* Copyright 2012-2019 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,10 +33,11 @@
3333
class TestTypeExcludeFilter extends TypeExcludeFilter {
3434

3535
private static final String[] CLASS_ANNOTATIONS = { "org.junit.runner.RunWith",
36-
"org.junit.jupiter.api.extension.ExtendWith" };
36+
"org.junit.jupiter.api.extension.ExtendWith", "org.testng.annotations.Test" };
3737

3838
private static final String[] METHOD_ANNOTATIONS = { "org.junit.Test",
39-
"org.junit.platform.commons.annotation.Testable" };
39+
"org.junit.platform.commons.annotation.Testable",
40+
"org.testng.annotations.Test" };
4041

4142
@Override
4243
public boolean match(MetadataReader metadataReader,
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2016 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.test.context.filter;
18+
19+
import org.testng.annotations.Test;
20+
21+
import org.springframework.context.annotation.Configuration;
22+
23+
/**
24+
* Abstract test with nest {@code @Configuration} and {@code @Test} used by
25+
* {@link TestTypeExcludeFilter}.
26+
*
27+
* @author Eddú Meléndez
28+
*/
29+
@Test
30+
public abstract class AbstractTestNG {
31+
32+
@Configuration
33+
static class Config {
34+
35+
}
36+
37+
}

spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,13 @@ public void doesNotMatchRegularConfiguration() throws Exception {
9898
this.metadataReaderFactory)).isFalse();
9999
}
100100

101+
@Test
102+
public void matchesNestedConfigurationClassWithoutTestngAnnotation()
103+
throws Exception {
104+
assertThat(this.filter.match(getMetadataReader(AbstractTestNG.Config.class),
105+
this.metadataReaderFactory)).isTrue();
106+
}
107+
101108
private MetadataReader getMetadataReader(Class<?> source) throws IOException {
102109
return this.metadataReaderFactory.getMetadataReader(source.getName());
103110
}

0 commit comments

Comments
 (0)