diff --git a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java index f6e1b737ff7..bf0ba7149de 100644 --- a/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java +++ b/spring-beans/src/main/java/org/springframework/beans/annotation/AnnotationBeanUtils.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -59,12 +59,12 @@ public abstract class AnnotationBeanUtils { * @see org.springframework.beans.BeanWrapper */ public static void copyPropertiesToBean(Annotation ann, Object bean, StringValueResolver valueResolver, String... excludedProperties) { - Set excluded = new HashSet(Arrays.asList(excludedProperties)); + Set excluded = new HashSet(Arrays.asList(excludedProperties)); Method[] annotationProperties = ann.annotationType().getDeclaredMethods(); BeanWrapper bw = PropertyAccessorFactory.forBeanPropertyAccess(bean); for (Method annotationProperty : annotationProperties) { String propertyName = annotationProperty.getName(); - if ((!excluded.contains(propertyName)) && bw.isWritableProperty(propertyName)) { + if (!excluded.contains(propertyName) && bw.isWritableProperty(propertyName)) { Object value = ReflectionUtils.invokeMethod(annotationProperty, ann); if (valueResolver != null && value instanceof String) { value = valueResolver.resolveStringValue((String) value); diff --git a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java index f53c9e1a253..a718338e63c 100644 --- a/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java +++ b/spring-context/src/test/java/org/springframework/context/annotation/AnnotationConfigApplicationContextTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2013 the original author or authors. + * Copyright 2002-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -25,6 +25,7 @@ import org.springframework.beans.factory.FactoryBean; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.config.BeanPostProcessor; +import org.springframework.context.ApplicationContext; import org.springframework.context.annotation6.ComponentForScanning; import org.springframework.context.annotation6.ConfigForScanning; import org.springframework.context.annotation6.Jsr330NamedForScanning; @@ -40,10 +41,10 @@ import static org.springframework.util.StringUtils.*; */ public class AnnotationConfigApplicationContextTests { - @Test(expected=IllegalArgumentException.class) + @Test(expected = IllegalArgumentException.class) public void nullGetBeanParameterIsDisallowed() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); - context.getBean((Class)null); + ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); + context.getBean((Class) null); } @Test @@ -83,7 +84,7 @@ public class AnnotationConfigApplicationContextTests { @Test public void getBeanByType() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); + ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); TestBean testBean = context.getBean(TestBean.class); assertNotNull("getBean() should not return null", testBean); assertThat(testBean.name, equalTo("foo")); @@ -95,7 +96,7 @@ public class AnnotationConfigApplicationContextTests { */ @Test public void defaultConfigClassBeanNameIsGeneratedProperly() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); + ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); // attempt to retrieve the instance by its generated bean name Config configObject = (Config) context.getBean("annotationConfigApplicationContextTests.Config"); @@ -108,18 +109,16 @@ public class AnnotationConfigApplicationContextTests { */ @Test public void explicitConfigClassBeanNameIsRespected() { - AnnotationConfigApplicationContext context = - new AnnotationConfigApplicationContext(ConfigWithCustomName.class); + ApplicationContext context = new AnnotationConfigApplicationContext(ConfigWithCustomName.class); // attempt to retrieve the instance by its specified name - ConfigWithCustomName configObject = - (ConfigWithCustomName) context.getBean("customConfigBeanName"); + ConfigWithCustomName configObject = (ConfigWithCustomName) context.getBean("customConfigBeanName"); assertNotNull(configObject); } @Test public void getBeanByTypeRaisesNoSuchBeanDefinitionException() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(Config.class); + ApplicationContext context = new AnnotationConfigApplicationContext(Config.class); // attempt to retrieve a bean that does not exist Class targetType = Pattern.class; @@ -135,7 +134,7 @@ public class AnnotationConfigApplicationContextTests { @Test public void getBeanByTypeAmbiguityRaisesException() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class); + ApplicationContext context = new AnnotationConfigApplicationContext(TwoTestBeanConfig.class); try { context.getBean(TestBean.class); @@ -153,7 +152,7 @@ public class AnnotationConfigApplicationContextTests { @Test public void autowiringIsEnabledByDefault() { - AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AutowiredConfig.class); + ApplicationContext context = new AnnotationConfigApplicationContext(AutowiredConfig.class); assertThat(context.getBean(TestBean.class).name, equalTo("foo")); } @@ -255,13 +254,14 @@ public class AnnotationConfigApplicationContextTests { } class TestBean { + String name; @Override public int hashCode() { final int prime = 31; int result = 1; - result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + (name == null ? 0 : name.hashCode()); return result; } @@ -277,7 +277,8 @@ class TestBean { if (name == null) { if (other.name != null) return false; - } else if (!name.equals(other.name)) + } + else if (!name.equals(other.name)) return false; return true; } diff --git a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java index 2acdf0b380f..0fb02550aeb 100644 --- a/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java +++ b/spring-core/src/main/java/org/springframework/core/annotation/AnnotationUtils.java @@ -121,12 +121,12 @@ public abstract class AnnotationUtils { private static final Map findAnnotationCache = new ConcurrentReferenceHashMap(256); - private static final Map, Boolean> annotatedInterfaceCache = - new ConcurrentReferenceHashMap, Boolean>(256); - private static final Map metaPresentCache = new ConcurrentReferenceHashMap(256); + private static final Map, Boolean> annotatedInterfaceCache = + new ConcurrentReferenceHashMap, Boolean>(256); + private static final Map, Boolean> synthesizableCache = new ConcurrentReferenceHashMap, Boolean>(256); @@ -787,7 +787,7 @@ public abstract class AnnotationUtils { * @see #isAnnotationDeclaredLocally(Class, Class) */ public static Class findAnnotationDeclaringClassForTypes(List> annotationTypes, Class clazz) { - Assert.notEmpty(annotationTypes, "The list of annotation types must not be empty"); + Assert.notEmpty(annotationTypes, "List of annotation types must not be empty"); if (clazz == null || Object.class == clazz) { return null; } @@ -1055,7 +1055,7 @@ public abstract class AnnotationUtils { try { Object value = method.invoke(annotation); Object defaultValue = method.getDefaultValue(); - if (mergeMode && (defaultValue != null)) { + if (mergeMode && defaultValue != null) { if (ObjectUtils.nullSafeEquals(value, defaultValue)) { value = DEFAULT_VALUE_PLACEHOLDER; } diff --git a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java index ed0ee2299ee..852de13c2e9 100644 --- a/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java +++ b/spring-core/src/test/java/org/springframework/core/annotation/AnnotatedElementUtilsTests.java @@ -56,6 +56,7 @@ public class AnnotatedElementUtilsTests { @Rule public final ExpectedException exception = ExpectedException.none(); + @Test public void getMetaAnnotationTypesOnNonAnnotatedClass() { assertNull(getMetaAnnotationTypes(NonAnnotatedClass.class, TransactionalComponent.class)); @@ -69,8 +70,7 @@ public class AnnotatedElementUtilsTests { @Test public void getMetaAnnotationTypesOnClassWithMetaDepth2() { - Set names = getMetaAnnotationTypes(ComposedTransactionalComponentClass.class, - ComposedTransactionalComponent.class); + Set names = getMetaAnnotationTypes(ComposedTransactionalComponentClass.class, ComposedTransactionalComponent.class); assertEquals(names(TransactionalComponent.class, Transactional.class, Component.class), names); }