64 lines
2.2 KiB
Java
64 lines
2.2 KiB
Java
import org.junit.jupiter.api.BeforeAll;
|
|
import org.junit.jupiter.api.Test;
|
|
|
|
import java.io.IOException;
|
|
import java.util.List;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
public class ParserTest {
|
|
|
|
public static Parser handle;
|
|
|
|
@BeforeAll
|
|
static void setUp() throws IOException {
|
|
String filePath = "src/main/resources/Movies.html";
|
|
handle = new Parser(filePath);
|
|
}
|
|
|
|
@Test
|
|
public void testSortByTitle() {
|
|
List<Movie> sortedMovies = handle.sortByTitle();
|
|
Movie m1 = new Movie("12 Angry Men", 9.0, 1957);
|
|
Movie m2 = new Movie("Forrest Gump", 8.8, 1994);
|
|
Movie m3 = new Movie("Star Wars: Episode V - The Empire Strikes Back", 8.7, 1980);
|
|
Movie m4 = new Movie("The Lord of the Rings: The Fellowship of the Ring", 8.8, 2001);
|
|
|
|
assertEquals(15, sortedMovies.size());
|
|
assertEquals(m1, sortedMovies.get(0));
|
|
assertEquals(m2, sortedMovies.get(2));
|
|
assertEquals(m3, sortedMovies.get(8));
|
|
assertEquals(m4, sortedMovies.get(11));
|
|
}
|
|
|
|
@Test
|
|
public void testSortByYear() {
|
|
List<Movie> sortedMovies = handle.sortByYear();
|
|
Movie m1 = new Movie("Interstellar", 8.6, 2014);
|
|
Movie m2 = new Movie("The Lord of the Rings: The Return of the King", 9.0, 2003);
|
|
Movie m3 = new Movie("Pulp Fiction", 8.9, 1994);
|
|
Movie m4 = new Movie("12 Angry Men", 9.0, 1957);
|
|
|
|
assertEquals(15, sortedMovies.size());
|
|
assertEquals(m1, sortedMovies.get(0));
|
|
assertEquals(m2, sortedMovies.get(3));
|
|
assertEquals(m3, sortedMovies.get(8));
|
|
assertEquals(m4, sortedMovies.get(14));
|
|
}
|
|
|
|
@Test
|
|
public void testSortByRating() {
|
|
List<Movie> sortedMovies = handle.sortByRating();
|
|
Movie m1 = new Movie("The Shawshank Redemption", 9.3, 1994);
|
|
Movie m2 = new Movie("The Dark Knight", 9.0, 2008);
|
|
Movie m3 = new Movie("Fight Club", 8.8, 1999);
|
|
Movie m4 = new Movie("Interstellar", 8.6, 2014);
|
|
|
|
assertEquals(15, sortedMovies.size());
|
|
assertEquals(m1, sortedMovies.get(0));
|
|
assertEquals(m2, sortedMovies.get(2));
|
|
assertEquals(m3, sortedMovies.get(9));
|
|
assertEquals(m4, sortedMovies.get(14));
|
|
}
|
|
}
|