ConfigurationMetadata { public static <T> ConfigurationMetadata<T> getConfigurationMetadata(Class<T> configClass) { return getConfigurationMetadata(configClass, Problems.NULL_MONITOR); } private  ConfigurationMetadata(Class<T> configClass, Monitor monitor); static ConfigurationMetadata<T> getValidConfigurationMetadata(Class<T> configClass); static ConfigurationMetadata<T> getConfigurationMetadata(Class<T> configClass); static boolean isConfigClass(Class<?> classz); Class<T> getConfigClass(); Constructor<T> getConstructor(); Map<String, AttributeMetadata> getAttributes(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString(); static Method findAnnotatedMethod(Class<?> configClass, Class<? extends java.lang.annotation.Annotation> annotation, String methodName, Class<?>... paramTypes);  }
@Test public void testSetterConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(SetterConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, SetterConfigClass.class, "description", false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testSetterSensitiveClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(SetterSensitiveClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, SetterSensitiveClass.class, "description", true, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testSubSetterConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(SetterSubConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, SetterSubConfigClass.class, "description", false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testSetterInterfaceImpl() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(SetterInterfaceImpl.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, SetterInterfaceImpl.class, "description", false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test(expectedExceptions = NullPointerException.class) public void testNull() { ConfigurationMetadata.getConfigurationMetadata(null); }
@Test public void testAbstractClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(AbstractClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, AbstractClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("abstract", AbstractClass.class.getName()); }
@Test public void testNotPublicClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NotPublicClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, NotPublicClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testNotPublicConstructorClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NotPublicConstructorClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, NotPublicConstructorClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testNoNoArgConstructorClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NoNoArgConstructorClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, NoNoArgConstructorClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("no-arg constructor", NoNoArgConstructorClass.class.getName()); }
@Test public void testNoConfigMethodsClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NoConfigMethodsClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, NoConfigMethodsClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("does not have any @Config annotations", NoConfigMethodsClass.class.getName()); }
@Test public void testDefunctOnlyClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctOnlyClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, DefunctOnlyClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testGetterAndSetterAnnotatedClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterAndSetterAnnotatedClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, GetterAndSetterAnnotatedClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded(GetterAndSetterAnnotatedClass.class.getName()); }
@Test public void testEmptyPropertyNameClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(EmptyPropertyNameClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, EmptyPropertyNameClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("empty value", "setValue"); }
@Test public void testNotPublicAttributeClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NotPublicAttributeClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, NotPublicAttributeClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testStaticAttributeClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(StaticAttributeClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, StaticAttributeClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded(StaticAttributeClass.class.getName(), "setValue", "is static"); }
@Test public void testGetterWithParameterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterWithParameterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, GetterWithParameterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "unusable", "getValue", "setValue"); }
@Test public void testGetterNoReturnClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterNoReturnClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, GetterNoReturnClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "unusable", "getValue", "setValue"); }
@Test public void testGetterNoSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterNoSetterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, GetterNoSetterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("is not a valid setter", GetterNoSetterClass.class.getName(), "getValue"); }
@Test public void testGetterMultipleSettersClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterMultipleSettersClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, GetterMultipleSettersClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testGetterPrivateSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterPrivateSetterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, GetterPrivateSetterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testIsMethodWithParameterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(IsMethodWithParameterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, IsMethodWithParameterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "unusable", "isValue", "setValue"); }
@Test public void testIsMethodNoReturnClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(IsMethodNoReturnClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, IsMethodNoReturnClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "setValue"); }
@Test public void testIsMethodNoSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(IsMethodNoSetterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, IsMethodNoSetterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded(IsMethodNoSetterClass.class.getName(), "isValue", "is not a valid setter"); }
@Test public void testIsMethodMultipleSettersClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(IsMethodMultipleSettersClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, IsMethodMultipleSettersClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testIsMethodPrivateSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(IsMethodPrivateSetterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, IsMethodPrivateSetterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testSetterWithNoParameterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(SetterWithNoParameterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, SetterWithNoParameterClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("does not have exactly one parameter", SetterWithNoParameterClass.class.getName(), "setValue"); }
@Test public void testNotJavaBeanClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NotJavaBeanClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, NotJavaBeanClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("not a valid setter", "putValue"); }
@Test public void testMultipleAnnotatedSettersClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MultipleAnnotatedSettersClass.class, monitor); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("Multiple methods are annotated", "Value"); }
@Test public void testCurrentAndLegacyConfigOnGetterClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(CurrentAndLegacyConfigOnGetterClass.class, monitor); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("not a valid setter", "getValue"); }
@Test public void testCurrentAndLegacyConfigOnSetterClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(CurrentAndLegacyConfigOnSetterClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value", "replacedValue")); verifyMetaData(metadata, CurrentAndLegacyConfigOnSetterClass.class, "description", false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testCurrentConfigWithReplacedByClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(CurrentConfigWithReplacedByClass.class, monitor); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@Config method", "setValue", "claiming to be replaced by", "'other-name'"); }
@Test public void testLegacyConfigOnGetterClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnGetterClass.class, monitor); monitor.assertNumberOfErrors(2); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("not a valid setter", "getValue"); monitor.assertMatchingErrorRecorded("LegacyConfig", "getValue", "not associated with any valid @Config"); }
@Test public void testLegacyConfigOnSetterClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnSetterClass.class, monitor); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("LegacyConfig", "setValue", "not associated with any valid @Config"); }
@Test public void testLegacyConfigOnDeprecatedSetterClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnDeprecatedSetterClass.class, monitor); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testLegacyConfigOnNonDeprecatedSetterClass() { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigOnNonDeprecatedSetterClass.class, monitor); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Replaced @LegacyConfig method", "setValue(int)", "should be @Deprecated"); }
@Test public void testMultipleLegacyConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MultipleLegacyConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("legacy1", "legacy2", "value")); verifyMetaData(metadata, MultipleLegacyConfigClass.class, "description", false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testEmptyStringLegacyConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(EmptyStringLegacyConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, EmptyStringLegacyConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig method", EmptyStringLegacyConfigClass.class.getName(), "setValue", "null or empty value"); }
@Test public void testEmptyArrayLegacyConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(EmptyArrayLegacyConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, EmptyArrayLegacyConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig method", EmptyArrayLegacyConfigClass.class.getName(), "setValue", "empty list"); }
@Test public void testEmptyStringInArrayLegacyConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(EmptyStringInArrayLegacyConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, EmptyStringInArrayLegacyConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig method", EmptyStringInArrayLegacyConfigClass.class.getName(), "setValue", "null or empty value"); }
@Test public void testLegacyConfigDuplicatesConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigDuplicatesConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, LegacyConfigDuplicatesConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@Config property", "'value'", "appears in @LegacyConfig", "setValue"); }
@Test public void testLegacyConfigDuplicatesConfigOnOtherMethodClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigDuplicatesConfigOnOtherMethodClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, LegacyConfigDuplicatesConfigOnOtherMethodClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(2); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig", "'value'", "is replaced by @Config", "same name", "setValue"); monitor.assertMatchingErrorRecorded("@LegacyConfig", "setValue", "not associated with any valid @Config"); }
@Test public void testLegacyConfigDuplicatesConfigOnLinkedMethodClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigDuplicatesConfigOnLinkedMethodClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, LegacyConfigDuplicatesConfigOnLinkedMethodClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(2); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig", "'value'", "is replaced by @Config", "same name", "setValue"); monitor.assertMatchingErrorRecorded("@LegacyConfig", "setIntValue", "not associated with any valid @Config"); }
@Test public void testDeprecatedConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DeprecatedConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); expectedAttributes.put("Deprecated", ImmutableSet.of("deprecated-value")); verifyMetaData(metadata, DeprecatedConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testDeprecatedConfigOnSetterOnlyClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DeprecatedConfigOnSetterOnlyClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); expectedAttributes.put("Deprecated", ImmutableSet.of("deprecated-value")); verifyMetaData(metadata, DeprecatedConfigOnSetterOnlyClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("getDeprecated", "setDeprecated", "must be @Deprecated together"); }
@Test public void testDeprecatedConfigOnGetterOnlyClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DeprecatedConfigOnGetterOnlyClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); expectedAttributes.put("Deprecated", ImmutableSet.of("deprecated-value")); verifyMetaData(metadata, DeprecatedConfigOnGetterOnlyClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("getDeprecated", "setDeprecated", "must be @Deprecated together"); }
@Test public void testDefunctConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DefunctConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testDefunctConfigEmptyArrayClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigEmptyArrayClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DefunctConfigEmptyArrayClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@DefunctConfig", "is empty"); }
@Test public void testDefunctConfigEmptyStringClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigEmptyStringClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DefunctConfigEmptyStringClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@DefunctConfig", "contains empty values"); }
@Test public void testDefunctConfigInUseClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigInUseClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DefunctConfigInUseClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@Config property", "'value'", "setValue", "is defunct on class"); }
@Test public void testDefunctConfigInLegacyUseClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigInLegacyUseClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value", "replacedValue")); verifyMetaData(metadata, DefunctConfigInLegacyUseClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig property", "'replacedValue'", "setValue", "is defunct on class"); }
@Test public void testDefunctConfigInLinkedLegacyUseClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DefunctConfigInLinkedLegacyUseClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value", "replacedValue")); verifyMetaData(metadata, DefunctConfigInLinkedLegacyUseClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@LegacyConfig property", "'replacedValue'", "setIntValue", "is defunct on class"); }
@Test public void testDuplicateDefunctConfigClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DuplicateDefunctConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DuplicateDefunctConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("Defunct property", "'defunct'", "listed more than once"); }
@Test public void testLegacyConfigSensitiveClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(LegacyConfigSensitiveClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value", "replacedValue")); verifyMetaData(metadata, LegacyConfigSensitiveClass.class, null, false , expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("@ConfigSecuritySensitive method", "setValue", "is not annotated with @Config."); }
@Test public void testSimpleMapClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(ConfigMapSimple.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Map", ImmutableSet.of("map")); verifyMetaData(metadata, ConfigMapSimple.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testComplexMapClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(ConfigMapComplex.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Map", ImmutableSet.of("map")); verifyMetaData(metadata, ConfigMapComplex.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testDeprecatedMapClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DeprecatedMapConfigClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value", "replacedValue")); verifyMetaData(metadata, DeprecatedMapConfigClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }
@Test public void testMapConfigTypesNotConcreteClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MapConfigTypesNotConcreteClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, MapConfigTypesNotConcreteClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(2); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map key type is not a concrete class"); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map value type is not a concrete class"); }
@Test public void testMapConfigRawType() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MapConfigNotGenericClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, MapConfigNotGenericClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map is a raw type"); }
@Test public void testMapConfigValueTypeErrorClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MapConfigValueTypeErrorClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, MapConfigValueTypeErrorClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map value type GetterNoSetterClass: Error: Method", "getValue", "is not a valid setter"); }
@Test public void testMapConfigValueTypeWarningClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(MapConfigValueTypeWarningClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, MapConfigValueTypeWarningClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(1); monitor.assertMatchingWarningRecorded("Configuration setter method", "setValue", "Map value type LegacyConfigOnNonDeprecatedSetterClass: Warning: Replaced @LegacyConfig method", "setValue", "should be @Deprecated"); }
@Test public void testDeprecatedMapConfigTypesNotConcreteClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(DeprecatedMapConfigTypesNotConcreteClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, DeprecatedMapConfigTypesNotConcreteClass.class, null, false, expectedAttributes); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map key type is not a concrete class"); monitor.assertMatchingErrorRecorded("Configuration setter method", "setValue", "Map value type is not a concrete class"); }
@Test public void testConfigValueImplementingMapNotTreatedAsConfigMap() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(ConfigValueImplementsMapClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); expectedAttributes.put("Value", ImmutableSet.of("value")); verifyMetaData(metadata, ConfigValueImplementsMapClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(0); monitor.assertNumberOfWarnings(0); }