GetOptionLabelFunction implements DDMExpressionFieldAccessorAware,
			   DDMExpressionFunction.Function2<String, String, Object>,
			   LocaleAware { @Override public Object apply(String fieldName, String optionName) { if (_ddmExpressionFieldAccessor == null) { return StringPool.BLANK; } GetFieldPropertyRequest.Builder builder = GetFieldPropertyRequest.Builder.newBuilder(fieldName, "options"); GetFieldPropertyResponse getFieldPropertyResponse = _ddmExpressionFieldAccessor.getFieldProperty(builder.build()); DDMFormFieldOptions ddmFormFieldOptions = (DDMFormFieldOptions)getFieldPropertyResponse.getValue(); LocalizedValue localizedValue = ddmFormFieldOptions.getOptionLabels( optionName); if (_locale != null) { return localizedValue.getString(_locale); } return localizedValue.getString(localizedValue.getDefaultLocale()); }  @Override Object apply(String fieldName, String optionName); @Override String getName(); @Override void setDDMExpressionFieldAccessor(
		DDMExpressionFieldAccessor ddmExpressionFieldAccessor); @Override void setLocale(Locale locale); static final String NAME; }
@Test public void testApply() { DefaultDDMExpressionFieldAccessor ddmExpressionFieldAccessor = new DefaultDDMExpressionFieldAccessor(); DDMFormFieldOptions ddmFormFieldOptions = mock( DDMFormFieldOptions.class); LocalizedValue localizedValue = new LocalizedValue(); localizedValue.addString(LocaleUtil.US, "Option 1"); localizedValue.addString(LocaleUtil.BRAZIL, "Opcao 1"); when( ddmFormFieldOptions.getOptionLabels(Mockito.eq("optionName")) ).thenReturn( localizedValue ); GetFieldPropertyResponse.Builder builder = GetFieldPropertyResponse.Builder.newBuilder(ddmFormFieldOptions); ddmExpressionFieldAccessor.setGetFieldPropertyResponseFunction( getFieldPropertyRequest -> builder.build()); _getOptionLabelFunction.setDDMExpressionFieldAccessor( ddmExpressionFieldAccessor); _getOptionLabelFunction.setLocale(LocaleUtil.BRAZIL); Assert.assertEquals( "Opcao 1", _getOptionLabelFunction.apply("fieldName", "optionName")); }
@Test public void testApplyWithNullDDMExpressionFieldAccessor() { Object result = _getOptionLabelFunction.apply( "fieldName", "optionName"); Assert.assertEquals(StringPool.BLANK, result); }