コード例 #1
0
  @Before
  public void setUp() throws Exception {
    when(builderConfiguration.getAnnotationOrder()).thenReturn(order);

    when(configBuilderFactory.getInstance(AnnotationHelper.class)).thenReturn(annotationHelper);
    when(configBuilderFactory.getInstance(PropertyValueProcessor.class))
        .thenReturn(propertyValueProcessor);
    when(configBuilderFactory.getInstance(CommandLineValueProcessor.class))
        .thenReturn(commandLineValueProcessor);
    when(configBuilderFactory.getInstance(DefaultValueProcessor.class))
        .thenReturn(defaultValueProcessor);

    when(propertyValueProcessor.getValue(
            Matchers.any(PropertyValue.class), Matchers.any(ConfigBuilderFactory.class)))
        .thenReturn("propertyValue");
    when(commandLineValueProcessor.getValue(
            Matchers.any(CommandLineValue.class), Matchers.any(ConfigBuilderFactory.class)))
        .thenReturn("commandLineValue");

    fieldValueExtractor = new FieldValueExtractor(configBuilderFactory);
  }
コード例 #2
0
  @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);
  }