Skip to content

Commit

Permalink
Merge pull request #243 from Mudaafi/junit-fix-commanddatelisttag
Browse files Browse the repository at this point in the history
Fixed JUnit test for CommandDateListTest.
  • Loading branch information
Mudaafi authored Nov 7, 2019
2 parents a65c18c + 4920f55 commit 1a8401e
Show file tree
Hide file tree
Showing 15 changed files with 50 additions and 30 deletions.
21 changes: 18 additions & 3 deletions src/main/java/executor/Executor.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,37 @@ public static Command createCommand(CommandType commandType, String userInput) {
return c;
}

/**
* Accesses the requested data from the Storage Layer.
* @param accessType AccessType representing the data to be accessed
* @param argsStr String any other String arguments
* @return InfoCapsule containing the result of the request
*/
public InfoCapsule access(AccessType accessType, String argsStr) {
Accessor accessor = Executor.createAccessor(accessType, argsStr);
Accessor accessor = Executor.createAccessor(accessType);
accessor.execute(this.storageLayer);
return accessor.getInfoCapsule();
}

public static Accessor createAccessor(AccessType accessType, String argsStr) {
/**
* Creates the Accessor Class given the AccessType.
* @param accessType AccessType of the Accessor to be created
* @return Accessor Object
*/
public static Accessor createAccessor(AccessType accessType) {
Accessor accessor;
try {
accessor = (Accessor) accessType.getAccessClass().getDeclaredConstructor().newInstance();
} catch (Exception e) {
accessor = new AccessDeny(argsStr);
accessor = new AccessDeny();
}
return accessor;
}

/**
* Saves all Data.
* @return InfoCapsule detailing any error messages that could occur.
*/
public InfoCapsule saveAllData() {
InfoCapsule infoCapsule = new InfoCapsule();
try {
Expand Down
7 changes: 4 additions & 3 deletions src/main/java/executor/accessors/AccessDeny.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,17 @@

public class AccessDeny extends Accessor {

public AccessDeny(String argsStr) {
/**
* Constructor for AccessDeny Class.
*/
public AccessDeny() {
super();
this.accessType = AccessType.DENY;
this.argsStr = argsStr;
}

@Override
public void execute(StorageManager storageManager) {
this.infoCapsule.setCodeError();
this.infoCapsule.setOutputStr("Access Denied");

}
}
2 changes: 1 addition & 1 deletion src/main/java/executor/accessors/AccessPieChartData.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
public class AccessPieChartData extends Accessor {

/**
* Constructor for AccessPieChartData
* Constructor for AccessPieChartData.
*/
public AccessPieChartData() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/executor/accessors/AccessTaskList.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class AccessTaskList extends Accessor {

/**
* Constructor for AccessTaskList Class
* Constructor for AccessTaskList Class.
*/
public AccessTaskList() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/executor/accessors/AccessWallet.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class AccessWallet extends Accessor {

/**
* Constructor for AccessWallet Class
* Constructor for AccessWallet Class.
*/
public AccessWallet() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/executor/accessors/AccessWalletBalance.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public class AccessWalletBalance extends Accessor {

/**
* Constructor for AccessWalletBalance Class
* Constructor for AccessWalletBalance Class.
*/
public AccessWalletBalance() {
super();
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/executor/accessors/AccessWalletExpenses.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
public class AccessWalletExpenses extends Accessor {

/**
* Constructor for AccessExpenses
* Constructor for AccessExpenses.
*/
public AccessWalletExpenses() {
super();
Expand Down
11 changes: 4 additions & 7 deletions src/main/java/executor/accessors/Accessor.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@

public abstract class Accessor {
protected AccessType accessType;
protected String argsStr;
protected InfoCapsule infoCapsule;

/**
* Constructor for Accessor Class.
*/
public Accessor() {
this.accessType = AccessType.DENY;
this.infoCapsule = new InfoCapsule();
Expand All @@ -18,8 +20,7 @@ public Accessor() {
}

/**
* Executes the Accessor Method to Obtain Information for the UI
* @return InfoCapsule containing the desired information
* Executes the Accessor Method to Obtain Information for the UI.
*/
public abstract void execute(StorageManager storageManager);

Expand All @@ -32,8 +33,4 @@ public InfoCapsule getInfoCapsule() {
public AccessType getAccessType() {
return this.accessType;
}

public String getArgsStr() {
return this.argsStr;
}
}
2 changes: 1 addition & 1 deletion src/main/java/storage/StorageManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public StorageManager() {
this.initializationStatus = "";
}

public void saveAllData() throws DukeException{
public void saveAllData() throws DukeException {
this.taskStore.saveData(this.taskList);
this.walletStore.saveData(this.wallet);
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/ui/gui/HomeWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,6 @@ void displayTasks() throws DukeException {
}

void displayBreakdownChart() {
InfoCapsule infoCapsule = this.interpreterLayer.request(AccessType.WALLET, null);
Wallet wallet = infoCapsule.getWallet();
XYChart.Series<String, Double> expenditureSeries = new XYChart.Series<>();
expenditureSeries.setName("Expenditure");
XYChart.Series<String, Double> incomeSeries = new XYChart.Series<>();
Expand All @@ -130,6 +128,8 @@ void displayBreakdownChart() {

XYChart.Series<String, Double> backdrop = new XYChart.Series<>();
backdrop.setName("Backdrop");
InfoCapsule infoCapsule = this.interpreterLayer.request(AccessType.WALLET, null);
Wallet wallet = infoCapsule.getWallet();
Double backdropValue = this.getBackdropValue(wallet);
HashMap<String, Double> backdropData = this.getBackdropData(backdropValue, expenditureSeries, incomeSeries);

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/ui/gui/MainWindow.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,12 @@ private void showHomeDisplay() {
try {
FXMLLoader loaderHomeDisplay = new FXMLLoader(MainGui.class
.getResource("/view/HomeWindow.fxml"));
AnchorPane homeDisplayRoot = loaderHomeDisplay.load();
this.homeController = loaderHomeDisplay.<HomeWindow>getController();
this.homeController.initialize(this.userInputHistory, this.interpreterLayer);
this.homeController.displayBalanceChart();
this.homeController.displayBreakdownChart();
this.homeController.displayTasks();
AnchorPane homeDisplayRoot = loaderHomeDisplay.load();
this.contentPane.getChildren().add(homeDisplayRoot);
this.displayType = DisplayType.HOME;
} catch (DukeException e) {
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/utils/AccessType.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
package utils;

import executor.accessors.*;
import executor.accessors.AccessDeny;
import executor.accessors.AccessPieChartData;
import executor.accessors.AccessTaskList;
import executor.accessors.AccessWallet;
import executor.accessors.AccessWalletBalance;
import executor.accessors.AccessWalletExpenses;

public enum AccessType {
DENY(AccessDeny.class),
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/CommandDateListTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ void execute() {
dateOne.execute(storageManager);
String output = dateOne.getInfoCapsule().getOutputStr();

assertEquals("You have the following receipts for 2019-02-011. [transport] 3.0 2019-02-01\n", output);
assertEquals("You have the following receipts for 2019-02-01\n1. [transport] 3.0 2019-02-01\n", output);

}

Expand Down
9 changes: 5 additions & 4 deletions testWalletDataLoad.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
In $5.00 /date 2019-08-30 /tags street
out $10 /date 2001-08-25
Out $15.00 /date 2019-12-10 /tags dogfood puppy monthly
in $3.00 /date 2018-03-14 /tags refund clothes
100.0
in $5.0 /date 2019-08-30 /tags street
out $10.0 /date 2001-08-25 /tags
out $15.0 /date 2019-12-10 /tags dogfood puppy monthly
in $3.0 /date 2018-03-14 /tags refund clothes
5 changes: 3 additions & 2 deletions testWalletDataSave.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
0.1
out $10.0 /date 2001-08-25 /tags
100.0
in $5.0 /date 2019-08-30 /tags street
out $10.0 /date 2001-08-25 /tags
out $15.0 /date 2019-12-10 /tags dogfood puppy monthly
in $3.0 /date 2018-03-14 /tags refund clothes

0 comments on commit 1a8401e

Please sign in to comment.