Skip to content

Commit cb57bea

Browse files
committed
Eliminate multiple top-level classes in a single file
Signed-off-by: Yanming Zhou <zhouyanming@gmail.com>
1 parent 99b991b commit cb57bea

5 files changed

Lines changed: 78 additions & 81 deletions

File tree

spring-context/src/test/java/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests.java

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*
4141
* @author Ramnivas Laddad
4242
* @author Chris Beams
43+
* @author Yanming Zhou
4344
*/
4445
class AfterReturningGenericTypeMatchingTests {
4546

@@ -107,77 +108,74 @@ void returnTypeLowerBoundMatching() {
107108
assertThat(counterAspect.getTestBeanInvocationsCount).isEqualTo(0);
108109
}
109110

110-
}
111-
111+
static class GenericReturnTypeVariationClass {
112112

113-
class GenericReturnTypeVariationClass {
113+
public Collection<String> getStrings() {
114+
return new ArrayList<>();
115+
}
114116

115-
public Collection<String> getStrings() {
116-
return new ArrayList<>();
117-
}
117+
public Collection<Integer> getIntegers() {
118+
return new ArrayList<>();
119+
}
118120

119-
public Collection<Integer> getIntegers() {
120-
return new ArrayList<>();
121-
}
121+
public Collection<TestBean> getTestBeans() {
122+
return new ArrayList<>();
123+
}
122124

123-
public Collection<TestBean> getTestBeans() {
124-
return new ArrayList<>();
125+
public Collection<Employee> getEmployees() {
126+
return new ArrayList<>();
127+
}
125128
}
126129

127-
public Collection<Employee> getEmployees() {
128-
return new ArrayList<>();
129-
}
130-
}
131-
130+
@Aspect
131+
static class CounterAspect {
132132

133-
@Aspect
134-
class CounterAspect {
133+
int getRawsInvocationsCount;
135134

136-
int getRawsInvocationsCount;
135+
int getStringsInvocationsCount;
137136

138-
int getStringsInvocationsCount;
137+
int getIntegersInvocationsCount;
139138

140-
int getIntegersInvocationsCount;
139+
int getNumbersInvocationsCount;
141140

142-
int getNumbersInvocationsCount;
141+
int getTestBeanInvocationsCount;
143142

144-
int getTestBeanInvocationsCount;
143+
@Pointcut("execution(* org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests.GenericReturnTypeVariationClass.*(..))")
144+
public void anyTestMethod() {
145+
}
145146

146-
@Pointcut("execution(* org.springframework.aop.aspectj.generic.GenericReturnTypeVariationClass.*(..))")
147-
public void anyTestMethod() {
148-
}
147+
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
148+
public void incrementGetRawsInvocationsCount(Collection<?> ret) {
149+
getRawsInvocationsCount++;
150+
}
149151

150-
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
151-
public void incrementGetRawsInvocationsCount(Collection<?> ret) {
152-
getRawsInvocationsCount++;
153-
}
152+
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
153+
public void incrementGetStringsInvocationsCount(Collection<String> ret) {
154+
getStringsInvocationsCount++;
155+
}
154156

155-
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
156-
public void incrementGetStringsInvocationsCount(Collection<String> ret) {
157-
getStringsInvocationsCount++;
158-
}
157+
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
158+
public void incrementGetIntegersInvocationsCount(Collection<Integer> ret) {
159+
getIntegersInvocationsCount++;
160+
}
159161

160-
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
161-
public void incrementGetIntegersInvocationsCount(Collection<Integer> ret) {
162-
getIntegersInvocationsCount++;
163-
}
162+
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
163+
public void incrementGetNumbersInvocationsCount(Collection<? extends Number> ret) {
164+
getNumbersInvocationsCount++;
165+
}
164166

165-
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
166-
public void incrementGetNumbersInvocationsCount(Collection<? extends Number> ret) {
167-
getNumbersInvocationsCount++;
168-
}
167+
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
168+
public void incrementTestBeanInvocationsCount(Collection<? super TestBean> ret) {
169+
getTestBeanInvocationsCount++;
170+
}
169171

170-
@AfterReturning(pointcut = "anyTestMethod()", returning = "ret")
171-
public void incrementTestBeanInvocationsCount(Collection<? super TestBean> ret) {
172-
getTestBeanInvocationsCount++;
172+
public void reset() {
173+
getRawsInvocationsCount = 0;
174+
getStringsInvocationsCount = 0;
175+
getIntegersInvocationsCount = 0;
176+
getNumbersInvocationsCount = 0;
177+
getTestBeanInvocationsCount = 0;
178+
}
173179
}
174180

175-
public void reset() {
176-
getRawsInvocationsCount = 0;
177-
getStringsInvocationsCount = 0;
178-
getIntegersInvocationsCount = 0;
179-
getNumbersInvocationsCount = 0;
180-
getTestBeanInvocationsCount = 0;
181-
}
182181
}
183-

spring-context/src/test/java/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests.java

Lines changed: 21 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
*
4141
* @author Ramnivas Laddad
4242
* @author Chris Beams
43+
* @author Yanming Zhou
4344
*/
4445
class GenericBridgeMethodMatchingTests {
4546

@@ -79,41 +80,39 @@ void genericBaseInterfaceMethodThroughInterface() {
7980
assertThat(counterAspect.count).isEqualTo(1);
8081
}
8182

82-
}
83+
interface BaseInterface<T> {
8384

85+
void genericBaseInterfaceMethod(T t);
86+
}
8487

85-
interface BaseInterface<T> {
8688

87-
void genericBaseInterfaceMethod(T t);
88-
}
89+
interface DerivedInterface<T> extends BaseInterface<T> {
8990

91+
void genericDerivedInterfaceMethod(T t);
92+
}
9093

91-
interface DerivedInterface<T> extends BaseInterface<T> {
9294

93-
void genericDerivedInterfaceMethod(T t);
94-
}
95+
static class DerivedStringParameterizedClass implements DerivedInterface<String> {
9596

97+
@Override
98+
public void genericDerivedInterfaceMethod(String t) {
99+
}
96100

97-
class DerivedStringParameterizedClass implements DerivedInterface<String> {
98-
99-
@Override
100-
public void genericDerivedInterfaceMethod(String t) {
101+
@Override
102+
public void genericBaseInterfaceMethod(String t) {
103+
}
101104
}
102105

103-
@Override
104-
public void genericBaseInterfaceMethod(String t) {
105-
}
106-
}
106+
@Aspect
107+
static class GenericCounterAspect {
107108

108-
@Aspect
109-
class GenericCounterAspect {
109+
public int count;
110110

111-
public int count;
111+
@Before("execution(* *..BaseInterface+.*(..))")
112+
public void increment() {
113+
count++;
114+
}
112115

113-
@Before("execution(* *..BaseInterface+.*(..))")
114-
public void increment() {
115-
count++;
116116
}
117117

118118
}
119-

spring-context/src/test/resources/org/springframework/aop/aspectj/generic/AfterReturningGenericTypeMatchingTests-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<aop:aspectj-autoproxy/>
99

10-
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.CounterAspect"/>
10+
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests$CounterAspect"/>
1111

12-
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericReturnTypeVariationClass"/>
12+
<bean id="testBean" class="org.springframework.aop.aspectj.generic.AfterReturningGenericTypeMatchingTests$GenericReturnTypeVariationClass"/>
1313

1414
</beans>

spring-context/src/test/resources/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingClassProxyTests-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<aop:aspectj-autoproxy proxy-target-class="true"/>
99

10-
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericCounterAspect"/>
10+
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$GenericCounterAspect"/>
1111

12-
<bean id="testBean" class="org.springframework.aop.aspectj.generic.DerivedStringParameterizedClass"/>
12+
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$DerivedStringParameterizedClass"/>
1313

1414
</beans>

spring-context/src/test/resources/org/springframework/aop/aspectj/generic/GenericBridgeMethodMatchingTests-context.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
<aop:aspectj-autoproxy proxy-target-class="false"/>
99

10-
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericCounterAspect"/>
10+
<bean id="counterAspect" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$GenericCounterAspect"/>
1111

12-
<bean id="testBean" class="org.springframework.aop.aspectj.generic.DerivedStringParameterizedClass"/>
12+
<bean id="testBean" class="org.springframework.aop.aspectj.generic.GenericBridgeMethodMatchingTests$DerivedStringParameterizedClass"/>
1313

1414
</beans>

0 commit comments

Comments
 (0)