CacheBase implements ApplicationContextAware, InitializingBean { protected void verifyReturnTypeIsList(final Method method, final Class<?> annotationClass) { if (!verifyTypeIsList(method.getReturnType())) { throw new InvalidAnnotationException( String.format("The annotation [%s] is only valid on a method that returns a [%s] or its subclass. " + "[%s] does not fulfill this requirement.", annotationClass.getName(), List.class.getName(), method.toString())); } }  @Override void afterPropertiesSet(); @Override void setApplicationContext(final ApplicationContext applicationContext); void setCacheKeyBuilder(final CacheKeyBuilder cacheKeyBuilder); CacheKeyBuilder getCacheKeyBuilder(); BridgeMethodMappingStore getBridgeMethodMappingStore(); void setBridgeMethodMappingStore(final BridgeMethodMappingStore bridgeMethodMappingStore); Cache getCache(final AnnotationData data); boolean isCacheDisabled(); Method getMethodToCache(final JoinPoint jp, final Class<T> annotationClass); @SuppressWarnings("unchecked") T getUpdateData(final AnnotationData data, final Method method, final Object[] args, final Object returnValue); static final String DISABLE_CACHE_PROPERTY; }
@Test public void testReturnTypeChecking() throws Exception { Method method = null; method = ReturnTypeCheck.class.getMethod("checkA", (Class<?>[]) null); cut.verifyReturnTypeIsList(method, CacheKeyMethod.class); method = ReturnTypeCheck.class.getMethod("checkB", (Class<?>[]) null); cut.verifyReturnTypeIsList(method, CacheKeyMethod.class); method = ReturnTypeCheck.class.getMethod("checkC", (Class<?>[]) null); cut.verifyReturnTypeIsList(method, CacheKeyMethod.class); method = ReturnTypeCheck.class.getMethod("checkD", (Class<?>[]) null); cut.verifyReturnTypeIsList(method, CacheKeyMethod.class); try { method = ReturnTypeCheck.class.getMethod("checkE", (Class<?>[]) null); cut.verifyReturnTypeIsList(method, CacheKeyMethod.class); fail("Expected Exception."); } catch (InvalidAnnotationException ex) { assertTrue(ex.getMessage().indexOf("requirement") != -1); } }