11/*
2- * Copyright 2002-2012 the original author or authors.
2+ * Copyright 2002-2017 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.
2727/**
2828 * Unit tests for the {@link AspectJAdviceParameterNameDiscoverer} class.
2929 *
30- * <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} in
31- * the 'tiger' tree for tests relating to annotations.
30+ * <p>See also {@link TigerAspectJAdviceParameterNameDiscovererTests} for tests relating to annotations.
3231 *
3332 * @author Adrian Colyer
3433 * @author Chris Beams
@@ -83,27 +82,28 @@ public void testNoArgs() {
8382
8483 @ Test
8584 public void testJoinPointOnly () {
86- assertParameterNames (getMethod ("tjp" ), "execution(* *(..))" , new String []{"thisJoinPoint" });
85+ assertParameterNames (getMethod ("tjp" ), "execution(* *(..))" , new String [] {"thisJoinPoint" });
8786 }
8887
8988 @ Test
9089 public void testJoinPointStaticPartOnly () {
91- assertParameterNames (getMethod ("tjpsp" ), "execution(* *(..))" , new String []{"thisJoinPointStaticPart" });
90+ assertParameterNames (getMethod ("tjpsp" ), "execution(* *(..))" , new String [] {"thisJoinPointStaticPart" });
9291 }
9392
9493 @ Test
9594 public void testTwoJoinPoints () {
96- assertException (getMethod ("twoJoinPoints" ), "foo()" , IllegalStateException .class , "Failed to bind all argument names: 1 argument(s) could not be bound" );
95+ assertException (getMethod ("twoJoinPoints" ), "foo()" , IllegalStateException .class ,
96+ "Failed to bind all argument names: 1 argument(s) could not be bound" );
9797 }
9898
9999 @ Test
100100 public void testOneThrowable () {
101- assertParameterNames (getMethod ("oneThrowable" ), "foo()" , null , "ex" , new String []{"ex" });
101+ assertParameterNames (getMethod ("oneThrowable" ), "foo()" , null , "ex" , new String [] {"ex" });
102102 }
103103
104104 @ Test
105105 public void testOneJPAndOneThrowable () {
106- assertParameterNames (getMethod ("jpAndOneThrowable" ), "foo()" , null , "ex" , new String []{"thisJoinPoint" , "ex" });
106+ assertParameterNames (getMethod ("jpAndOneThrowable" ), "foo()" , null , "ex" , new String [] {"thisJoinPoint" , "ex" });
107107 }
108108
109109 @ Test
@@ -120,7 +120,7 @@ public void testThrowableNoCandidates() {
120120
121121 @ Test
122122 public void testReturning () {
123- assertParameterNames (getMethod ("oneObject" ), "foo()" , "obj" , null , new String []{"obj" });
123+ assertParameterNames (getMethod ("oneObject" ), "foo()" , "obj" , null , new String [] {"obj" });
124124 }
125125
126126 @ Test
@@ -137,16 +137,16 @@ public void testReturningNoCandidates() {
137137
138138 @ Test
139139 public void testThisBindingOneCandidate () {
140- assertParameterNames (getMethod ("oneObject" ), "this(x)" , new String []{"x" });
140+ assertParameterNames (getMethod ("oneObject" ), "this(x)" , new String [] {"x" });
141141 }
142142
143143 @ Test
144144 public void testThisBindingWithAlternateTokenizations () {
145- assertParameterNames (getMethod ("oneObject" ), "this( x )" , new String []{"x" });
146- assertParameterNames (getMethod ("oneObject" ), "this( x)" , new String []{"x" });
147- assertParameterNames (getMethod ("oneObject" ), "this (x )" , new String []{"x" });
148- assertParameterNames (getMethod ("oneObject" ), "this(x )" , new String []{"x" });
149- assertParameterNames (getMethod ("oneObject" ), "foo() && this(x)" , new String []{"x" });
145+ assertParameterNames (getMethod ("oneObject" ), "this( x )" , new String [] {"x" });
146+ assertParameterNames (getMethod ("oneObject" ), "this( x)" , new String [] {"x" });
147+ assertParameterNames (getMethod ("oneObject" ), "this (x )" , new String [] {"x" });
148+ assertParameterNames (getMethod ("oneObject" ), "this(x )" , new String [] {"x" });
149+ assertParameterNames (getMethod ("oneObject" ), "foo() && this(x)" , new String [] {"x" });
150150 }
151151
152152 @ Test
@@ -165,16 +165,16 @@ public void testThisBindingWithBadPointcutExpressions() {
165165
166166 @ Test
167167 public void testTargetBindingOneCandidate () {
168- assertParameterNames (getMethod ("oneObject" ), "target(x)" , new String []{"x" });
168+ assertParameterNames (getMethod ("oneObject" ), "target(x)" , new String [] {"x" });
169169 }
170170
171171 @ Test
172172 public void testTargetBindingWithAlternateTokenizations () {
173- assertParameterNames (getMethod ("oneObject" ), "target( x )" , new String []{"x" });
174- assertParameterNames (getMethod ("oneObject" ), "target( x)" , new String []{"x" });
175- assertParameterNames (getMethod ("oneObject" ), "target (x )" , new String []{"x" });
176- assertParameterNames (getMethod ("oneObject" ), "target(x )" , new String []{"x" });
177- assertParameterNames (getMethod ("oneObject" ), "foo() && target(x)" , new String []{"x" });
173+ assertParameterNames (getMethod ("oneObject" ), "target( x )" , new String [] {"x" });
174+ assertParameterNames (getMethod ("oneObject" ), "target( x)" , new String [] {"x" });
175+ assertParameterNames (getMethod ("oneObject" ), "target (x )" , new String [] {"x" });
176+ assertParameterNames (getMethod ("oneObject" ), "target(x )" , new String [] {"x" });
177+ assertParameterNames (getMethod ("oneObject" ), "foo() && target(x)" , new String [] {"x" });
178178 }
179179
180180 @ Test
@@ -193,7 +193,7 @@ public void testTargetBindingWithBadPointcutExpressions() {
193193
194194 @ Test
195195 public void testArgsBindingOneObject () {
196- assertParameterNames (getMethod ("oneObject" ), "args(x)" , new String []{"x" });
196+ assertParameterNames (getMethod ("oneObject" ), "args(x)" , new String [] {"x" });
197197 }
198198
199199 @ Test
@@ -210,7 +210,7 @@ public void testAmbiguousArgsBinding() {
210210
211211 @ Test
212212 public void testArgsOnePrimitive () {
213- assertParameterNames (getMethod ("onePrimitive" ), "args(count)" , new String []{"count" });
213+ assertParameterNames (getMethod ("onePrimitive" ), "args(count)" , new String [] {"count" });
214214 }
215215
216216 @ Test
@@ -221,62 +221,64 @@ public void testArgsOnePrimitiveOneObject() {
221221
222222 @ Test
223223 public void testThisAndPrimitive () {
224- assertParameterNames (getMethod ("oneObjectOnePrimitive" ), "args(count) && this(obj)" , new String []{"obj" , "count" });
224+ assertParameterNames (getMethod ("oneObjectOnePrimitive" ), "args(count) && this(obj)" , new String [] {"obj" , "count" });
225225 }
226226
227227 @ Test
228228 public void testTargetAndPrimitive () {
229- assertParameterNames (getMethod ("oneObjectOnePrimitive" ), "args(count) && target(obj)" , new String []{"obj" , "count" });
229+ assertParameterNames (getMethod ("oneObjectOnePrimitive" ), "args(count) && target(obj)" , new String [] {"obj" , "count" });
230230 }
231231
232232 @ Test
233233 public void testThrowingAndPrimitive () {
234- assertParameterNames (getMethod ("oneThrowableOnePrimitive" ), "args(count)" , null , "ex" , new String []{"ex" , "count" });
234+ assertParameterNames (getMethod ("oneThrowableOnePrimitive" ), "args(count)" , null , "ex" , new String [] {"ex" , "count" });
235235 }
236236
237237 @ Test
238238 public void testAllTogetherNow () {
239- assertParameterNames (getMethod ("theBigOne" ), "this(foo) && args(x)" , null , "ex" , new String []{"thisJoinPoint" , "ex" , "x" , "foo" });
239+ assertParameterNames (getMethod ("theBigOne" ), "this(foo) && args(x)" , null , "ex" , new String [] {"thisJoinPoint" , "ex" , "x" , "foo" });
240240 }
241241
242242 @ Test
243243 public void testReferenceBinding () {
244- assertParameterNames (getMethod ("onePrimitive" ),"somepc(foo)" ,new String [] {"foo" });
244+ assertParameterNames (getMethod ("onePrimitive" ),"somepc(foo)" , new String [] {"foo" });
245245 }
246246
247247 @ Test
248248 public void testReferenceBindingWithAlternateTokenizations () {
249- assertParameterNames (getMethod ("onePrimitive" ),"call(bar *) && somepc(foo)" ,new String [] {"foo" });
250- assertParameterNames (getMethod ("onePrimitive" ),"somepc ( foo )" ,new String [] {"foo" });
251- assertParameterNames (getMethod ("onePrimitive" ),"somepc( foo)" ,new String [] {"foo" });
249+ assertParameterNames (getMethod ("onePrimitive" ),"call(bar *) && somepc(foo)" , new String [] {"foo" });
250+ assertParameterNames (getMethod ("onePrimitive" ),"somepc ( foo )" , new String [] {"foo" });
251+ assertParameterNames (getMethod ("onePrimitive" ),"somepc( foo)" , new String [] {"foo" });
252252 }
253253
254254
255255 protected Method getMethod (String name ) {
256256 // assumes no overloading of test methods...
257257 Method [] candidates = this .getClass ().getMethods ();
258- for (int i = 0 ; i < candidates . length ; i ++ ) {
259- if (candidates [ i ] .getName ().equals (name )) {
260- return candidates [ i ] ;
258+ for (Method candidate : candidates ) {
259+ if (candidate .getName ().equals (name )) {
260+ return candidate ;
261261 }
262262 }
263263 fail ("Bad test specification, no method '" + name + "' found in test class" );
264264 return null ;
265265 }
266266
267- protected void assertParameterNames (Method m , String pointcut , String [] parameterNames ) {
268- assertParameterNames (m , pointcut , null , null , parameterNames );
267+ protected void assertParameterNames (Method method , String pointcut , String [] parameterNames ) {
268+ assertParameterNames (method , pointcut , null , null , parameterNames );
269269 }
270270
271- protected void assertParameterNames (Method m , String pointcut , String returning , String throwing , String [] parameterNames ) {
271+ protected void assertParameterNames (Method method , String pointcut , String returning , String throwing ,
272+ String [] parameterNames ) {
273+
272274 assertEquals ("bad test specification, must have same number of parameter names as method arguments" ,
273- m .getParameterCount (), parameterNames .length );
275+ method .getParameterCount (), parameterNames .length );
274276
275277 AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer (pointcut );
276278 discoverer .setRaiseExceptions (true );
277279 discoverer .setReturningName (returning );
278280 discoverer .setThrowingName (throwing );
279- String [] discoveredNames = discoverer .getParameterNames (m );
281+ String [] discoveredNames = discoverer .getParameterNames (method );
280282
281283 String formattedExpectedNames = format (parameterNames );
282284 String formattedActualNames = format (discoveredNames );
@@ -294,18 +296,20 @@ protected void assertParameterNames(Method m, String pointcut, String returning,
294296 }
295297 }
296298
297- protected void assertException (Method m , String pointcut , Class <?> exceptionType , String message ) {
298- assertException (m , pointcut , null , null , exceptionType , message );
299+ protected void assertException (Method method , String pointcut , Class <?> exceptionType , String message ) {
300+ assertException (method , pointcut , null , null , exceptionType , message );
299301 }
300302
301- protected void assertException (Method m , String pointcut , String returning , String throwing , Class <?> exceptionType , String message ) {
303+ protected void assertException (Method method , String pointcut , String returning , String throwing ,
304+ Class <?> exceptionType , String message ) {
305+
302306 AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer (pointcut );
303307 discoverer .setRaiseExceptions (true );
304308 discoverer .setReturningName (returning );
305309 discoverer .setThrowingName (throwing );
306310
307311 try {
308- discoverer .getParameterNames (m );
312+ discoverer .getParameterNames (method );
309313 fail ("Expecting " + exceptionType .getName () + " with message '" + message + "'" );
310314 }
311315 catch (RuntimeException expected ) {
0 commit comments