@Test public void testParameterNameDiscoverWithReferencePointcut() throws Exception { AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer("somepc(formal) && set(* *)"); discoverer.setRaiseExceptions(true); Method methodUsedForParameterTypeDiscovery = getClass().getMethod("methodWithOneParam", String.class); String[] pnames = discoverer.getParameterNames(methodUsedForParameterTypeDiscovery); assertEquals("one parameter name", 1, pnames.length); assertEquals("formal", pnames[0]); }
protected void assertException( Method method, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) { AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); discoverer.setRaiseExceptions(true); discoverer.setReturningName(returning); discoverer.setThrowingName(throwing); try { discoverer.getParameterNames(method); fail("Expecting " + exceptionType.getName() + " with message '" + message + "'"); } catch (RuntimeException expected) { assertEquals("Expecting exception of type " + exceptionType.getName(), exceptionType, expected.getClass()); assertEquals("Exception message does not match expected", message, expected.getMessage()); } }
protected void assertParameterNames( Method method, String pointcut, String returning, String throwing, String[] parameterNames) { assertEquals("bad test specification, must have same number of parameter names as method arguments", method.getParameterCount(), parameterNames.length); AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); discoverer.setRaiseExceptions(true); discoverer.setReturningName(returning); discoverer.setThrowingName(throwing); String[] discoveredNames = discoverer.getParameterNames(method); String formattedExpectedNames = format(parameterNames); String formattedActualNames = format(discoveredNames); assertEquals("Expecting " + parameterNames.length + " parameter names in return set '" + formattedExpectedNames + "', but found " + discoveredNames.length + " '" + formattedActualNames + "'", parameterNames.length, discoveredNames.length); for (int i = 0; i < discoveredNames.length; i++) { assertNotNull("Parameter names must never be null", discoveredNames[i]); assertEquals("Expecting parameter " + i + " to be named '" + parameterNames[i] + "' but was '" + discoveredNames[i] + "'", parameterNames[i], discoveredNames[i]); } }