From b005008cacf8c6f71900b3d5537699577672204b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edd=C3=BA=20Mel=C3=A9ndez?= Date: Mon, 12 Dec 2016 19:30:01 -0500 Subject: [PATCH 1/2] Add TestNG support in TestTypeExcludeFilter See gh-7630 --- .../spring-boot-dependencies/pom.xml | 6 +++ spring-boot-project/spring-boot-test/pom.xml | 5 +++ .../context/filter/TestTypeExcludeFilter.java | 7 ++-- .../test/context/filter/AbstractTestNG.java | 37 +++++++++++++++++++ .../filter/TestTypeExcludeFilterTests.java | 7 ++++ 5 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index 7026be1e776..eee384fc381 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -182,6 +182,7 @@ 3.1.0 ${javax-mail.version} 1.5.0 + 6.10 3.0.11.RELEASE 3.0.4.RELEASE 2.3.0 @@ -2965,6 +2966,11 @@ nio-multipart-parser ${nio-multipart-parser.version} + + org.testng + testng + ${testng.version} + org.thymeleaf thymeleaf diff --git a/spring-boot-project/spring-boot-test/pom.xml b/spring-boot-project/spring-boot-test/pom.xml index 0c490191287..1e25028b498 100644 --- a/spring-boot-project/spring-boot-test/pom.xml +++ b/spring-boot-project/spring-boot-test/pom.xml @@ -192,6 +192,11 @@ mockito-kotlin test + + org.testng + testng + test + diff --git a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilter.java b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilter.java index 9747d041d33..4f1efe67b5a 100644 --- a/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilter.java +++ b/spring-boot-project/spring-boot-test/src/main/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilter.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-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. @@ -33,10 +33,11 @@ import org.springframework.core.type.classreading.MetadataReaderFactory; class TestTypeExcludeFilter extends TypeExcludeFilter { private static final String[] CLASS_ANNOTATIONS = { "org.junit.runner.RunWith", - "org.junit.jupiter.api.extension.ExtendWith" }; + "org.junit.jupiter.api.extension.ExtendWith", "org.testng.annotations.Test" }; private static final String[] METHOD_ANNOTATIONS = { "org.junit.Test", - "org.junit.platform.commons.annotation.Testable" }; + "org.junit.platform.commons.annotation.Testable", + "org.testng.annotations.Test" }; @Override public boolean match(MetadataReader metadataReader, diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java new file mode 100644 index 00000000000..7349825ae43 --- /dev/null +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java @@ -0,0 +1,37 @@ +/* + * Copyright 2012-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. + * 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. + */ + +package org.springframework.boot.test.context.filter; + +import org.testng.annotations.Test; + +import org.springframework.context.annotation.Configuration; + +/** + * Abstract test with nest {@code @Configuration} and {@code @Test} used by + * {@link TestTypeExcludeFilter}. + * + * @author Eddú Meléndez + */ +@Test +public abstract class AbstractTestNG { + + @Configuration + static class Config { + + } + +} diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java index 18fc4c0fba0..ba66b544f2b 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java @@ -98,6 +98,13 @@ public class TestTypeExcludeFilterTests { this.metadataReaderFactory)).isFalse(); } + @Test + public void matchesNestedConfigurationClassWithoutTestngAnnotation() + throws Exception { + assertThat(this.filter.match(getMetadataReader(AbstractTestNG.Config.class), + this.metadataReaderFactory)).isTrue(); + } + private MetadataReader getMetadataReader(Class source) throws IOException { return this.metadataReaderFactory.getMetadataReader(source.getName()); } From c04eba7ebc4e7374c3ec53e29df32f17498c107c Mon Sep 17 00:00:00 2001 From: Andy Wilkinson Date: Tue, 12 Feb 2019 15:26:04 +0000 Subject: [PATCH 2/2] Polish "Add TestNG support in TestTypeExcludeFilter" See gh-7630 --- spring-boot-project/spring-boot-dependencies/pom.xml | 6 ------ spring-boot-project/spring-boot-parent/pom.xml | 6 ++++++ ...ctTestNG.java => AbstractTestNgTestWithConfig.java} | 10 ++-------- .../context/filter/TestTypeExcludeFilterTests.java | 7 ++++--- 4 files changed, 12 insertions(+), 17 deletions(-) rename spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/{AbstractTestNG.java => AbstractTestNgTestWithConfig.java} (76%) diff --git a/spring-boot-project/spring-boot-dependencies/pom.xml b/spring-boot-project/spring-boot-dependencies/pom.xml index eee384fc381..7026be1e776 100644 --- a/spring-boot-project/spring-boot-dependencies/pom.xml +++ b/spring-boot-project/spring-boot-dependencies/pom.xml @@ -182,7 +182,6 @@ 3.1.0 ${javax-mail.version} 1.5.0 - 6.10 3.0.11.RELEASE 3.0.4.RELEASE 2.3.0 @@ -2966,11 +2965,6 @@ nio-multipart-parser ${nio-multipart-parser.version} - - org.testng - testng - ${testng.version} - org.thymeleaf thymeleaf diff --git a/spring-boot-project/spring-boot-parent/pom.xml b/spring-boot-project/spring-boot-parent/pom.xml index 82bcf95c601..bff0ad0b463 100644 --- a/spring-boot-project/spring-boot-parent/pom.xml +++ b/spring-boot-project/spring-boot-parent/pom.xml @@ -27,6 +27,7 @@ 1.1.1 1.0-groovy-2.4 1.10.6 + 6.14.3 1.0.6.RELEASE 0.1.0.BUILD-SNAPSHOT @@ -246,6 +247,11 @@ import pom + + org.testng + testng + ${testng.version} + org.zeroturnaround zt-zip diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNgTestWithConfig.java similarity index 76% rename from spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java rename to spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNgTestWithConfig.java index 7349825ae43..b11d0b739cd 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNG.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/AbstractTestNgTestWithConfig.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2016 the original author or authors. + * Copyright 2012-2019 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,14 +20,8 @@ import org.testng.annotations.Test; import org.springframework.context.annotation.Configuration; -/** - * Abstract test with nest {@code @Configuration} and {@code @Test} used by - * {@link TestTypeExcludeFilter}. - * - * @author Eddú Meléndez - */ @Test -public abstract class AbstractTestNG { +public abstract class AbstractTestNgTestWithConfig { @Configuration static class Config { diff --git a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java index ba66b544f2b..400d931830b 100644 --- a/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java +++ b/spring-boot-project/spring-boot-test/src/test/java/org/springframework/boot/test/context/filter/TestTypeExcludeFilterTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2012-2018 the original author or authors. + * Copyright 2012-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. @@ -99,9 +99,10 @@ public class TestTypeExcludeFilterTests { } @Test - public void matchesNestedConfigurationClassWithoutTestngAnnotation() + public void matchesNestedConfigurationClassWithoutTestNgAnnotation() throws Exception { - assertThat(this.filter.match(getMetadataReader(AbstractTestNG.Config.class), + assertThat(this.filter.match( + getMetadataReader(AbstractTestNgTestWithConfig.Config.class), this.metadataReaderFactory)).isTrue(); }