public class BaseBeanTest {
@SuppressWarnings("rawtypes")
@Test
public void testInitEntity() {
BaseBean backingBean = new BaseBean<TestEntity>(TestEntity.class) {
private static final long serialVersionUID = 1L;
@Override
protected IService<TestEntity> getPersistenceService() {
return new DummyPersistenceService();
}
};
// test new instance of TestEntity is created when objectId is not set.
IEntity initEntity = backingBean.initEntity();
Assert.assertNotNull(initEntity);
Assert.assertTrue(initEntity instanceof TestEntity);
Assert.assertNull(initEntity.getId());
backingBean.setObjectId(22L);
//
initEntity = backingBean.initEntity();
Assert.assertNotNull(initEntity);
Assert.assertTrue(initEntity instanceof TestEntity);
Assert.assertEquals(Long.valueOf(22L), initEntity.getId());
// not exist
backingBean.setObjectId(23L);
initEntity = backingBean.initEntity();
Assert.assertNull(initEntity);
}