MethodUtil { public static void addEnumValues(Class<?> theClass, Builder builder) { if (theClass.isEnum()) { Object[] enumConstants = theClass.getEnumConstants(); for (Object object : enumConstants) { builder.option(object.toString(), object.toString()); } } } private  MethodUtil(); static Class<?>[] getAllInterfaces(Object serviceObject); static List<AttributeDefinition> buildAttributesList(Class<?> theClass); static void addEnumValues(Class<?> theClass, Builder builder); @SuppressWarnings("unchecked") static T buildBean(Class<T> beanClass, Map<String, String> values); static Map<String, PropertyEditor> getRelevantProperties(final Object bean); static Map<String, String> buildAttributeMap(Object bean); static T buildBeanFromAttributeMap(Class<T> beanClass, Map<String, String> values); static Object convertToCorrectClass(Class<?> type, Object value); static Constructor<?> getStringOnlyConstructor(Class<?> type);  }
@Test public void testAddEnumValues_shouldWork() throws Exception { StringLocalizer mock = Mockito.mock(StringLocalizer.class); LocalizableString mock2 = Mockito.mock(LocalizableString.class); LocalizableString mock3 = Mockito.mock(LocalizableString.class); when(mock2.getKey()).thenReturn("123"); when(mock2.getString(Locale.getDefault())).thenReturn("ONE"); when(mock2.getKey()).thenReturn("123"); when(mock3.getString(Locale.getDefault())).thenReturn("TWO"); when(mock.getString("ONE")).thenReturn(mock2); when(mock.getString("TWO")).thenReturn(mock2); Builder builder = AttributeDefinition.builder(mock); builder.name("ONE").id("123"); MethodUtil.addEnumValues(TestEnum.class, builder); AttributeDefinition build = builder.build(); List<Option> options = build.getOptions(); Option option0 = options.get(0); assertThat(option0.getLabel().getString(Locale.getDefault()), equalTo(TestEnum.ONE.toString())); assertThat(option0.getValue().toString(), equalTo(TestEnum.ONE.toString())); Option option1 = options.get(1); assertThat(option1.getLabel().getString(Locale.getDefault()), equalTo(TestEnum.ONE.toString())); assertThat(option1.getValue().toString(), equalTo(TestEnum.TWO.toString())); }