diff --git a/Help/SortedByRating.txt b/Help/SortedByRating.txt new file mode 100644 index 0000000..a26369a --- /dev/null +++ b/Help/SortedByRating.txt @@ -0,0 +1,15 @@ +1. Movie: The Shawshank Redemption, Rating: 9.3, Year: 1994 +2. Movie: The Godfather, Rating: 9.2, Year: 1972 +3. Movie: The Dark Knight, Rating: 9.0, Year: 2008 +4. Movie: 12 Angry Men, Rating: 9.0, Year: 1957 +5. Movie: Schindler's List, Rating: 9.0, Year: 1993 +6. Movie: The Lord of the Rings: The Return of the King, Rating: 9.0, Year: 2003 +7. Movie: Pulp Fiction, Rating: 8.9, Year: 1994 +8. Movie: The Lord of the Rings: The Fellowship of the Ring, Rating: 8.8, Year: 2001 +9. Movie: Forrest Gump, Rating: 8.8, Year: 1994 +10. Movie: Fight Club, Rating: 8.8, Year: 1999 +11. Movie: Inception, Rating: 8.8, Year: 2010 +12. Movie: Star Wars: Episode V - The Empire Strikes Back, Rating: 8.7, Year: 1980 +13. Movie: The Matrix, Rating: 8.7, Year: 1999 +14. Movie: Goodfellas, Rating: 8.7, Year: 1990 +15. Movie: Interstellar, Rating: 8.6, Year: 2014 \ No newline at end of file diff --git a/src/test/java/ParserTest.java b/src/test/java/ParserTest.java new file mode 100644 index 0000000..28f4912 --- /dev/null +++ b/src/test/java/ParserTest.java @@ -0,0 +1,63 @@ +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 { + handle = new Parser(); + handle.setUp(); + } + + @Test + public void testSortByTitle() { + List 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 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 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)); + } +}