Skip to content

Commit

Permalink
Improve coding standard by removing magic strings.
Browse files Browse the repository at this point in the history
  • Loading branch information
NaychiMin committed Nov 9, 2023
1 parent b3d10e5 commit ea05f47
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ public class ListIngredientCommand extends Command {
protected Ui ui;
protected Menu menu;


public ListIngredientCommand(int listIndex, Menu menu, Ui ui) {
this.index = listIndex;
this.menu = menu;
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/seedu/cafectrl/data/Pantry.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,16 +154,16 @@ public void calculateDishAvailability(Menu menu, Order order) {
public int calculateMaxDishes(Dish dish, Menu menu, Order order) {
int maxNumofDish = Integer.MAX_VALUE;
ArrayList<Ingredient> dishIngredients = retrieveIngredientsForDish(dish.getName(), menu);
boolean restockHeaderDisplayed = false;
boolean isRestockHeaderDisplayed = false;
int dishQty = order.getQuantity();

for (Ingredient dishIngredient : dishIngredients) {
int numOfDish = calculateMaxDishForEachIngredient(dishIngredient);
maxNumofDish = Math.min(numOfDish, maxNumofDish);

if (!restockHeaderDisplayed && (numOfDish < dishQty)) {
if (!isRestockHeaderDisplayed && (numOfDish < dishQty)) {
ui.showToUser(Messages.RESTOCK_CORNER, Messages.RESTOCK_TITLE, Messages.RESTOCK_CORNER);
restockHeaderDisplayed = true;
isRestockHeaderDisplayed = true;
}

if (numOfDish < dishQty && !order.getIsComplete()) {
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/seedu/cafectrl/storage/Decoder.java
Original file line number Diff line number Diff line change
Expand Up @@ -129,9 +129,7 @@ public static Sales decodeSales(ArrayList<String> textLines, Menu menu) {
boolean isComplete = "true".equals(orderData[4].trim());
Dish dish = menu.getDishFromName(dishName);
if(dish == null) {
ui.showToUser("oh no! " + dishName + " does not exist in our menu, "
+ "you might have tempered with the file and added in a non existing dish."
, "don't worry, we will continue operations without " + dishName);
ui.showDecodedInvalidDish(dishName);
} else {
Order orderedDish = new Order(menu.getDishFromName(dishName), quantity, totalOrderCost, isComplete);
//increase size of orderLists if needed
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/seedu/cafectrl/ui/Messages.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,9 @@ public class Messages {
public static final String INGREDIENTS_END_CAP = "+-------------------------------------------------------+";
public static final String INGREDIENTS_CORNER = "+----------------------------------------+--------------+";
public static final String INGREDIENTS_TITLE = "| Ingredient + Quantity +";
/** Messages for decoder **/
public static final String INVALID_DISH = " does not exist in our menu. \n"
+ "You might have tempered with the file and added in a non existing dish.\n"
+ "Don't worry :D , we will continue operations without ";

}
4 changes: 4 additions & 0 deletions src/main/java/seedu/cafectrl/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -261,4 +261,8 @@ public void showPreviousDay() {
public void showNextDay() {
showToUser(Messages.NEXT_DAY_COMMAND_MESSAGE);
}

public void showDecodedInvalidDish(String dishName) {
showToUser(dishName + Messages.INVALID_DISH + dishName);
}
}
25 changes: 12 additions & 13 deletions src/test/java/seedu/cafectrl/command/AddOrderCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import seedu.cafectrl.data.Pantry;
import seedu.cafectrl.data.dish.Dish;
import seedu.cafectrl.data.dish.Ingredient;
import seedu.cafectrl.ui.Messages;
import seedu.cafectrl.ui.Ui;

import java.io.ByteArrayOutputStream;
Expand Down Expand Up @@ -56,16 +57,15 @@ public void execute_addValidOrder_expectOneOrder() {
String actualOutput = baos.toString().trim();
System.setOut(originalOut);

String expectedOutput = "I'm busy crafting your selected dish in the virtual kitchen of your dreams. "
+ "Bon appétit!"
+ "-----------------------------------------------------"
+ "Order is ready!"
String expectedOutput = Messages.CHEF_MESSAGE
+ Messages.LINE_STRING
+ Messages.COMPLETE_ORDER
+ "Total order cost: $5.00"
+ "-----------------------------------------------------"
+ "Listed below are the availability of the dishes for the next order!"
+ Messages.LINE_STRING
+ Messages.AVAILABLE_DISHES
+ "Dish: chicken rice"
+ "Available Dishes: 8"
+ "-----------------------------------------------------"
+ Messages.LINE_STRING
+ "Dish: chicken curry"
+ "Available Dishes: 4";

Expand Down Expand Up @@ -116,14 +116,13 @@ public void execute_addInvalidOrder_expectRestockMessage() {
String actualOutput = baos.toString().trim();
System.setOut(originalOut);

String expectedOutput = "I'm busy crafting your selected dish in the virtual kitchen of your dreams. "
+ "Bon appétit!"
+ "+----------------------------------------+--------------+--------------+"
String expectedOutput = Messages.CHEF_MESSAGE
+ Messages.RESTOCK_CORNER
+ "| Restock | Current | Needed |"
+ "+----------------------------------------+--------------+--------------+"
+ Messages.RESTOCK_CORNER
+ "| chicken | 1000g | 2000g |"
+ "+----------------------------------------------------------------------+"
+ "Please restock ingredients before preparing the order :) ";
+ Messages.RESTOCK_END_CAP
+ Messages.INCOMPLETE_ORDER;


String normalizedExpected = expectedOutput.toLowerCase().replaceAll("\\s+", "").trim();
Expand Down

0 comments on commit ea05f47

Please sign in to comment.