#631 - Partial Response : Return video details as json string.
This commit is contained in:
parent
b7dbb4049c
commit
a0c081f5ea
@ -29,7 +29,7 @@ package com.iluwatar.partialresponse;
|
||||
* <p>
|
||||
*/
|
||||
public class Video {
|
||||
private String id;
|
||||
private Integer id;
|
||||
private String title;
|
||||
private Integer length;
|
||||
private String description;
|
||||
@ -41,10 +41,10 @@ public class Video {
|
||||
* @param title video title
|
||||
* @param length video length in minutes
|
||||
* @param description video description by publisher
|
||||
* @param director video director name
|
||||
* @param language video language {private, public}
|
||||
* @param director video director name
|
||||
* @param language video language {private, public}
|
||||
*/
|
||||
public Video(String id, String title, Integer length, String description, String director, String language) {
|
||||
public Video(Integer id, String title, Integer length, String description, String director, String language) {
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.length = length;
|
||||
@ -55,13 +55,12 @@ public class Video {
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Video{" +
|
||||
"id='" + id + '\'' +
|
||||
", title='" + title + '\'' +
|
||||
", length=" + length +
|
||||
", description='" + description + '\'' +
|
||||
", director='" + director + '\'' +
|
||||
", language='" + language + '\'' +
|
||||
'}';
|
||||
return "{" +
|
||||
"\"id\": \"" + id + "\"," +
|
||||
"\"title\": \"" + title + "\"," +
|
||||
"\"description\": \"" + description + "\"," +
|
||||
"\"director\": \"" + director + "\"," +
|
||||
"\"language\": \"" + language + "\"," +
|
||||
"}";
|
||||
}
|
||||
}
|
||||
|
@ -27,13 +27,13 @@ package com.iluwatar.partialresponse;
|
||||
import java.util.Map;
|
||||
|
||||
public class VideoResource {
|
||||
private Map<String, Video> videos;
|
||||
private Map<Integer, Video> videos;
|
||||
|
||||
public VideoResource(Map<String, Video> videos) {
|
||||
public VideoResource(Map<Integer, Video> videos) {
|
||||
this.videos = videos;
|
||||
}
|
||||
|
||||
public String getDetails(String id) {
|
||||
public String getDetails(Integer id) {
|
||||
return videos.get(id).toString();
|
||||
}
|
||||
}
|
||||
|
@ -30,21 +30,25 @@ import org.junit.Test;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
public class VideoResourceTest {
|
||||
private VideoResource resource;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
Map<String, Video> videos = new HashMap<>();
|
||||
videos.put("1", new Video("1", "Avatar", 178, "epic science fiction film", "James Cameron", "English"));
|
||||
videos.put("1", new Video("2", "Godzilla Resurgence", 120, "Action & drama movie|", "Hideaki Anno", "Japanese"));
|
||||
videos.put("1", new Video("3", "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English"));
|
||||
Map<Integer, Video> videos = new HashMap<>();
|
||||
videos.put(1, new Video(1, "Avatar", 178, "epic science fiction film", "James Cameron", "English"));
|
||||
videos.put(2, new Video(2, "Godzilla Resurgence", 120, "Action & drama movie|", "Hideaki Anno", "Japanese"));
|
||||
videos.put(3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English"));
|
||||
resource = new VideoResource(videos);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGiveVideoDetailsById() {
|
||||
String details = resource.getDetails("1");
|
||||
System.out.println(details);
|
||||
String details = resource.getDetails(1);
|
||||
|
||||
String expectedDetails = "{\"id\": \"1\",\"title\": \"Avatar\",\"description\": \"epic science fiction film\",\"director\": \"James Cameron\",\"language\": \"English\",}";
|
||||
assertEquals(details, expectedDetails);
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user