-
Notifications
You must be signed in to change notification settings - Fork 163
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[T6A1][W10-B4]Goh Yue Quan #432
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.addressbook.storage; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.data.exception.IllegalValueException; | ||
|
||
public abstract class Storage { | ||
|
||
/** | ||
* Signals that some error has occured while trying to convert and read/write data between the application | ||
* and the storage file. | ||
*/ | ||
public static class StorageOperationException extends Exception { | ||
public StorageOperationException(String message) { | ||
super(message); | ||
} | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
/** | ||
* Signals that the given file path does not fulfill the storage filepath constraints. | ||
*/ | ||
public static class InvalidStoragePathException extends IllegalValueException { | ||
public InvalidStoragePathException(String message) { | ||
super(message); | ||
} | ||
} | ||
|
||
public abstract void save(AddressBook addressBook) throws StorageOperationException; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
|
||
public abstract AddressBook load() throws StorageOperationException; | ||
|
||
public abstract String getPath(); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,6 @@ | |
import seedu.addressbook.data.person.*; | ||
import seedu.addressbook.data.tag.Tag; | ||
import seedu.addressbook.data.tag.UniqueTagList; | ||
import seedu.addressbook.storage.StorageFile; | ||
|
||
import java.util.*; | ||
|
||
|
@@ -28,16 +27,16 @@ public class LogicTest { | |
@Rule | ||
public TemporaryFolder saveFolder = new TemporaryFolder(); | ||
|
||
private StorageFile saveFile; | ||
private StorageStub storageStub; | ||
private AddressBook addressBook; | ||
private Logic logic; | ||
|
||
@Before | ||
public void setup() throws Exception { | ||
saveFile = new StorageFile(saveFolder.newFile("testSaveFile.txt").getPath()); | ||
storageStub = new StorageStub(); | ||
addressBook = new AddressBook(); | ||
saveFile.save(addressBook); | ||
logic = new Logic(saveFile, addressBook); | ||
storageStub.save(addressBook); | ||
logic = new Logic(storageStub, addressBook); | ||
} | ||
|
||
@Test | ||
|
@@ -90,7 +89,7 @@ private void assertCommandBehavior(String inputCommand, | |
//Confirm the state of data is as expected | ||
assertEquals(expectedAddressBook, addressBook); | ||
assertEquals(lastShownList, logic.getLastShownList()); | ||
assertEquals(addressBook, saveFile.load()); | ||
assertEquals(null, storageStub.load()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 You are the only one to have identified this. You can simply just remove the line 😄 |
||
} | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package seedu.addressbook.logic; | ||
|
||
import seedu.addressbook.data.AddressBook; | ||
import seedu.addressbook.storage.Storage; | ||
import seedu.addressbook.storage.Storage.StorageOperationException; | ||
|
||
public class StorageStub extends Storage { | ||
|
||
@Override | ||
public AddressBook load() throws StorageOperationException { | ||
return null; | ||
} | ||
|
||
@Override | ||
public String getPath() { | ||
return null; | ||
} | ||
|
||
@Override | ||
public void save(AddressBook addressBook) throws StorageOperationException { | ||
|
||
} | ||
|
||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 Very nice. Minimalist and in the correct directory. ⭐️ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 Good attempt at applying DIP.
The creating of
StorageFile
is a little unfortunate, but nonetheless has to be done. The original design already violates OCP. Fyi, an issue has been raised regarding this se-edu/addressbook-level3#75