DashboardItemDeletionHandler extends DeletionHandler { @Override public void deleteUser( User user ) { for ( DashboardItem item : dashboardService.getUserDashboardItems( user ) ) { while ( item.getUsers().contains( user ) ) { item.getUsers().remove( user ); } if ( item.getUsers().isEmpty() ) { dashboardService.deleteDashboardItem( item ); } } } DashboardItemDeletionHandler( DashboardService dashboardService ); @Override void deleteVisualization( Visualization visualization ); @Override void deleteReportTable( ReportTable reportTable ); @Override void deleteChart( Chart chart ); @Override void deleteEventChart( EventChart eventChart ); @Override void deleteMap( Map map ); @Override void deleteEventReport( EventReport eventReport ); @Override void deleteUser( User user ); @Override void deleteReport( Report report ); @Override void deleteDocument( Document document );  }
@Test public void testDeleteUser() { User userA = createUser( 'A' ); User userB = createUser( 'B' ); userService.addUser( userA ); userService.addUser( userB ); dashboardItem.getUsers().add ( userA ); dashboardItem.getUsers().add ( userA ); dashboardItem.getUsers().add ( userB ); dashboardService.saveDashboard( dashboard ); assertEquals(1, dashboardService.getUserDashboardItems( userA ).size() ); assertEquals(1, dashboardService.getUserDashboardItems( userB ).size() ); assertEquals( 1, dashboard.getItemCount() ); userService.deleteUser( userA ); assertEquals(0, dashboardService.getUserDashboardItems( userA ).size() ); assertEquals(1, dashboardService.getUserDashboardItems( userB ).size() ); assertEquals( 1, dashboard.getItemCount() ); userService.deleteUser( userB ); assertEquals(0, dashboardService.getUserDashboardItems( userA ).size() ); assertEquals(0, dashboardService.getUserDashboardItems( userB ).size() ); assertEquals( 0, dashboard.getItemCount() ); }