-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStreamCollectorTest.java
More file actions
195 lines (159 loc) · 6.65 KB
/
StreamCollectorTest.java
File metadata and controls
195 lines (159 loc) · 6.65 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
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
import org.junit.jupiter.api.*;
import java.util.*;
import static org.junit.jupiter.api.Assertions.*;
public class StreamCollectorTest
{
private StreamCollector streamCollector;
private List<StreamCollector.Book> books;
private List<StreamCollector.Movie> movies;
private List<StreamCollector.Movie> contemporaryMovies;
private List<StreamCollector.Book> contemporaryBooks;
private List<StreamCollector.Movie> moviesBasedOnBooks;
private Map<String, List<StreamCollector.Movie>> moviesByDirector;
private Map<String, List<StreamCollector.Book>> booksByAuthor;
// Initilize Each expected result before
@BeforeEach
public void setUp()
{
// LISTS
// List of Books
books = List.of(
new StreamCollector.Book("Murder on the Orient Express", "Agatha Christie", 1934),
new StreamCollector.Book("Death on the Nile", "Agatha Christie", 1937),
new StreamCollector.Book("Frankenstein", "Mary Shelly", 1818),
new StreamCollector.Book("Dracula", "Bram Stoker", 1896),
new StreamCollector.Book("Minor Detail", "Adania Shibli", 2017),
new StreamCollector.Book("Septology", "Jon Fosse", 2019),
new StreamCollector.Book("Dune", "Frank Herbert", 1965)
);
// List of Movies
movies = List.of(
new StreamCollector.Movie("Murder on the Orient Express", "Kenneth Branagh", 2017),
new StreamCollector.Movie("Frankenstein", "James Whale", 1932),
new StreamCollector.Movie("Dracula", "Francis Ford Coppola", 1993),
new StreamCollector.Movie("Apocalypse Now", "Francis Ford Coppola", 1979),
new StreamCollector.Movie("The Pianist", "Roman Polanski", 2002),
new StreamCollector.Movie("Dune", "David Villeneuve", 2021),
new StreamCollector.Movie("Arrival", "David Villeneuve", 2016)
);
// Expected result for contemporaryBooks (releaseYear > 2003)
contemporaryBooks = List.of(
new StreamCollector.Book("Minor Detail", "Adania Shibli", 2017),
new StreamCollector.Book("Septology", "Jon Fosse", 2019)
);
// Expected result for contemporaryMovies (releaseYear > 2003)
contemporaryMovies = List.of(
new StreamCollector.Movie("Murder on the Orient Express", "Kenneth Branagh", 2017),
new StreamCollector.Movie("Dune 2", "David Villeneuve", 2024),
new StreamCollector.Movie("Arrival", "David Villeneuve", 2016)
);
// Expected result for movies based on books (Not actually factually accurate : Just supposed to check for common titles across the lists, a more complete database would allow for accuracy)
moviesBasedOnBooks = List.of(
new StreamCollector.Movie("Murder on the Orient Express", "Kenneth Branagh", 2017),
new StreamCollector.Movie("Frankenstein", "James Whale", 1932),
new StreamCollector.Movie("Dracula", "Francis Ford Coppola", 1993),
new StreamCollector.Movie("Dune", "David Villeneuve", 2021)
);
// HASH MAPS
// Movies by director
moviesByDirector = new HashMap<>();
moviesByDirector.put("Kenneth Branagh",
List.of(new StreamCollector.Movie("Murder on the Orient Express", "Kenneth Branagh", 2017))
);
moviesByDirector.put("James Whale",
List.of(new StreamCollector.Movie("Frankenstein", "James Whale", 1932))
);
moviesByDirector.put("Francis Ford Coppola",
List.of(
new StreamCollector.Movie("Dracula", "Francis Ford Coppola", 1993),
new StreamCollector.Movie("Apocalypse Now", "Francis Ford Coppola", 1979)
)
);
moviesByDirector.put("Roman Polanski",
List.of(new StreamCollector.Movie("The Pianist", "Roman Polanski", 2002))
);
moviesByDirector.put("David Villeneuve",
List.of(
new StreamCollector.Movie("Dune 2", "David Villeneuve", 2024),
new StreamCollector.Movie("Arrival", "David Villeneuve", 2016)
)
); // End of Hash Map
// GROUPED LISTS
// Books by author
booksByAuthor = new HashMap<>();
booksByAuthor.put("Agatha Christie",
List.of(
new StreamCollector.Book("Murder on the Orient Express", "Agatha Christie", 1934),
new StreamCollector.Book("Death on the Nile", "Agatha Christie", 1937)
)
);
booksByAuthor.put("Mary Shelly",
List.of(
new StreamCollector.Book("Frankenstein", "Mary Shelly", 1818)
)
);
booksByAuthor.put("Bram Stoker",
List.of(
new StreamCollector.Book("Dracula", "Bram Stoker", 1896)
)
);
booksByAuthor.put("Adania Shibli",
List.of(
new StreamCollector.Book("Minor Detail", "Adania Shibli", 2017)
)
);
booksByAuthor.put("Jon Fosse",
List.of(
new StreamCollector.Book("Septology", "Jon Fosse", 2019)
)
);
booksByAuthor.put("Frank Herbert",
List.of(
new StreamCollector.Book("Dune", "Frank Herbert", 1965)
)
); // End of Hash Map
// Initilize StreamCollector
streamCollector = new StreamCollector(books, movies);
}
// TESTS
/* Test for PartitionBooksByReleaseYear function
Expected Result : Pass
*/
@Test
public void testPartitionBooksByReleaseYear()
{
assertEquals(contemporaryBooks, streamCollector.PartitionBooksByReleaseYear(2003));
}
/* Test for PartitionMoviesByReleaseYear function
Expected Result : Pass
*/
@Test
public void testPartitionMoviesByReleaseYear()
{
assertEquals(contemporaryMovies, streamCollector.PartitionMoviesByReleaseYear(2003));
}
/* Test for MoviesBasedOnBooks function
Expected Result : Pass
*/
@Test
public void testMoviesBasedOnBooks()
{
assertEquals(moviesBasedOnBooks, streamCollector.MoviesBasedOnBooks());
}
/* Test for GroupMoviesByAuthor function
Expected Result : Pass
*/
@Test
public void testGroupMoviesByDirector()
{
assertEquals(moviesByDirector, streamCollector.GroupMoviesByDirector());
}
/* Test for GroupBooksByAuthor function
Expected Result : Pass
*/
@Test
public void testGroupBooksByAuthor()
{
assertEquals(booksByAuthor, streamCollector.GroupBooksByAuthor());
}
}