View Javadoc
1   package integrationTest.Bug258;
2   
3   import org.apache.commons.beanutils.BeanUtilsBean;
4   import org.apache.commons.beanutils.PropertyUtilsBean;
5   import org.junit.jupiter.api.Assertions;
6   import org.junit.jupiter.api.Disabled;
7   import org.junit.jupiter.api.DisplayName;
8   import org.junit.jupiter.api.Test;
9   
10  import java.lang.reflect.Field;
11  import java.lang.reflect.InvocationTargetException;
12  import java.lang.reflect.Modifier;
13  
14  public class BeanUtilsBeanTest {
15  
16      @Test
17      @Disabled("Disabled as this was just to test what was returned.")
18      @DisplayName("What does getProperties return on a new instance?")
19      public void whenNewInstance_thenGetPropertiesReturnOnNewInstance() throws InvocationTargetException, IllegalAccessException, NoSuchMethodException {
20          //ConvertUtilsBean readConverter = BeanUtilsBean.getInstance().getConvertUtils();
21          BeanUtilsBean beanUtilsBean = BeanUtilsBean.getInstance();
22          PropertyUtilsBean pb = beanUtilsBean.getPropertyUtils();
23          Assertions.assertNotNull(pb);
24      }
25  
26      public static boolean isStaticFieldInitialized(Class<?> clazz, String fieldName) {
27          try {
28              Field field = clazz.getDeclaredField(fieldName);
29              if (Modifier.isStatic(field.getModifiers())) {
30                  field.setAccessible(true); // Allow access to private fields
31                  Object value = field.get(null); // Pass null for static fields
32                  return value != null;
33              }
34          } catch (NoSuchFieldException | IllegalAccessException e) {
35              // Handle exceptions as needed
36              e.printStackTrace();
37          }
38          return false;
39      }
40  
41      @Test()
42      @DisplayName("Check that the static field is initialized.")
43      public void checkStaticFieldInitialized() {
44          Assertions.assertTrue(isStaticFieldInitialized(BeanUtilsBean.class, "BEANS_BY_CLASSLOADER"));
45      }
46  }