DDMFormInstanceModelListener extends BaseModelListener<DDMFormInstance> { @Override public void onBeforeRemove(DDMFormInstance ddmFormInstance) throws ModelListenerException { try { DDMFormInstanceReport ddmFormInstanceReport = ddmFormInstanceReportLocalService. getFormInstanceReportByFormInstanceId( ddmFormInstance.getFormInstanceId()); TransactionCommitCallbackUtil.registerCallback( () -> { _ddmFormInstanceReportPortalExecutor.execute( () -> ddmFormInstanceReportLocalService. deleteDDMFormInstanceReport( ddmFormInstanceReport. getFormInstanceReportId())); return null; }); } catch (Exception exception) { if (_log.isWarnEnabled()) { StringBundler sb = new StringBundler(4); sb.append("Unable to update dynamic data mapping form "); sb.append("instance report for dynamic data mapping form "); sb.append("instance "); sb.append(ddmFormInstance.getFormInstanceId()); _log.warn(sb.toString(), exception); } } }  @Override void onAfterCreate(DDMFormInstance ddmFormInstance); @Override void onBeforeRemove(DDMFormInstance ddmFormInstance);  }
@Test public void testOnBeforeRemove() throws PortalException { when( _ddmFormInstanceReportLocalService. getFormInstanceReportByFormInstanceId(Mockito.anyLong()) ).thenThrow( new NoSuchFormInstanceReportException() ); DDMFormInstance ddmFormInstance = mock(DDMFormInstance.class); when( ddmFormInstance.getFormInstanceId() ).thenReturn( 0L ); _ddmFormInstanceModelListener.onBeforeRemove(ddmFormInstance); }