### Question:
DatabaseService implements IDatabaseService { @Override public byte[] getTableDump(String reportCode, String dataSource, String tableName) { File tempFile = null; byte[] bytes = null; try { InputStream stream = this.getDatabaseManager().getTableDump(tableName, dataSource, reportCode); if (null == stream) { logger.warn("no dump found with code {}, dataSource {}, table {}", reportCode, dataSource, tableName); BeanPropertyBindingResult bindingResult = new BeanPropertyBindingResult(tableName, "tableName"); bindingResult.reject(DatabaseValidator.ERRCODE_NO_TABLE_DUMP_FOUND, new Object[]{reportCode, dataSource, tableName}, "database.dump.table.notFound"); throw new ResourceNotFoundException("code - dataSource - table", "'" + reportCode + "' - '" + dataSource + "' - '" + tableName + "'"); } tempFile = FileTextReader.createTempFile(new Random().nextInt(100) + reportCode + "_" + dataSource + "_" + tableName, stream); bytes = FileTextReader.fileToByteArray(tempFile); } catch (ResourceNotFoundException r) { throw r; } catch (Throwable t) { logger.error("error extracting database dump with code {}, dataSource {}, table {}", reportCode, dataSource, tableName, t); throw new RestServerError("error extracting database dump", t); } finally { if (null != tempFile) { boolean deleted = tempFile.delete(); if (!deleted) { logger.warn("Failed to create temp file {}", tempFile.getAbsolutePath()); } } } return bytes; }  @Override int getStatus(); @Override PagedMetadata<ShortDumpReportDto> getShortDumpReportDtos(RestListRequest requestList); @Override DumpReportDto getDumpReportDto(String reportCode); @Override void deleteDumpReport(String reportCode); @Override List<ComponentDto> getCurrentComponents(); @Override void startDatabaseBackup(); @Override void startDatabaseRestore(String reportCode); @Override byte[] getTableDump(String reportCode, String dataSource, String tableName); IDatabaseManager getDatabaseManager(); void setDatabaseManager(IDatabaseManager databaseManager); IComponentManager getComponentManager(); void setComponentManager(IComponentManager componentManager);  }### Answer:
@Test public void getValidTableDump() throws Throwable { ByteArrayInputStream is = new ByteArrayInputStream("dump".getBytes()); when(databaseManager.getTableDump(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(is); byte[] base64 = this.databaseService.getTableDump("reportCode", "dataSourcePort", "categories"); Assert.assertNotNull(base64); }
@Test(expected = ResourceNotFoundException.class) public void getInValidTableDump_1() throws Throwable { when(databaseManager.getTableDump(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())).thenReturn(null); this.databaseService.getTableDump("reportCode", "dataSourcePort", "categories"); }
@Test(expected = RestServerError.class) public void getInValidTableDump_2() throws Throwable { when(databaseManager.getTableDump(ArgumentMatchers.anyString(), ArgumentMatchers.anyString(), ArgumentMatchers.anyString())) .thenThrow(new ApsSystemException("Error")); this.databaseService.getTableDump("reportCode", "dataSourcePort", "categories"); }