From 2fdb124ef2b69cb3e6b981a40a90eb38ce9bb4a6 Mon Sep 17 00:00:00 2001 From: Song Zhiwen Date: Tue, 3 Jan 2017 18:17:59 +0800 Subject: [PATCH] [#130] Change file extension requirement from .txt to .xml (#132) * change file ext requirement from txt to xml * test script change --- .gitignore | 2 +- doc/UserGuide.md | 6 +++--- src/seedu/addressbook/storage/StorageFile.java | 8 ++++---- .../StorageFileTest/{InvalidData.txt => InvalidData.xml} | 0 .../data/StorageFileTest/{ValidData.txt => ValidData.xml} | 0 test/expected.txt | 2 +- test/java/seedu/addressbook/storage/StorageFileTest.java | 8 ++++---- 7 files changed, 13 insertions(+), 13 deletions(-) rename test/data/StorageFileTest/{InvalidData.txt => InvalidData.xml} (100%) rename test/data/StorageFileTest/{ValidData.txt => ValidData.xml} (100%) diff --git a/.gitignore b/.gitignore index 0b30e2916..8a18db8d7 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,6 @@ # Default storage file for addressbook : don't need to cleanup when running from IDE -addressbook.txt +addressbook.xml # Compiled classfiles bin/ diff --git a/doc/UserGuide.md b/doc/UserGuide.md index d38914a95..2f4e37b34 100644 --- a/doc/UserGuide.md +++ b/doc/UserGuide.md @@ -123,13 +123,13 @@ Address book data are saved in the hard disk automatically after any command tha There is no need to save manually. #### Changing the save location -Address book data are saved in a file called `addressbook.txt` in the project root folder. +Address book data are saved in a file called `addressbook.xml` in the project root folder. You can change the location by specifying the file path as a program argument. Example: -* `java seedu.addressbook.Main mydata.txt` +* `java seedu.addressbook.Main mydata.xml` -> The file name must end in `.txt` for it to be acceptable to the program. +> The file name must end in `.xml` for it to be acceptable to the program. > > When running the program inside Eclipse, you can set command line parameters before running the program. diff --git a/src/seedu/addressbook/storage/StorageFile.java b/src/seedu/addressbook/storage/StorageFile.java index 684559a1b..92ff9c3f1 100644 --- a/src/seedu/addressbook/storage/StorageFile.java +++ b/src/seedu/addressbook/storage/StorageFile.java @@ -26,7 +26,7 @@ public class StorageFile { /** Default file path used if the user doesn't provide the file name. */ - public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.txt"; + public static final String DEFAULT_STORAGE_FILEPATH = "addressbook.xml"; /* Note: Note the use of nested classes below. * More info https://docs.oracle.com/javase/tutorial/java/javaOO/nested.html @@ -74,16 +74,16 @@ public StorageFile(String filePath) throws InvalidStorageFilePathException { path = Paths.get(filePath); if (!isValidPath(path)) { - throw new InvalidStorageFilePathException("Storage file should end with '.txt'"); + throw new InvalidStorageFilePathException("Storage file should end with '.xml'"); } } /** * Returns true if the given path is acceptable as a storage file. - * The file path is considered acceptable if it ends with '.txt' + * The file path is considered acceptable if it ends with '.xml' */ private static boolean isValidPath(Path filePath) { - return filePath.toString().endsWith(".txt"); + return filePath.toString().endsWith(".xml"); } /** diff --git a/test/data/StorageFileTest/InvalidData.txt b/test/data/StorageFileTest/InvalidData.xml similarity index 100% rename from test/data/StorageFileTest/InvalidData.txt rename to test/data/StorageFileTest/InvalidData.xml diff --git a/test/data/StorageFileTest/ValidData.txt b/test/data/StorageFileTest/ValidData.xml similarity index 100% rename from test/data/StorageFileTest/ValidData.txt rename to test/data/StorageFileTest/ValidData.xml diff --git a/test/expected.txt b/test/expected.txt index eb43494c6..a57efcc33 100644 --- a/test/expected.txt +++ b/test/expected.txt @@ -3,7 +3,7 @@ || Welcome to your Address Book! || AddessBook Level 2 - Version 1.0 || Launch command format: java seedu.addressbook.Main [STORAGE_FILE_PATH] -|| Using storage file : addressbook.txt +|| Using storage file : addressbook.xml || =================================================== || Enter command: || [Command entered: sfdfd] || add: Adds a person to the address book. Contact details can be marked private by prepending 'p' to the prefix. diff --git a/test/java/seedu/addressbook/storage/StorageFileTest.java b/test/java/seedu/addressbook/storage/StorageFileTest.java index 1bd6fcab3..3c0db33e2 100644 --- a/test/java/seedu/addressbook/storage/StorageFileTest.java +++ b/test/java/seedu/addressbook/storage/StorageFileTest.java @@ -44,14 +44,14 @@ public void constructor_noTxtExtension_exceptionThrown() throws Exception { @Test public void load_invalidFormat_exceptionThrown() throws Exception { // The file contains valid xml data, but does not match the AddressBook class - StorageFile storage = getStorage("InvalidData.txt"); + StorageFile storage = getStorage("InvalidData.xml"); thrown.expect(StorageOperationException.class); storage.load(); } @Test public void load_validFormat() throws Exception { - AddressBook actualAB = getStorage("ValidData.txt").load(); + AddressBook actualAB = getStorage("ValidData.xml").load(); AddressBook expectedAB = getTestAddressBook(); // ensure loaded AddressBook is properly constructed with test data @@ -72,7 +72,7 @@ public void save_validAddressBook() throws Exception { StorageFile storage = getTempStorage(); storage.save(ab); - assertStorageFilesEqual(storage, getStorage("ValidData.txt")); + assertStorageFilesEqual(storage, getStorage("ValidData.xml")); } // getPath() method in StorageFile class is trivial so it is not tested @@ -89,7 +89,7 @@ private StorageFile getStorage(String fileName) throws Exception { } private StorageFile getTempStorage() throws Exception { - return new StorageFile(testFolder.getRoot().getPath() + "/" + "temp.txt"); + return new StorageFile(testFolder.getRoot().getPath() + "/" + "temp.xml"); } private AddressBook getTestAddressBook() throws Exception {