### Question:
PropertyAccessor { public V getPropertyValue(T boundObject) { return readMethod.readValue(boundObject); } PropertyAccessor(Class<? extends T> boundClass, String propertyName); String getPropertyName(); V getPropertyValue(T boundObject); void setPropertyValue(T boundObject, @CheckForNull V value); void invoke(T boundObject); boolean canWrite(); boolean canInvoke(); boolean canRead(); Class<?> getValueClass();  }### Answer:
@Test public void testRead() { String propertyValue = stringAccessor.getPropertyValue(testObject); assertEquals(STRING_PROPERTY_INITIAL_VALUE, propertyValue); }
@Test public void testLongProperty() { PropertyAccessor<TestObject, Long> propertyAccessor = new PropertyAccessor<>(TestObject.class, TestObject.READ_ONLY_LONG_PROPERTY); Long propertyValue = propertyAccessor.getPropertyValue(testObject); assertEquals(42, propertyValue.longValue()); }
@Test public void testDefaultMethod() { PropertyAccessor<TestInterface, String> propertyAccessor = new PropertyAccessor<>(TestInterfaceImpl.class, TestInterface.RO_DEFAULT_METHOD); TestInterface testInterfaceImpl = new TestInterfaceImpl(); String propertyValue = propertyAccessor.getPropertyValue(testInterfaceImpl); assertEquals("Hello", propertyValue); }
@Test public void testDefaultMethod_InSubclass() { PropertyAccessor<TestInterface, String> propertyAccessor = new PropertyAccessor<>( TestInterfaceImplSub.class, TestInterface.RO_DEFAULT_METHOD); TestInterface testInterfaceImpl = new TestInterfaceImplSub(); String propertyValue = propertyAccessor.getPropertyValue(testInterfaceImpl); assertEquals("Hello", propertyValue); }
@Test public void testDefaultMethod_OverwrittenInSubclass() { PropertyAccessor<TestInterface, String> propertyAccessor = new PropertyAccessor<>( TestInterfaceOverwriting.class, TestInterface.RO_DEFAULT_METHOD); TestInterface testInterfaceImpl = new TestInterfaceOverwriting(); String propertyValue = propertyAccessor.getPropertyValue(testInterfaceImpl); assertEquals("Hi", propertyValue); }
@Test public void testDefaultMethod_OtherPackage() { PropertyAccessor<TestInterface, String> propertyAccessor = new PropertyAccessor<>( OtherPackageTestObject.class, TestInterface.RO_DEFAULT_METHOD); TestInterface testInterfaceImpl = new OtherPackageTestObject(); String propertyValue = propertyAccessor.getPropertyValue(testInterfaceImpl); assertEquals("other", propertyValue); }
@Test public void testDefaultMethod_OtherPackagePrivate() { TestInterface testInterfaceImpl = OtherPackageTestObject.getPackagePrivateInstance(); PropertyAccessor<TestInterface, String> propertyAccessor = new PropertyAccessor<>( testInterfaceImpl.getClass(), TestInterface.RO_DEFAULT_METHOD); String propertyValue = propertyAccessor.getPropertyValue(testInterfaceImpl); assertEquals("otherPackage", propertyValue); }
@Test public void testDefaultMethod_OtherPackageProtected() { PropertyAccessor<TestPublicSubclass, Integer> propertyAccessor = new PropertyAccessor<>( TestPublicSubclass.class, TestPublicSubclass.PROPERTY_ANSWER); int propertyValue = propertyAccessor.getPropertyValue(new TestPublicSubclass()); assertEquals(42, propertyValue); }