RdfToPojoLoader { public void loadResourceByReflection(String resource, String graph, Object entity, DescriptorFactory descriptorFactory) throws RdfUtilsException { ReflectionLoader entityWrap = new ReflectionLoader(descriptorFactory, entity); entityWrap.initialize(); loadResource(resource, graph, entityWrap); } RdfToPojoLoader(BackendRdfSource source); void loadResource(String resource, String graph, Loadable entity); void loadResourceByReflection(String resource, String graph,
            Object entity, DescriptorFactory descriptorFactory);  }
@Test public void loadByReflection() throws RdfUtilsException, NoSuchFieldException { SimpleStore store = new SimpleStore(Arrays.asList( new SimpleTriple("resource", "title", new SimpleValue("TestObjectTitle", false)), new SimpleTriple("resource", "object", new SimpleValue("ref", true)), new SimpleTriple("ref", "title", new SimpleValue("InnerObject", false)) )); Descriptor descriptor = Mockito.mock(Descriptor.class); Mockito.when(descriptor.getFieldForResource()).thenReturn( TestObject.class.getDeclaredField("resource") ); Mockito.when(descriptor.getFieldForPredicate("title")).thenReturn( TestObject.class.getDeclaredField("title") ); Mockito.when(descriptor.getFieldForPredicate("object")).thenReturn( TestObject.class.getDeclaredField("object") ); DescriptorFactory descriptorFactory = Mockito.mock(DescriptorFactory.class); Mockito.when(descriptorFactory.create(Mockito.any())) .thenReturn(descriptor); RdfToPojoLoader loader = new RdfToPojoLoader(store); TestObject testObject = new TestObject(); loader.loadResourceByReflection("resource", "", testObject, descriptorFactory); Assert.assertEquals("resource", testObject.resource); Assert.assertEquals("TestObjectTitle", testObject.title); Assert.assertNotNull(testObject.object); Assert.assertEquals("ref", testObject.object.resource); Assert.assertEquals("InnerObject", testObject.object.title); }