forked from nus-cs2113-AY2324S2/tp
-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add application logic to main method of BinBash class #38
Merged
nur-haziq
merged 10 commits into
AY2324S2-CS2113T-T09-2:master
from
YHWong20:feature-updateMain
Mar 14, 2024
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
1f2c1bf
Update file and package names
YHWong20 5cfe5db
Add application execution logic to main method
YHWong20 38a0529
Add unit test for BinBash main method
YHWong20 1c031f1
Add ByeCommand class
YHWong20 30db802
Add text UI tests
YHWong20 36f9e3e
Add ByeCommand creation logic to Parser
YHWong20 73d1d71
Update Ui helper methods
YHWong20 c2a5455
Update formatting for newline character
YHWong20 760b963
Update formatting for newline character
YHWong20 15c907e
Update newline character formatting in unit test
YHWong20 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package seedu.binbash; | ||
|
||
import seedu.binbash.ui.Ui; | ||
import seedu.binbash.command.Command; | ||
import seedu.binbash.command.ByeCommand; | ||
|
||
public class BinBash { | ||
/** | ||
* Main entry-point for the BinBash application. | ||
*/ | ||
public static void main(String[] args) { | ||
Ui userInterface = new Ui(); | ||
ItemList itemList = new ItemList(); | ||
Parser inputParser = new Parser(itemList); | ||
|
||
userInterface.greet(); | ||
|
||
while (userInterface.isUserActive()) { | ||
String userInput = userInterface.readUserCommand(); | ||
Command userCommand = inputParser.parseCommand(userInput); | ||
|
||
if (userCommand instanceof ByeCommand) { | ||
userInterface.setUserAsInactive(); | ||
continue; | ||
} | ||
|
||
String executionResult = userCommand.execute(); | ||
userInterface.talk(executionResult); | ||
} | ||
|
||
userInterface.farewell(); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package seedu.binbash.command; | ||
|
||
import seedu.binbash.ItemList; | ||
|
||
public class ByeCommand extends Command { | ||
public static final String COMMAND_STRING = "bye"; | ||
|
||
public ByeCommand(ItemList itemList) { | ||
super(itemList); | ||
} | ||
|
||
@Override | ||
public String execute() { | ||
return ""; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package seedu.binbash; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.ByteArrayInputStream; | ||
import java.io.ByteArrayOutputStream; | ||
import java.io.InputStream; | ||
import java.io.PrintStream; | ||
|
||
class BinBashTest { | ||
private static final String NEWLINE = System.lineSeparator(); | ||
private static final String TEST_INPUT = "bye"; | ||
private static final String EXPECTED_OUTPUT = "-------------------------------------------------------------" + | ||
NEWLINE + | ||
" ____ _ ____ _" + NEWLINE + | ||
" | __ )(_)_ __ | __ ) __ _ ___| |__" + NEWLINE + | ||
" | _ \\| | '_ \\| _ \\ / _` / __| '_ \\" + NEWLINE + | ||
" | |_) | | | | | |_) | (_| \\__ \\ | | |" + NEWLINE + | ||
" |____/|_|_| |_|____/ \\__,_|___/_| |_|" + NEWLINE + NEWLINE + | ||
"Welcome to BinBash!" + NEWLINE + | ||
"-------------------------------------------------------------" + NEWLINE + | ||
"-------------------------------------------------------------" + NEWLINE + | ||
"Bye!" + NEWLINE + | ||
"-------------------------------------------------------------" + NEWLINE; | ||
private static final InputStream systemIn = System.in; | ||
private static final PrintStream systemOut = System.out; | ||
private ByteArrayInputStream testIn; | ||
private ByteArrayOutputStream testOut; | ||
|
||
@Test | ||
public void main_readByeCommand_byeCommandExecuted() { | ||
try { | ||
setupInput(); | ||
setupOutput(); | ||
BinBash.main(new String[0]); | ||
assertEquals(getOutput(), EXPECTED_OUTPUT); | ||
} finally { | ||
restoreSystemInputOutput(); | ||
} | ||
} | ||
|
||
private void setupInput() { | ||
testIn = new ByteArrayInputStream(TEST_INPUT.getBytes()); | ||
System.setIn(testIn); | ||
} | ||
|
||
private void setupOutput() { | ||
testOut = new ByteArrayOutputStream(); | ||
System.setOut(new PrintStream(testOut)); | ||
} | ||
|
||
private String getOutput() { | ||
return testOut.toString(); | ||
} | ||
|
||
private void restoreSystemInputOutput() { | ||
System.setIn(systemIn); | ||
System.setOut(systemOut); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
Hello from | ||
____ _ | ||
| _ \ _ _| | _____ | ||
| | | | | | | |/ / _ \ | ||
| |_| | |_| | < __/ | ||
|____/ \__,_|_|\_\___| | ||
------------------------------------------------------------- | ||
____ _ ____ _ | ||
| __ )(_)_ __ | __ ) __ _ ___| |__ | ||
| _ \| | '_ \| _ \ / _` / __| '_ \ | ||
| |_) | | | | | |_) | (_| \__ \ | | | | ||
|____/|_|_| |_|____/ \__,_|___/_| |_| | ||
|
||
What is your name? | ||
Hello James Gosling | ||
Welcome to BinBash! | ||
------------------------------------------------------------- | ||
------------------------------------------------------------- | ||
|
||
------------------------------------------------------------- | ||
------------------------------------------------------------- | ||
Bye! | ||
------------------------------------------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
James Gosling | ||
list | ||
bye |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Consider adding an empty line here