### Question:
AbstractPropertyReflectingFilter implements ViolationFilter { @SuppressWarnings("unchecked") protected <T> T getInternalValue(final Violation violation, final String propertyName) { final String methodName = "get" + Character.toUpperCase(propertyName.charAt(0)) + propertyName.substring(1); try { final Method getter = violation.getClass().getDeclaredMethod(methodName); if (!getter.isAccessible()) { getter.setAccessible(true); } return (T) getter.invoke(violation); } catch (final IllegalArgumentException | IllegalAccessException | InvocationTargetException | NoSuchMethodException | SecurityException e) { LOGGER.trace("Failed to retrieve '{}' off of {}; moving on to field retrieval.", methodName, violation); LOGGER.trace("Tracing thrown exception during retrieval by method.", e); } try { final Field field = violation.getClass().getDeclaredField(propertyName); if (!field.isAccessible()) { field.setAccessible(true); } return (T) field.get(violation); } catch (final IllegalArgumentException | IllegalAccessException | NoSuchFieldException | SecurityException e) { LOGGER.trace("Failed to retrieve field by name '{}' off of {}.", propertyName, violation); LOGGER.trace("Tracing thrown exception during retrieval by field.", e); } return null; }    }### Answer:
@Test public void testGetInternalValueField() { final String expectedValue = "an.expected.value"; final Violation toFilter = new ViolationStub() { @SuppressWarnings("unused") private final String internalProperty = expectedValue; }; assertThat(filter.<String> getInternalValue(toFilter, "internalProperty")).isEqualTo(expectedValue); }
@Test public void testGetInternalValueGetter() { final String expectedValue = "the.expected.value"; final Violation toFilter = new ViolationStub() { @SuppressWarnings("unused") private String getInternalProperty() { return expectedValue; } }; assertThat(filter.<String> getInternalValue(toFilter, "internalProperty")).isEqualTo(expectedValue); }
@Test public void testGetInternalValueNotFound() { assertThat(filter.<String> getInternalValue(new ViolationStub(), "thisWillNeverEverBeAProperty")).isNull(); }