Skip to content

Commit f79562f

Browse files
committed
Introduce tests for generics & @nested test classes
1 parent a6c45f0 commit f79562f

File tree

2 files changed

+71
-5
lines changed

2 files changed

+71
-5
lines changed

spring-test/src/test/java/org/springframework/test/context/junit/jupiter/generics/GenericComicCharactersTestCase.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2017 the original author or authors.
2+
* Copyright 2002-2018 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.
@@ -19,12 +19,11 @@
1919
import java.util.List;
2020

2121
import org.junit.jupiter.api.Test;
22-
import org.junit.jupiter.api.extension.ExtendWith;
2322

2423
import org.springframework.beans.factory.annotation.Autowired;
25-
import org.springframework.test.context.ContextConfiguration;
2624
import org.springframework.test.context.junit.SpringJUnitJupiterTestSuite;
2725
import org.springframework.test.context.junit.jupiter.SpringExtension;
26+
import org.springframework.test.context.junit.jupiter.SpringJUnitConfig;
2827
import org.springframework.test.context.junit.jupiter.TestConfig;
2928
import org.springframework.test.context.junit.jupiter.comics.Character;
3029

@@ -41,8 +40,7 @@
4140
* @author Sam Brannen
4241
* @since 5.0
4342
*/
44-
@ExtendWith(SpringExtension.class)
45-
@ContextConfiguration(classes = TestConfig.class)
43+
@SpringJUnitConfig(TestConfig.class)
4644
abstract class GenericComicCharactersTestCase<T extends Character> {
4745

4846
@Autowired
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
/*
2+
* Copyright 2002-2018 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.test.context.junit.jupiter.generics;
18+
19+
import org.junit.jupiter.api.Nested;
20+
21+
import org.springframework.test.context.junit.SpringJUnitJupiterTestSuite;
22+
import org.springframework.test.context.junit.jupiter.SpringExtension;
23+
import org.springframework.test.context.junit.jupiter.comics.Cat;
24+
import org.springframework.test.context.junit.jupiter.comics.Dog;
25+
26+
/**
27+
* Integration tests that verify support for Java generics combined with {@code @Nested}
28+
* test classes when used with the Spring TestContext Framework and the
29+
* {@link SpringExtension}.
30+
*
31+
* <p>
32+
* To run these tests in an IDE that does not have built-in support for the JUnit
33+
* Platform, simply run {@link SpringJUnitJupiterTestSuite} as a JUnit 4 test.
34+
*
35+
* @author Sam Brannen
36+
* @since 5.0.5
37+
*/
38+
class GenericsAndNestedTestsTestCase {
39+
40+
@Nested
41+
class CatTestCase extends GenericComicCharactersTestCase<Cat> {
42+
43+
@Override
44+
int getExpectedNumCharacters() {
45+
return 2;
46+
}
47+
48+
@Override
49+
String getExpectedName() {
50+
return "Catbert";
51+
}
52+
}
53+
54+
@Nested
55+
class DogTestCase extends GenericComicCharactersTestCase<Dog> {
56+
57+
@Override
58+
int getExpectedNumCharacters() {
59+
return 1;
60+
}
61+
62+
@Override
63+
String getExpectedName() {
64+
return "Dogbert";
65+
}
66+
}
67+
68+
}

0 commit comments

Comments
 (0)