@Test public void testExportImport() throws Exception { File exportFile = new File(testDir, "ExportImportTest-" + System.currentTimeMillis() + ".txt"); addressBook.export(exportFile, null); File tmpAddressBookFile = new File(testDir, "ExportImportAB-" + System.currentTimeMillis()); AddressBook tmpAddressBook = new AddressBook(tmpAddressBookFile, passwordHolder); FileInputStream fis = new FileInputStream(exportFile); try { tmpAddressBook.importFromFileDescriptor(fis.getFD(), null, false, false); SortedSet<Contact> start = addressBook.getAll(); SortedSet<Contact> end = tmpAddressBook.getAll(); for (Contact contact : start) { assertThat(contact, isIn(end)); } for (Contact contact : end) { assertThat(contact, isIn(start)); } } finally { try { fis.close(); } catch (IOException e) { } assertTrue("Can't delete file: " + exportFile.getAbsolutePath(), exportFile.delete()); assertTrue("Can't delete file: " + tmpAddressBookFile.getAbsolutePath(), tmpAddressBookFile.delete()); } } }