@@ -92,32 +92,41 @@ open class CgTestClassConstructor(val context: CgContext) :
9292 )
9393 )
9494 }
95-
96- for (testSet in testClassModel.methodTestSets) {
97- updateCurrentExecutable(testSet.executableId)
98- val currentMethodUnderTestRegions = constructTestSet(testSet) ? : continue
99- val executableUnderTestCluster = CgMethodsCluster (
100- " Test suites for executable $currentExecutable " ,
101- currentMethodUnderTestRegions
95+ if (testClassModel.nestedClasses.isNotEmpty()) {
96+ val newTestClassModel = TestClassModel ( testClassModel.classUnderTest, testClassModel. methodTestSets, emptyList())
97+ nestedClassRegions + = CgRealNestedClassesRegion (
98+ " Tests for ${classUnderTest.simpleName} " ,
99+ listOf (
100+ withNestedClassScope(newTestClassModel) { constructTestClass(newTestClassModel) }
101+ )
102102 )
103- methodRegions + = executableUnderTestCluster
104- }
105-
106- val currentTestClassDataProviderMethods = currentTestClassContext.cgDataProviderMethods
107- if (currentTestClassDataProviderMethods.isNotEmpty()) {
108- staticDeclarationRegions + =
109- CgStaticsRegion (
110- " Data provider methods for parametrized tests" ,
111- currentTestClassDataProviderMethods,
103+ } else {
104+ for (testSet in testClassModel.methodTestSets) {
105+ updateCurrentExecutable(testSet.executableId)
106+ val currentMethodUnderTestRegions = constructTestSet(testSet) ? : continue
107+ val executableUnderTestCluster = CgMethodsCluster (
108+ " Test suites for executable $currentExecutable " ,
109+ currentMethodUnderTestRegions
112110 )
113- }
111+ methodRegions + = executableUnderTestCluster
112+ }
113+
114+ val currentTestClassDataProviderMethods = currentTestClassContext.cgDataProviderMethods
115+ if (currentTestClassDataProviderMethods.isNotEmpty()) {
116+ staticDeclarationRegions + =
117+ CgStaticsRegion (
118+ " Data provider methods for parametrized tests" ,
119+ currentTestClassDataProviderMethods,
120+ )
121+ }
114122
115- if (currentTestClass == outerMostTestClass) {
116- val utilEntities = collectUtilEntities()
117- // If utilMethodProvider is TestClassUtilMethodProvider, then util entities should be declared
118- // in the test class. Otherwise, util entities will be located elsewhere (e.g. another class).
119- if (utilMethodProvider is TestClassUtilMethodProvider && utilEntities.isNotEmpty()) {
120- staticDeclarationRegions + = CgStaticsRegion (" Util methods" , utilEntities)
123+ if (currentTestClass == outerMostTestClass) {
124+ val utilEntities = collectUtilEntities()
125+ // If utilMethodProvider is TestClassUtilMethodProvider, then util entities should be declared
126+ // in the test class. Otherwise, util entities will be located elsewhere (e.g. another class).
127+ if (utilMethodProvider is TestClassUtilMethodProvider && utilEntities.isNotEmpty()) {
128+ staticDeclarationRegions + = CgStaticsRegion (" Util methods" , utilEntities)
129+ }
121130 }
122131 }
123132 }
0 commit comments