Skip to content

Commit

Permalink
Merge pull request #126 from zhixianggg/branch-model-manager
Browse files Browse the repository at this point in the history
Integration Testing
  • Loading branch information
yan-wl authored Oct 16, 2019
2 parents 6d9118d + c1ba48b commit fa35406
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 33 deletions.
80 changes: 65 additions & 15 deletions src/main/java/seedu/address/MainApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,11 @@
import seedu.address.commons.util.StringUtil;
import seedu.address.logic.Logic;
import seedu.address.logic.LogicManager;
import seedu.address.model.CustomerBook;
import seedu.address.model.Model;
import seedu.address.model.ModelManager;
import seedu.address.model.OrderBook;
import seedu.address.model.PhoneBook;
import seedu.address.model.ReadOnlyDataBook;
import seedu.address.model.ReadOnlyUserPrefs;
import seedu.address.model.ScheduleBook;
Expand Down Expand Up @@ -92,26 +95,73 @@ public void init() throws Exception {
* or an empty address book will be used instead if errors occur when reading {@code storage}'s address book.
*/
private Model initModelManager(Storage storage, ReadOnlyUserPrefs userPrefs) {
/*Optional<ReadOnlyAddressBook> addressBookOptional;
ReadOnlyAddressBook initialData;
Optional<ReadOnlyDataBook<Customer>> customerBookOptional;
Optional<ReadOnlyDataBook<Phone>> phoneBookOptional;
Optional<ReadOnlyDataBook<Order>> orderBookOptional;

ReadOnlyDataBook<Customer> initialCustomerData;
ReadOnlyDataBook<Phone> initialPhoneData;
ReadOnlyDataBook<Order> initialOrderData;

try {
addressBookOptional = storage.readAddressBook();
if (!addressBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample AddressBook");
customerBookOptional = storage.readCustomerBook();

if (!customerBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample CustomerBook");
}
initialData = addressBookOptional.orElseGet(SampleDataUtil::getSampleAddressBook);
initialCustomerData = customerBookOptional.orElseGet(SampleDataUtil::getSampleCustomerBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty AddressBook");
initialData = new AddressBook();
logger.warning("Data file not in the correct format. Will be starting with an empty CustomerBook");
initialCustomerData = new CustomerBook();

} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty AddressBook");
initialData = new AddressBook();
}*/
logger.warning("Problem while reading from the file. Will be starting with an empty CustomerBook");
initialCustomerData = new CustomerBook();
}

try {
phoneBookOptional = storage.readPhoneBook();

if (!phoneBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample PhoneBook");
}

initialPhoneData = phoneBookOptional.orElseGet(SampleDataUtil::getSamplePhoneBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty PhoneBook");
initialPhoneData = new PhoneBook();

} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty PhoneBook");
initialPhoneData = new PhoneBook();
}

try {
orderBookOptional = storage.readOrderBook();

if (!orderBookOptional.isPresent()) {
logger.info("Data file not found. Will be starting with a sample OrderBook");
}

initialOrderData = orderBookOptional.orElseGet(SampleDataUtil::getSampleOrderBook);

} catch (DataConversionException e) {
logger.warning("Data file not in the correct format. Will be starting with an empty OrderBook");

initialOrderData = new OrderBook();

} catch (IOException e) {
logger.warning("Problem while reading from the file. Will be starting with an empty OrderBook");
initialOrderData = new OrderBook();
}

//ReadOnlyDataBook<Customer> customerBook = SampleDataUtil.getSampleCustomerBook();
//ReadOnlyDataBook<Phone> phoneBook = SampleDataUtil.getSamplePhoneBook();
//ReadOnlyDataBook<Order> orderBook = SampleDataUtil.getSampleOrderBook();

ReadOnlyDataBook<Customer> customerBook = SampleDataUtil.getSampleCustomerBook();
ReadOnlyDataBook<Phone> phoneBook = SampleDataUtil.getSamplePhoneBook();
ReadOnlyDataBook<Order> orderBook = SampleDataUtil.getSampleOrderBook();
return new ModelManager(customerBook, phoneBook, orderBook, new ScheduleBook(), userPrefs);
return new ModelManager(initialCustomerData, initialPhoneData, initialOrderData, new ScheduleBook(), userPrefs);

}

Expand Down
18 changes: 0 additions & 18 deletions src/main/java/seedu/address/logic/LogicManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,27 +51,9 @@ public CommandResult execute(String commandText) throws CommandException, ParseE
Command command = addressBookParser.parseCommand(commandText);
commandResult = command.execute(model);

try {
storage.saveAddressBook(model.getAddressBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveCustomerBook(model.getCustomerBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.savePhoneBook(model.getPhoneBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveScheduleBook(model.getScheduleBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
}
try {
storage.saveOrderBook(model.getOrderBook());
} catch (IOException ioe) {
throw new CommandException(FILE_OPS_ERROR_MESSAGE + ioe, ioe);
Expand Down

0 comments on commit fa35406

Please sign in to comment.