@Test public void testLegacyConfigOnGetterClass() throws Exception { 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 testLegacyConfigOnGetterClass() throws Exception { 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 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 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 testNotPublicAttributeClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(NotPublicAttributeClass.class, monitor); Map<String, Set<String>> expectedAttributes = new HashMap<>(); verifyMetaData(metadata, NotPublicAttributeClass.class, null, false, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "unusable", "getValue", "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 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 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 testLegacyConfigOnSetterClass() throws Exception { 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 testCurrentConfigWithReplacedByClass() throws Exception { 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 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 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 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 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 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 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 testGetterNoReturnClass() throws Exception { TestMonitor monitor = new TestMonitor(); ConfigurationMetadata<?> metadata = ConfigurationMetadata.getConfigurationMetadata(GetterNoReturnClass.class, monitor); Map<String, Set<String>> expectedAttributes = Maps.newHashMap(); verifyMetaData(metadata, GetterNoReturnClass.class, null, expectedAttributes); monitor.assertNumberOfErrors(1); monitor.assertNumberOfWarnings(0); monitor.assertMatchingErrorRecorded("No getter", "unusable", "getValue", "setValue"); }
@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 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"); }