### Question:
IdGenerator { public Object generateAndSetId(Object e, EntityMetadata m, PersistenceDelegator pd, final KunderaMetadata kunderaMetadata) { Metamodel metamodel = KunderaMetadataManager.getMetamodel(kunderaMetadata, m.getPersistenceUnit()); Client<?> client = pd.getClient(m); return generateId(e, m, client, kunderaMetadata); }  Object generateAndSetId(Object e, EntityMetadata m, PersistenceDelegator pd,
            final KunderaMetadata kunderaMetadata);  }### Answer:
@Test public void testAutoStrategy() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { IdGenerator idGenerator = new IdGenerator(); GeneratedIdStrategyAuto autoStrategy = new GeneratedIdStrategyAuto(); autoStrategy.setName("auto strategy"); Assert.assertEquals(0, autoStrategy.getId()); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, GeneratedIdStrategyAuto.class); idGenerator.generateAndSetId(autoStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); Assert.assertTrue(autoStrategy.getId() > 0); }
@Test public void testSequenceStrategy() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { IdGenerator idGenerator = new IdGenerator(); GeneratedIdStrategySequence seqStrategy = new GeneratedIdStrategySequence(); seqStrategy.setName("sequence strategy"); Assert.assertEquals(0, seqStrategy.getId()); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, GeneratedIdStrategySequence.class); idGenerator.generateAndSetId(seqStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); Assert.assertTrue(seqStrategy.getId() > 0); try { setInvalidClient(CoreTestUtilities.getDelegator(em)); idGenerator.generateAndSetId(seqStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); Assert.fail("Should have gone to catch block!"); } catch (IllegalArgumentException iaex) { Assert.assertNotNull(iaex); } }
@Test public void testIdentityStrategy() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { IdGenerator idGenerator = new IdGenerator(); GeneratedIdStrategyIdentity identityStrategy = new GeneratedIdStrategyIdentity(); identityStrategy.setName("identity strategy"); Assert.assertEquals(0, identityStrategy.getId()); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, GeneratedIdStrategyIdentity.class); try { idGenerator.generateAndSetId(identityStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); } catch (UnsupportedOperationException usex) { Assert.assertNotNull(usex); } }
@Test public void testTableStrategy() throws NoSuchFieldException, SecurityException, IllegalArgumentException, IllegalAccessException { IdGenerator idGenerator = new IdGenerator(); GeneratedIdStrategyTable tableStrategy = new GeneratedIdStrategyTable(); tableStrategy.setName("table strategy"); Assert.assertEquals(0, tableStrategy.getId()); EntityMetadata entityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, GeneratedIdStrategyTable.class); idGenerator .generateAndSetId(tableStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); Assert.assertTrue(tableStrategy.getId() > 0); try { setInvalidClient(CoreTestUtilities.getDelegator(em)); idGenerator.generateAndSetId(tableStrategy, entityMetadata, CoreTestUtilities.getDelegator(em), kunderaMetadata); Assert.fail("Should have gone to catch block!"); } catch (IllegalArgumentException iaex) { Assert.assertNotNull(iaex); } }