Commit 0bc9e80e authored by Stephen Bennett's avatar Stephen Bennett

Add unit tests for puzzle one

parent 31282a1c
This diff is collapsed.
package org.alfresco.filmstats;
import org.alfresco.MovieRepository;
import org.alfresco.model.DirectorAndLeadingActorPair;
import org.alfresco.model.Film;
......@@ -12,6 +13,12 @@ import static java.util.Collections.emptyList;
*/
public class FilmStats {
private final MovieRepository movieRepository;
public FilmStats(MovieRepository movieRepository) {
this.movieRepository = movieRepository;
}
public List<Film> top10HighestGrossingFilms() {
return emptyList();
}
......
package org.alfresco.filmstats;
import org.alfresco.MovieRepository;
import org.alfresco.model.Film;
import org.junit.Test;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.util.List;
import static java.util.stream.Collectors.toList;
import static org.assertj.core.api.Assertions.assertThat;
/**
* These are the answers for puzzle one. Complete the code in FilmStats.java to make these tests pass.
*/
public class FilmStatsTest {
private final MovieRepository movieRepository;
public FilmStatsTest() throws FileNotFoundException {
this.movieRepository = new MovieRepository(new FileReader("movie-data.json"));
}
@Test
public void shouldReturnTop10HighestGrossingFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
List<Film> films = filmStats.top10HighestGrossingFilms();
assertThat(asListOfFilmNames(films)).containsExactly(
"Avatar",
"Titanic",
"Jurassic World",
"The Avengers",
"The Avengers",
"The Dark Knight",
"Star Wars: Episode I - The Phantom Menace",
"Star Wars: Episode IV - A New Hope",
"Avengers: Age of Ultron",
"The Dark Knight Rises"
);
}
@Test
public void shouldReturnTop10ValueForMoneyFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
List<Film> films = filmStats.top10ValueForMoneyFilms();
assertThat(asListOfFilmNames(films)).containsExactly(
"Paranormal Activity",
"Tarnation",
"The Blair Witch Project",
"The Brothers McMullen",
"The Texas Chain Saw Massacre",
"The Texas Chain Saw Massacre",
"El Mariachi",
"The Gallows",
"Super Size Me",
"Halloween"
);
}
@Test
public void shouldReturnActorWhoHasAppearedInTheMostFilms() {
FilmStats filmStats = new FilmStats(movieRepository);
String actor = filmStats.actorWhoHasAppearedInTheMostFilms();
assertThat(actor).isEqualTo("Robert De Niro");
}
private List<String> asListOfFilmNames(List<Film> films) {
return films.stream().map(Film::getMovieTitle).collect(toList());
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment