Skip to content

Commit c62bced

Browse files
committed
Add JUnit test
Same package but test could not be found
1 parent 50bb3e6 commit c62bced

3 files changed

Lines changed: 68 additions & 2 deletions

File tree

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ test {
2828
}
2929

3030
application {
31-
mainClass.set("seedu.duke.Duke")
31+
mainClass.set("Milo.Milo")
3232
}
3333

3434
shadowJar {
35-
archiveBaseName = "duke"
35+
archiveBaseName = "Milo"
3636
archiveClassifier = null
3737
}
3838

src/test/java/Milo/MiloTest.java

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package Milo;
2+
import org.junit.jupiter.api.Test;
3+
import java.io.ByteArrayInputStream;
4+
import java.io.ByteArrayOutputStream;
5+
import java.io.PrintStream;
6+
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
8+
public class MiloTest {
9+
@Test
10+
public void testGreetingAndExit() {
11+
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
12+
// Redirect System.out to capture printed output
13+
System.setOut(new PrintStream(outputStreamCaptor));
14+
// Simulate user input with "bye" to immediately exit
15+
System.setIn(new ByteArrayInputStream("bye\n".getBytes()));
16+
// Run the Milo application
17+
Milo milo = new Milo();
18+
milo.run();
19+
20+
String expectedOutput = """
21+
____________________________________________________________
22+
Hello! I'm Milo.Milo
23+
What can I do for you?
24+
╱|、
25+
(˚ˎ 。7 \s
26+
|、˜〵 \s
27+
じしˍ,)ノ
28+
____________________________________________________________
29+
____________________________________________________________
30+
Bye. Hope to see you again soon!
31+
∧,,,∧
32+
( ̳• · •̳)
33+
/ づ♡
34+
____________________________________________________________
35+
""";
36+
37+
// Verify that the greeting and exit messages were printed
38+
assertEquals(expectedOutput, outputStreamCaptor.toString().replace("\r", ""));
39+
}
40+
}

src/test/java/Milo/UiTest.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package Milo;
2+
import org.junit.jupiter.api.Test;
3+
import java.io.ByteArrayOutputStream;
4+
import java.io.PrintStream;
5+
import static org.junit.jupiter.api.Assertions.assertEquals;
6+
7+
class UiTest {
8+
@Test
9+
public void testGreetUser() {
10+
Ui ui = new Ui();
11+
ui.greetUser();
12+
ByteArrayOutputStream outputStreamCaptor = new ByteArrayOutputStream();
13+
System.setOut(new PrintStream(outputStreamCaptor));
14+
String expectedOutput = """
15+
____________________________________________________________
16+
Hello! I'm Milo.Milo
17+
What can I do for you?
18+
╱|、
19+
(˚ˎ 。7 \s
20+
|、˜〵 \s
21+
じしˍ,)ノ
22+
____________________________________________________________
23+
""";
24+
assertEquals(expectedOutput, outputStreamCaptor.toString());
25+
}
26+
}

0 commit comments

Comments
 (0)