DatabaseBackupServiceImpl implements DatabaseBackupService { @Override public synchronized byte[] exportDatabase() { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); XMLStreamWriter writer = null; try { writer = createXmlWriter(outputStream); exportDatabase(writer); return outputStream.toByteArray(); } catch (XMLStreamException e) { LOGGER.error(e); return new byte[0]; } finally { if (writer != null) { try { writer.close(); } catch (XMLStreamException e) { } } } } @Autowired  DatabaseBackupServiceImpl(BackupDao backupDao, ConfigurationService configurationService, BackupConfig backupConfig); @Override synchronized byte[] exportDatabase();  }
@SuppressWarnings("unchecked") @Test public void shouldProduceXml() { Map<String, Object> map = new HashMap<>(); map.put("ASSIGNMENT_ID", 1); map.put("ENTRY_DATE", new Date()); map.put("COMMENT", "\uC3BC and \uC3B6 and <&> für"); List<Map<String, Object>> rows = Lists.newArrayList(map); when(exportDao.findAll("TIMESHEET_ENTRY")).thenReturn(rows); EhourConfigStub configuration = new EhourConfigStub(); configuration.setVersion("0.9"); when(configurationService.getConfiguration()).thenReturn(configuration); List<Configuration> configurationList = Lists.newArrayList(new Configuration(ConfigurationItem.AVAILABLE_TRANSLATIONS.getDbField(), "nl")); when(configurationService.findAllConfiguration()).thenReturn(configurationList); byte[] xmlBytes = service.exportDatabase(); String xml = new String(xmlBytes); assertThat(xml, containsString("0.9")); assertThat(xml, containsString("TIMESHEET_ENTRY")); assertThat(xml, containsString("CONFIG")); assertTrue(xml.startsWith("<?xml version=")); }