### Question:
Classes { public static <T> T getValueFromProtectedField(Object object, String fieldName) { Class<?> clazz = object.getClass(); try { Field field = clazz.getDeclaredField(fieldName); if (!field.isAccessible()) { field.setAccessible(true); } return (T) field.get(object); } catch (NoSuchFieldException | IllegalAccessException e) { throw new IllegalStateException("Cannot find field " + fieldName + " in class " + clazz.getName(), e); } } private  Classes(); static T instanciate(Class<? extends T> clazz); static boolean isPresent(String className); static Class<?> forName(String className); static T getValueFromProtectedField(Object object, String fieldName);  }### Answer:
@Test void getValueFromProtectedField_when_field_exists() { Object object = new Instanciable(); String existingFieldValue = Classes.getValueFromProtectedField(object, "existingField"); assertThat(existingFieldValue).as("Existing field value").isEqualTo("test"); }
@Test void getValueFromProtectedField_when_field_does_not_exist() { Object object = new Instanciable(); assertThatExceptionOfType(IllegalStateException.class) .isThrownBy(() -> Classes.getValueFromProtectedField(object, "missingField")) .withMessage("Cannot find field missingField in class com.github.fridujo.automocker.utils.ClassesTest$Instanciable"); }