@Test public void testExtractValue() throws Exception { field = TestConfig.class.getDeclaredField("testField"); PropertyValue propertyValue = field.getAnnotation(PropertyValue.class); CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class); List<Annotation> orderList = Lists.newArrayList(propertyValue, commandLineValue); when(annotationHelper.getAnnotationsInOrder( Matchers.any(Field.class), Matchers.any(Class[].class))) .thenReturn(orderList); String result = (String) fieldValueExtractor.extractValue(field, builderConfiguration); verify(annotationHelper).getAnnotationsInOrder(field, order); assertEquals("propertyValue", result); }
@Test public void testExtractValueWithNullValue() throws Exception { field = TestConfig.class.getDeclaredField("testField"); PropertyValue propertyValue = field.getAnnotation(PropertyValue.class); CommandLineValue commandLineValue = field.getAnnotation(CommandLineValue.class); List<Annotation> orderList = Lists.newArrayList(propertyValue, commandLineValue); when(annotationHelper.getAnnotationsInOrder( Matchers.any(Field.class), Matchers.any(Class[].class))) .thenReturn(orderList); when(propertyValueProcessor.getValue( Matchers.any(PropertyValue.class), Matchers.any(ConfigBuilderFactory.class))) .thenReturn(null); when(commandLineValueProcessor.getValue( Matchers.any(CommandLineValue.class), Matchers.any(ConfigBuilderFactory.class))) .thenReturn(null); Object result = fieldValueExtractor.extractValue(field, builderConfiguration); assertEquals(null, result); }