-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFrontendTests.java
More file actions
145 lines (116 loc) · 4.44 KB
/
FrontendTests.java
File metadata and controls
145 lines (116 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Assertions;
import java.util.Scanner;
/**
* Tester class for the Frontend Implementation.
*/
public class FrontendTests {
/**
* Tests the Load File option in the Frontend Implementation. Uses the Backend Placeholder for
* testing.
*
* @return True if all tests pass, False otherwise.
*/
@Test
public void roleTest1() {
// Test Load File
{
Scanner sc = new Scanner("testFilepath\n");
TextUITester uiTester = new TextUITester("");
IterableSortedCollection<Song> tree = new Tree_Placeholder();
BackendInterface backend = new Backend_Placeholder(tree);
FrontendInterface frontend = new Frontend(sc, backend);
try {
frontend.loadFile();
} catch (Exception e) {
Assertions.assertTrue(false, "Unexpected Exception Encountered.");
}
sc.close();
}
}
/**
* Tests the Get Songs and set Filter options in the Frontend Implementation. Uses the Backend
* Placeholder for testing.
*
* @return True if all tests pass, False otherwise.
*/
@Test
public void roleTest2() {
// Test Get Songs & Filter
{ // Test GET with 1 song out.
Scanner sc = new Scanner("2\n16\n");
TextUITester uiTester = new TextUITester("");
IterableSortedCollection<Song> tree = new Tree_Placeholder();
BackendInterface backend = new Backend_Placeholder(tree);
FrontendInterface frontend = new Frontend(sc, backend);
try {
frontend.getSongs();
} catch (Exception e) {
Assertions.assertTrue(false, "Unexpected Exception Encountered.");
}
String out = uiTester.checkOutput();
if (!out.contains("Cake By The Ocean")
|| (out.contains("BO$$") || out.contains("A L I E N S")))
Assertions.assertTrue(false, "Displaying Invalid Songs.");
}
{ // Test GET with 2 songs out.
Scanner sc = new Scanner("1\n20\n");
TextUITester uiTester = new TextUITester("");
IterableSortedCollection<Song> tree = new Tree_Placeholder();
BackendInterface backend = new Backend_Placeholder(tree);
FrontendInterface frontend = new Frontend(sc, backend);
try {
frontend.getSongs();
} catch (Exception e) {
Assertions.assertTrue(false, "Unexpected Exception Encountered.");
}
String out = uiTester.checkOutput();
if (!(out.contains("Cake By The Ocean") && out.contains("BO$$"))
|| (out.contains("A L I E N S")))
Assertions.assertTrue(false, "Displaying Invalid Songs.");
}
{ // Test FILTER.
Scanner sc = new Scanner("8\n");
TextUITester uiTester = new TextUITester("");
IterableSortedCollection<Song> tree = new Tree_Placeholder();
BackendInterface backend = new Backend_Placeholder(tree);
FrontendInterface frontend = new Frontend(sc, backend);
try {
frontend.setFilter();
} catch (Exception e) {
Assertions.assertTrue(false, "Unexpected Exception Encountered.");
}
String out = uiTester.checkOutput();
if (!(out.contains("Cake By The Ocean") && out.contains("BO$$")
&& out.contains("A L I E N S")))
// With given placeholder, all songs are returned regardless of input.
Assertions.assertTrue(false, "Displaying Invalid Songs.");
}
}
/**
* Tests the Display Top 5 option in the Frontend Implementation (Including after setting filter
* and energy). Uses the Backend Placeholder for testing.
*
* @return True if all tests pass, False otherwise.
*/
@Test
public void roleTest3() {
// Test Display Top 5
{ // Test Display 5.
Scanner sc = new Scanner("");
TextUITester uiTester = new TextUITester("");
IterableSortedCollection<Song> tree = new Tree_Placeholder();
BackendInterface backend = new Backend_Placeholder(tree);
FrontendInterface frontend = new Frontend(sc, backend);
try {
frontend.displayTopFive();
} catch (Exception e) {
Assertions.assertTrue(false, "Unexpected Exception Encountered.");
}
String out = uiTester.checkOutput();
if (!(out.contains("Cake By The Ocean") && out.contains("BO$$")
&& out.contains("A L I E N S")))
Assertions.assertTrue(false, "Displaying Invalid Songs.");
}
}
}