Skip to content

Commit

Permalink
Merge pull request AY2324S2-CS2113T-T09-1#248 from nickczh/nickczh-Co…
Browse files Browse the repository at this point in the history
…deQuality-V2.1

refactor: Enhance code quality for stricter style checks
  • Loading branch information
royaliceblue authored Apr 15, 2024
2 parents 5911240 + 0d8b42e commit 005f5e8
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 63 deletions.
7 changes: 4 additions & 3 deletions docs/team/nickczh.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
- Issue #71: Add assertion to Add command
- Issue #72: Modify Ui to be static
- Issue #74: More flags for Add command and Exception Handling
- Issue #150: Enhance code quality for stricter styling checks
- Issue #159: [PE-D][Tester E] Remarks changes from null to empty upon restart of application
- Issue #182: [PE-D][Tester C] Lack of /help page
- Issue #184: [PE-D][Tester F] using an example from the user guide is causing an error
Expand All @@ -20,16 +21,16 @@

### Developer Guide Contributions
- Add command specifications
- Update Add Command with sequence diagrams (Issue #138)
- Sequence diagram for Add Command (Issue #138)

### User Guide Contributions
- Table of Contents
- Add command
- Description
- Command Format
- Example
- Output
- Command Summary
- Table of Contents

- Help command

### Team-based tasks
Expand Down
38 changes: 16 additions & 22 deletions src/main/java/meditracker/command/AddCommand.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
package meditracker.command;

import java.time.LocalDate;
import java.util.Map;

import meditracker.argument.ArgumentHelper;
import meditracker.argument.ArgumentList;
import meditracker.argument.ArgumentName;
import meditracker.argument.DosageAfternoonArgument;
import meditracker.argument.DosageEveningArgument;
import meditracker.argument.DosageMorningArgument;
import meditracker.argument.ExpirationDateArgument;
import meditracker.argument.NameArgument;
import meditracker.argument.QuantityArgument;
import meditracker.argument.RemarksArgument;
import meditracker.argument.RepeatArgument;
import meditracker.dailymedication.DailyMedicationManager;
import meditracker.exception.ArgumentException;
import meditracker.exception.HelpInvokedException;
Expand All @@ -10,20 +23,6 @@
import meditracker.time.MediTrackerTime;
import meditracker.ui.Ui;

import meditracker.argument.ArgumentName;
import meditracker.argument.ArgumentList;
import meditracker.argument.RepeatArgument;
import meditracker.argument.DosageAfternoonArgument;
import meditracker.argument.DosageMorningArgument;
import meditracker.argument.DosageEveningArgument;
import meditracker.argument.NameArgument;
import meditracker.argument.QuantityArgument;
import meditracker.argument.ExpirationDateArgument;
import meditracker.argument.RemarksArgument;

import java.time.LocalDate;
import java.util.Map;

// @@author nickczh
/**
* The AddCommand class represents a command to add a new medication.
Expand Down Expand Up @@ -77,17 +76,12 @@ public void execute() {
Medication medication;
try {
medication = createMedication();
} catch (MediTrackerException e) {
Ui.showErrorMessage(e);
return;
}

try {
MedicationManager.addMedication(medication);
} catch (MediTrackerException e) {
Ui.showErrorMessage(e);
return;
}

DailyMedicationManager.checkForDaily(medication);
assertionTest();
Ui.showSuccessMessage("Medicine has been added");
Expand Down Expand Up @@ -124,8 +118,8 @@ Medication createMedication() throws MediTrackerException {
* Performs assertion tests for medication and daily medication managers.
*/
private void assertionTest() {
assert MedicationManager.getTotalMedications() != 0 : "Total medications in medication " +
"manager should not be 0!";
assert MedicationManager.getTotalMedications() != 0 : "Total medications in medication "
+ "manager should not be 0!";
}

}
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/meditracker/ui/Ui.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,27 +37,27 @@ public static void showWelcomeMessage() {
public static void printIntroName() {

// Solution below adapted by http://patorjk.com/software/taag/#p=display&f=Graffiti&t=Type%20Something%20
System.out.println(" __ ______ __ " +
System.lineSeparator() +
" /'\\_/`\\ /\\ \\ __/\\__ _\\ /\\ \\ " +
System.lineSeparator() +
"/\\ \\ __ \\_\\ \\/\\_\\/_/\\ \\/ _ __ __ ___\\ \\ \\/'\\ __ _ __ " +
System.lineSeparator() +
"\\ \\ \\__\\ \\ /'__`\\ /'_` \\/\\ \\ \\ \\ \\/\\`'__\\/'__`\\ /'___\\ \\ , < /'__`\\/\\`'__\\" +
System.lineSeparator() +
" \\ \\ \\_/\\ \\/\\ __//\\ \\L\\ \\ \\ \\ \\ \\ \\ \\ \\//\\ \\L\\.\\_/\\ \\__/\\ \\ \\\\`\\ /\\" +
" __/\\" +
" \\ \\/ " +
System.lineSeparator() +
" \\ \\_\\\\ \\_\\ \\____\\ \\___,_\\ \\_\\ \\ \\_\\ \\_\\\\ \\__/.\\_\\ \\____\\\\ \\_\\ \\_\\ " +
"\\____\\" +
"\\ \\_\\ " +
System.lineSeparator() +
" \\/_/ \\/_/\\/____/\\/__,_ /\\/_/ \\/_/\\/_/ \\/__/\\/_/\\/____/ \\/_/\\/_/\\/____/ \\/_/ " +
System.lineSeparator() +
" " +
System.lineSeparator() +
" ");
System.out.println(" __ ______ __ "
+ System.lineSeparator()
+ " /'\\_/`\\ /\\ \\ __/\\__ _\\ /\\ \\ "
+ System.lineSeparator()
+ "/\\ \\ __ \\_\\ \\/\\_\\/_/\\ \\/ _ __ __ ___\\ \\ \\/'\\ __ _ __ "
+ System.lineSeparator()
+ "\\ \\ \\__\\ \\ /'__`\\ /'_` \\/\\ \\ \\ \\ \\/\\`'__\\/'__`\\ /'___\\ \\ , < /'__`\\/\\`'__\\"
+ System.lineSeparator()
+ " \\ \\ \\_/\\ \\/\\ __//\\ \\L\\ \\ \\ \\ \\ \\ \\ \\ \\//\\ \\L\\.\\_/\\ \\__/\\ \\ \\\\`\\ /\\"
+ " __/\\"
+ " \\ \\/ "
+ System.lineSeparator()
+ " \\ \\_\\\\ \\_\\ \\____\\ \\___,_\\ \\_\\ \\ \\_\\ \\_\\\\ \\__/.\\_\\ \\____\\\\ \\_\\ \\_\\ "
+ "\\____\\"
+ "\\ \\_\\ "
+ System.lineSeparator()
+ " \\/_/ \\/_/\\/____/\\/__,_ /\\/_/ \\/_/\\/_/ \\/__/\\/_/\\/____/ \\/_/\\/_/\\/____/ \\/_/ "
+ System.lineSeparator()
+ " "
+ System.lineSeparator()
+ " ");
}

/**
Expand Down
35 changes: 18 additions & 17 deletions src/test/java/meditracker/command/AddCommandTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,24 +2,25 @@

// @@author nickczh

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import meditracker.dailymedication.DailyMedicationManagerTest;
import meditracker.exception.ArgumentException;
import meditracker.exception.MediTrackerException;
import meditracker.exception.HelpInvokedException;
import meditracker.exception.MediTrackerException;
import meditracker.medication.Medication;
import meditracker.medication.MedicationManager;
import meditracker.medication.MedicationManagerTest;
import meditracker.time.MediTrackerTime;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

import java.lang.reflect.InvocationTargetException;
import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;

class AddCommandTest {

Expand All @@ -37,8 +38,8 @@ void execute_correctExampleInput_expectOneMedication()
throws HelpInvokedException, ArgumentException {

// setup lines
String inputString = "add -n Medication A -q 5000 -e 2025-07-01 " +
"-dM 500 -dA 250 -dE 100 -r cause_dizziness -rep 1";
String inputString = "add -n Medication A -q 5000 -e 2025-07-01 "
+ "-dM 500 -dA 250 -dE 100 -r cause_dizziness -rep 1";
AddCommand command = new AddCommand(inputString);
command.execute();

Expand Down Expand Up @@ -76,8 +77,8 @@ void execute_emptyMedicationName_expectZeroMedication()
void createMedication_correctExampleInput_success()
throws HelpInvokedException, MediTrackerException, ArgumentException {
// setup lines
String inputString = "add -n Medication A -q 5000 -e 2025-07-01 -dM 500 -dA 250 -dE 100 " +
"-r cause_dizziness -rep 1";
String inputString = "add -n Medication A -q 5000 -e 2025-07-01 -dM 500 -dA 250 -dE 100 "
+ "-r cause_dizziness -rep 1";
AddCommand command = new AddCommand(inputString);
// Get the current date and the day of the year
LocalDate currentDate = MediTrackerTime.getCurrentDate();
Expand All @@ -103,8 +104,8 @@ void createMedication_correctExampleInput_success()
void createMedication_incorrectQuantityInput_exceptionThrown()
throws HelpInvokedException, ArgumentException {
// setup lines
String inputString = "add -n Medication A -q %%% -e 2025-07-01 -dM 500 -dA 250 -dE 100 " +
"-r cause_dizziness -rep 1";
String inputString = "add -n Medication A -q %%% -e 2025-07-01 -dM 500 -dA 250 -dE 100 "
+ "-r cause_dizziness -rep 1";
AddCommand command = new AddCommand(inputString);

// actual test
Expand Down

0 comments on commit 005f5e8

Please sign in to comment.