Skip to content

Commit d4848d7

Browse files
authored
Merge pull request jhonM8a#9 from jhonM8a/9.AppPeliculasTestGenero
Se crea app y test de movie
2 parents bc6d280 + 45eb49d commit d4848d7

File tree

5 files changed

+187
-0
lines changed

5 files changed

+187
-0
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/**
2+
*
3+
*/
4+
package com.testing.javatest.movie.data;
5+
6+
import java.util.Collection;
7+
8+
import com.testing.javatest.movie.model.Movie;
9+
10+
/**
11+
* Clase para el acceso a datos de Movie.
12+
*
13+
* @author sumel
14+
*
15+
*/
16+
public interface MovieRepository {
17+
18+
Movie finById(long id);
19+
20+
Collection<Movie> findAll();
21+
22+
void saveOrUpdate(Movie movie);
23+
}
24+
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
/**
2+
*
3+
*/
4+
package com.testing.javatest.movie.model;
5+
6+
/**
7+
* Clase que representa generos de peliculas.
8+
*
9+
* @author sumel
10+
*
11+
*/
12+
public enum Genre {
13+
ACTION,COMEDY,DRAMA, HORROR, THILLER
14+
}
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
*
3+
*/
4+
package com.testing.javatest.movie.model;
5+
6+
/**
7+
* Clase que representa una pelicula(Movie)
8+
*
9+
* @author sumel
10+
*
11+
*/
12+
public class Movie {
13+
14+
private Integer id;
15+
private String name;
16+
private int minutes;
17+
private Genre genre;
18+
19+
public Movie(String name, int minutes, Genre genre) {
20+
this(null, name, minutes, genre);
21+
}
22+
23+
public Movie(Integer id, String name, int minutes, Genre genre) {
24+
25+
this.id = id;
26+
this.name = name;
27+
this.minutes = minutes;
28+
this.genre = genre;
29+
}
30+
31+
public Integer getId() {
32+
return id;
33+
}
34+
35+
public void setId(Integer id) {
36+
this.id = id;
37+
}
38+
39+
public String getName() {
40+
return name;
41+
}
42+
43+
public void setName(String name) {
44+
this.name = name;
45+
}
46+
47+
public int getMinutes() {
48+
return minutes;
49+
}
50+
51+
public void setMinutes(int minutes) {
52+
this.minutes = minutes;
53+
}
54+
55+
public Genre getGenre() {
56+
return genre;
57+
}
58+
59+
public void setGenre(Genre genre) {
60+
this.genre = genre;
61+
}
62+
63+
64+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
*
3+
*/
4+
package com.testing.javatest.movie.service;
5+
6+
import java.util.Collection;
7+
import java.util.stream.Collectors;
8+
9+
import com.testing.javatest.movie.data.MovieRepository;
10+
import com.testing.javatest.movie.model.Genre;
11+
import com.testing.javatest.movie.model.Movie;
12+
13+
/**
14+
* Clase para lo logica de negocio de peliculas(Movie)
15+
*
16+
* @author sumel
17+
*
18+
*/
19+
public class MovieService {
20+
21+
private MovieRepository movieRepository;
22+
23+
24+
public MovieService(MovieRepository movieRepository) {
25+
26+
this.movieRepository = movieRepository;
27+
}
28+
29+
30+
public Collection<Movie> findMoviesByGenre(Genre genre) {
31+
32+
Collection<Movie> allMovies = movieRepository.findAll().stream().filter(movie -> movie.getGenre() == genre).collect(Collectors.toList());
33+
34+
35+
return allMovies;
36+
37+
}
38+
39+
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
package com.testing.javatest.movie.service;
2+
3+
import static org.hamcrest.CoreMatchers.is;
4+
import static org.junit.Assert.assertThat;
5+
import static org.junit.Assert.assertTrue;
6+
7+
import java.util.ArrayList;
8+
import java.util.Arrays;
9+
import java.util.Collection;
10+
import java.util.List;
11+
import java.util.stream.Collector;
12+
import java.util.stream.Collectors;
13+
14+
import org.junit.Test;
15+
import org.mockito.Mockito;
16+
17+
import com.testing.javatest.movie.data.MovieRepository;
18+
import com.testing.javatest.movie.model.Genre;
19+
import com.testing.javatest.movie.model.Movie;
20+
21+
public class MovieServiceTest {
22+
23+
@Test
24+
public void return_movies_by_genre() {
25+
26+
MovieRepository movieRepository = Mockito.mock(MovieRepository.class);
27+
28+
Mockito.when(movieRepository.findAll()).thenReturn(Arrays.asList(
29+
new Movie(1,"Pelicula 1", 200, Genre.ACTION),
30+
new Movie(2,"Pelicula 1", 200, Genre.THILLER),
31+
new Movie(3,"Pelicula 1", 200, Genre.COMEDY),
32+
new Movie(4,"Pelicula 1", 200, Genre.THILLER),
33+
new Movie(5,"Pelicula 1", 200, Genre.HORROR),
34+
new Movie(6,"Pelicula 1", 200, Genre.COMEDY),
35+
new Movie(7,"Pelicula 1", 200, Genre.ACTION)));
36+
37+
MovieService movieService = new MovieService(movieRepository);
38+
39+
Collection<Movie> movies = movieService.findMoviesByGenre(Genre.COMEDY);
40+
//Dado la coleccion de movies, se optienen los id se pasan a una lista
41+
List<Integer> moveIds = movies.stream().map(movie -> movie.getId()).collect(Collectors.toList());
42+
43+
assertThat(moveIds, is(Arrays.asList(3,6)));
44+
}
45+
46+
}

0 commit comments

Comments
 (0)