@Test
public void testRemove() throws Exception {

  DynamicClassLoader classLoader = new DynamicClassLoader(DataStoreImplTest.class.getClassLoader());
  // create mocks
  JpaEntityManager jpaEntityManager = createMock(JpaEntityManager.class);
  ServerSession session = createMock(ServerSession.class);
  DatabaseLogin databaseLogin = createMock(DatabaseLogin.class);
  EntityManagerFactory entityManagerFactory = createMock(EntityManagerFactory.class);
  EntityManager entityManager = createMock(EntityManager.class);
  JPADynamicHelper jpaDynamicHelper = createNiceMock(JPADynamicHelper.class);
  SchemaManager schemaManager = createNiceMock(SchemaManager.class);
  EntityTransaction transaction = createMock(EntityTransaction.class);
  DynamicEntity dynamicEntity = createMock(DynamicEntity.class);
  // set expectations
  PowerMock.mockStatic(JpaHelper.class);
  expect(JpaHelper.getEntityManager(entityManager)).andReturn(jpaEntityManager).anyTimes();
  PowerMock.replay(JpaHelper.class);
  expect(jpaEntityManager.getServerSession()).andReturn(session).anyTimes();
  expect(session.getLogin()).andReturn(databaseLogin).anyTimes();
  Capture<Sequence> sequenceCapture = EasyMock.newCapture();
  databaseLogin.addSequence(capture(sequenceCapture));
  EasyMock.expectLastCall().anyTimes();
  Capture<DynamicType> typeCapture = EasyMock.newCapture();
  Capture<DynamicType> typeCapture2 = EasyMock.newCapture();
  jpaDynamicHelper.addTypes(eq(true), eq(true), capture(typeCapture), capture(typeCapture2));
  expect(entityManagerFactory.createEntityManager()).andReturn(entityManager).anyTimes();
  expect(entityManager.getTransaction()).andReturn(transaction).anyTimes();
  Capture<Class> entityClassCapture = EasyMock.newCapture();
  expect(entityManager.getReference(capture(entityClassCapture), eq(99))).andReturn(dynamicEntity);
  entityManager.remove(dynamicEntity);
  entityManager.close();
  transaction.begin();
  transaction.commit();
  // replay mocks
  replay(entityManagerFactory, entityManager, jpaDynamicHelper, transaction, schemaManager, dynamicEntity, jpaEntityManager, session, databaseLogin);
  DataStoreImpl dataStore = getDataStore(entityManagerFactory, jpaDynamicHelper, classLoader, schemaManager);
  dataStore.remove(new TestEntity(99, "foo", new TestSubEntity("bar")));
  if ((entityClassCapture.getValue() != typeCapture.getValue().getJavaClass()) &&
      (entityClassCapture.getValue() != typeCapture2.getValue().getJavaClass())) {
    Assert.fail();
  }
  // verify mocks
  verify(entityManagerFactory, entityManager, jpaDynamicHelper, transaction, schemaManager, dynamicEntity, jpaEntityManager, session, databaseLogin);
}