Commit deca7579 authored by Stephen Bennett's avatar Stephen Bennett

Refactored implementation to read from JSON file

parent 894de905
1. Create a data model from the input.
1. Find some answers to the following questions
a) Find the top 10 highest grossing films
b) Find the top 10 best value for money (grossing v budget)
c) Which actor has been in the most films?
d) Which director and leading actor pairing is the most successful?
2. Find some answers to the following questions
a) Find the top 10 highest budget films
b) Find the top 10 highest grossing films
c) Find the top 10 highest fb liked films
d) Find the top 10 best likes per dollar rating
e) Find the top 10 best value for money (grossing v budget)
f) Which actor has been in the most films?
g) Which director has directed the most films?
h) Which director and leading actor pairing is the most successful?
2. Create a watch-list
a) Must be able to add items to my to-watch list. You can ony add films to your watch-list that appear in the library. New items are added to the end of the list.
b) Must be able to remove items from my to-watch list.
c) You should be able to get the next movie to watch from the list.
d) You should be able to mark items in the list as "viewed".
e) You should be able to re-order items in the to-watch list.
3. Create a watch-list
a) Must be able to add items to my to-watch list.
b) Reorder items in the list.
c) Mark items as watched.
d) Remove an item from the list.
3. Create an implementation of a video rental store
a) A rental store has a single copy of each movie. A copy of a movie can only be rented by one person.
b) A rental store has N copies of each movie. Each movie can only be rented by N people. The same person can rent a movie N times. It should be possible to list the people who have a particular movie.
c) Each movie rental has a due date for return. It should be possible to find all movies (and people) that are overdue.
\ No newline at end of file
This diff is collapsed.
......@@ -12,6 +12,8 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<dependencies>
......@@ -20,11 +22,22 @@
<artifactId>opencsv</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>3.5.2</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
package com.alfresco;
import com.alfresco.model.Film;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.FileReader;
import java.io.FileWriter;
import java.io.IOException;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
/**
......@@ -8,8 +19,9 @@ import java.util.List;
*/
public class App {
public static void main( String[] args ) {
List<String[]> rows = new MovieDatabaseReader().readMovieDatabase();
public static void main( String[] args ) throws IOException {
List<Film> films = new MovieRepository(new FileReader("movie-data.json")).allFilms();
System.out.println(films);
}
}
package com.alfresco;
import au.com.bytecode.opencsv.CSVReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.List;
public class MovieDatabaseReader {
private static final String MOVIE_DATABASE_CSV = "/movie_metadata.csv";
public List<String[]> readMovieDatabase() {
CSVReader reader = new CSVReader(new InputStreamReader(MovieDatabaseReader.class.getResourceAsStream(MOVIE_DATABASE_CSV)));
try {
return reader.readAll();
} catch (IOException e) {
throw new RuntimeException("Failed to read movie database", e);
}
}
}
package com.alfresco;
import com.alfresco.model.Film;
import com.google.gson.FieldNamingPolicy;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.reflect.TypeToken;
import java.io.Reader;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;
public class MovieRepository {
private final Reader reader;
public MovieRepository(Reader reader) {
this.reader = reader;
}
public List<Film> allFilms() {
Gson gson = new GsonBuilder().setPrettyPrinting()
.setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES)
.create();
Type listType = new TypeToken<ArrayList<Film>>(){}.getType();
return gson.fromJson(reader, listType);
}
}
This diff is collapsed.
This diff is collapsed.
package com.alfresco;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public class AppTest {
/**
* Rigourous Test :-)
*/
@Test
public void testApp()
{
assertTrue( true );
}
}
package com.alfresco;
import com.alfresco.model.Film;
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class FilmBuilderTest {
@Test
public void shouldSetGenres() {
String genres = "Action|Adventure|Fantasy|Sci-Fi";
Film.Builder filmBuilder = new Film.Builder();
Film film = filmBuilder.withGenres(genres).build();
assertThat(film.getGenres()).containsExactly("Action", "Adventure", "Fantasy", "Sci-Fi");
}
@Test
public void shouldSetPlotKeywords() {
String keywords = "avatar|future|marine|native|paraplegic";
Film.Builder filmBuilder = new Film.Builder();
Film film = filmBuilder.withPlotKeywords(keywords).build();
assertThat(film.getPlotKeywords()).containsExactly("avatar", "future", "marine", "native", "paraplegic");
}
}
\ 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