### Question:
DataModelerEventObserver { public void onDataObjectCreated(@Observes DataObjectCreatedEvent event) { Path descriptorPath; PersistenceDescriptorModel persistenceDescriptor; if (isPersistable(event.getCurrentDataObject())) { descriptorPath = descriptorService.calculatePersistenceDescriptorPath(event.getCurrentModule()); persistenceDescriptor = safeLoad(descriptorPath); if (persistenceDescriptor != null && !containsClass(persistenceDescriptor.getPersistenceUnit(), event.getCurrentDataObject().getClassName())) { persistenceDescriptor.getPersistenceUnit().getClasses().add(new PersistableDataObject(event.getCurrentDataObject().getClassName())); descriptorService.save(descriptorPath, persistenceDescriptor, null, "Entity added to persistence descriptor"); } } } DataModelerEventObserver(); @Inject  DataModelerEventObserver(final PersistenceDescriptorService descriptorService,
                                    final @Named("ioStrategy") IOService ioService); void onDataObjectCreated(@Observes DataObjectCreatedEvent event); void onDataObjectDeleted(@Observes DataObjectDeletedEvent event);  }### Answer:
@Test public void onPersistableDataObjectCreatedTest() { DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject); eventObserver.onDataObjectCreated(createdEvent); verify(descriptorService, times(1)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString()); assertTrue(descriptorModel.getPersistenceUnit().getClasses().contains(new PersistableDataObject(dataObject.getClassName()))); }
@Test public void onNonPersistableDataObjectCreatedTest() { descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject("package1.PersistableObject")); DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject); eventObserver.onDataObjectCreated(createdEvent); verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString()); assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size()); }
@Test public void onNonPersistableDataObjectDeletedTest() { DataObject dataObject = new DataObjectImpl("package1", "NonPersistableObject"); DataObjectCreatedEvent createdEvent = new DataObjectCreatedEvent(module, dataObject); eventObserver.onDataObjectCreated(createdEvent); descriptorModel.getPersistenceUnit().getClasses().add(new PersistableDataObject(createdEvent.getCurrentDataObject().getClassName())); verify(descriptorService, times(0)).save(eq(descriptorPath), eq(descriptorModel), any(Metadata.class), anyString()); assertEquals(1, descriptorModel.getPersistenceUnit().getClasses().size()); }