@Test public void testParameterIfParamNull() throws NoSuchMethodException { Method method = TestClass.class.getMethod("methodB", String.class); when(methodSignature.getMethod()).thenReturn(method); when(proceedingJoinPoint.getArgs()).thenReturn(new Object[]{null}); assertFalse(underTest.getParameter(proceedingJoinPoint, methodSignature, NotNull.class).isPresent()); }
public Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation) { Optional<Parameter> optionalParameter = Arrays.stream(methodSignature.getMethod().getParameters()) .filter(parameter -> parameter.isAnnotationPresent(annotation)) .findFirst(); if (optionalParameter.isPresent()) { int parameterIndex = Lists.newArrayList(methodSignature.getMethod().getParameters()).indexOf(optionalParameter.get()); return Optional.ofNullable(proceedingJoinPoint.getArgs()[parameterIndex]); } return Optional.empty(); }
ReflectionUtil { public Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation) { Optional<Parameter> optionalParameter = Arrays.stream(methodSignature.getMethod().getParameters()) .filter(parameter -> parameter.isAnnotationPresent(annotation)) .findFirst(); if (optionalParameter.isPresent()) { int parameterIndex = Lists.newArrayList(methodSignature.getMethod().getParameters()).indexOf(optionalParameter.get()); return Optional.ofNullable(proceedingJoinPoint.getArgs()[parameterIndex]); } return Optional.empty(); } }
ReflectionUtil { public Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation) { Optional<Parameter> optionalParameter = Arrays.stream(methodSignature.getMethod().getParameters()) .filter(parameter -> parameter.isAnnotationPresent(annotation)) .findFirst(); if (optionalParameter.isPresent()) { int parameterIndex = Lists.newArrayList(methodSignature.getMethod().getParameters()).indexOf(optionalParameter.get()); return Optional.ofNullable(proceedingJoinPoint.getArgs()[parameterIndex]); } return Optional.empty(); }  }
ReflectionUtil { public Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation) { Optional<Parameter> optionalParameter = Arrays.stream(methodSignature.getMethod().getParameters()) .filter(parameter -> parameter.isAnnotationPresent(annotation)) .findFirst(); if (optionalParameter.isPresent()) { int parameterIndex = Lists.newArrayList(methodSignature.getMethod().getParameters()).indexOf(optionalParameter.get()); return Optional.ofNullable(proceedingJoinPoint.getArgs()[parameterIndex]); } return Optional.empty(); }  Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation); Object proceed(ProceedingJoinPoint proceedingJoinPoint); }
ReflectionUtil { public Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation) { Optional<Parameter> optionalParameter = Arrays.stream(methodSignature.getMethod().getParameters()) .filter(parameter -> parameter.isAnnotationPresent(annotation)) .findFirst(); if (optionalParameter.isPresent()) { int parameterIndex = Lists.newArrayList(methodSignature.getMethod().getParameters()).indexOf(optionalParameter.get()); return Optional.ofNullable(proceedingJoinPoint.getArgs()[parameterIndex]); } return Optional.empty(); }  Optional<Object> getParameter(ProceedingJoinPoint proceedingJoinPoint, MethodSignature methodSignature, Class annotation); Object proceed(ProceedingJoinPoint proceedingJoinPoint);  }