use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class MapProxyTest method shouldGenerateClassWithAppropriateSetter.
@Test
public void shouldGenerateClassWithAppropriateSetter() throws Exception {
//given
Map<String, Object> map = new HashMap<String, Object>();
Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
properties.put("age", Integer.class);
//when
Class testClass = MapProxyTool.classForName("TestClass2", properties, new ClassLoaderServiceImpl());
Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
//then
Setter setter = ReflectionTools.getSetter(testClass, "age", "property", serviceRegistry);
int ageExpected = 14;
setter.set(testClassInstance, ageExpected, null);
Object age = map.get("age");
Assert.assertEquals(ageExpected, age);
}
use of org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl in project hibernate-orm by hibernate.
the class MapProxyTest method shouldGenerateClassWithAppropriateGetter.
@Test
public void shouldGenerateClassWithAppropriateGetter() throws Exception {
//given
Map<String, Object> map = new HashMap<String, Object>();
int ageExpected = 14;
map.put("age", ageExpected);
Map<String, Class<?>> properties = new HashMap<String, Class<?>>();
properties.put("age", Integer.class);
//when
Class testClass = MapProxyTool.classForName("TestClass1", properties, new ClassLoaderServiceImpl());
Object testClassInstance = testClass.getConstructor(Map.class).newInstance(map);
//then
Getter getter = ReflectionTools.getGetter(testClass, "age", "property", serviceRegistry);
int age = (Integer) getter.get(testClassInstance);
Assert.assertEquals(ageExpected, age);
}
Aggregations