Skip to content

Commit

Permalink
[#130] Change file extension requirement from .txt to .xml (#132)
Browse files Browse the repository at this point in the history
* change file ext requirement from txt to xml

* test script change
  • Loading branch information
zzzzwen authored and pyokagan committed Jan 3, 2017
1 parent a909e09 commit 2fdb124
Show file tree
Hide file tree
Showing 7 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -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/
Expand Down
6 changes: 3 additions & 3 deletions doc/UserGuide.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
8 changes: 4 additions & 4 deletions src/seedu/addressbook/storage/StorageFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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");
}

/**
Expand Down
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion test/expected.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
8 changes: 4 additions & 4 deletions test/java/seedu/addressbook/storage/StorageFileTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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 {
Expand Down

0 comments on commit 2fdb124

Please sign in to comment.