### Question:
DataSourceService extends BaseService { @Transactional(rollbackFor = RuntimeException.class) public Result delete(User loginUser, int datasourceId) { Result result = new Result(); try { DataSource dataSource = dataSourceMapper.selectById(datasourceId); if (dataSource == null) { logger.error("resource id {} not exist", datasourceId); putMsg(result, Status.RESOURCE_NOT_EXIST); return result; } if (!hasPerm(loginUser, dataSource.getUserId())) { putMsg(result, Status.USER_NO_OPERATION_PERM); return result; } dataSourceMapper.deleteById(datasourceId); datasourceUserMapper.deleteByDatasourceId(datasourceId); putMsg(result, Status.SUCCESS); } catch (Exception e) { logger.error("delete datasource error", e); throw new RuntimeException("delete datasource error"); } return result; }  Map<String, Object> createDataSource(User loginUser, String name, String desc, DbType type, String parameter); Map<String, Object> updateDataSource(int id, User loginUser, String name, String desc, DbType type, String parameter); Map<String, Object> queryDataSource(int id); Map<String, Object> queryDataSourceListPaging(User loginUser, String searchVal, Integer pageNo, Integer pageSize); Map<String, Object> queryDataSourceList(User loginUser, Integer type); Result verifyDataSourceName(String name); boolean checkConnection(DbType type, String parameter); boolean connectionTest(int id); String buildParameter(DbType type, String host,
                                 String port, String database, String principal, String userName,
                                 String password, DbConnectType connectType, String other); @Transactional(rollbackFor = RuntimeException.class) Result delete(User loginUser, int datasourceId); Map<String, Object> unauthDatasource(User loginUser, Integer userId); Map<String, Object> authedDatasource(User loginUser, Integer userId); static final String NAME; static final String NOTE; static final String TYPE; static final String HOST; static final String PORT; static final String PRINCIPAL; static final String DATABASE; static final String USER_NAME; static final String OTHER; }### Answer:
@Test public void deleteTest() { User loginUser = getAdminUser(); int dataSourceId = 1; Result result = new Result(); dataSourceService.putMsg(result, Status.RESOURCE_NOT_EXIST); PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(null); Assert.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode()); dataSourceService.putMsg(result, Status.USER_NO_OPERATION_PERM); DataSource dataSource = new DataSource(); dataSource.setUserId(0); PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); Assert.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode()); dataSourceService.putMsg(result, Status.SUCCESS); dataSource.setUserId(-1); PowerMockito.when(dataSourceMapper.selectById(dataSourceId)).thenReturn(dataSource); Assert.assertEquals(result.getCode(), dataSourceService.delete(loginUser, dataSourceId).getCode()); }