#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>
|
* <p>
|
||||||
*/
|
*/
|
||||||
public class Video {
|
public class Video {
|
||||||
private String id;
|
private Integer id;
|
||||||
private String title;
|
private String title;
|
||||||
private Integer length;
|
private Integer length;
|
||||||
private String description;
|
private String description;
|
||||||
@ -41,10 +41,10 @@ public class Video {
|
|||||||
* @param title video title
|
* @param title video title
|
||||||
* @param length video length in minutes
|
* @param length video length in minutes
|
||||||
* @param description video description by publisher
|
* @param description video description by publisher
|
||||||
* @param director video director name
|
* @param director video director name
|
||||||
* @param language video language {private, public}
|
* @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.id = id;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.length = length;
|
this.length = length;
|
||||||
@ -55,13 +55,12 @@ public class Video {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "Video{" +
|
return "{" +
|
||||||
"id='" + id + '\'' +
|
"\"id\": \"" + id + "\"," +
|
||||||
", title='" + title + '\'' +
|
"\"title\": \"" + title + "\"," +
|
||||||
", length=" + length +
|
"\"description\": \"" + description + "\"," +
|
||||||
", description='" + description + '\'' +
|
"\"director\": \"" + director + "\"," +
|
||||||
", director='" + director + '\'' +
|
"\"language\": \"" + language + "\"," +
|
||||||
", language='" + language + '\'' +
|
"}";
|
||||||
'}';
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -27,13 +27,13 @@ package com.iluwatar.partialresponse;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
public class VideoResource {
|
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;
|
this.videos = videos;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDetails(String id) {
|
public String getDetails(Integer id) {
|
||||||
return videos.get(id).toString();
|
return videos.get(id).toString();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,21 +30,25 @@ import org.junit.Test;
|
|||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
public class VideoResourceTest {
|
public class VideoResourceTest {
|
||||||
private VideoResource resource;
|
private VideoResource resource;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
Map<String, Video> videos = new HashMap<>();
|
Map<Integer, Video> videos = new HashMap<>();
|
||||||
videos.put("1", new Video("1", "Avatar", 178, "epic science fiction film", "James Cameron", "English"));
|
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(2, 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"));
|
videos.put(3, new Video(3, "Interstellar", 169, "Adventure & Sci-Fi", "Christopher Nolan", "English"));
|
||||||
resource = new VideoResource(videos);
|
resource = new VideoResource(videos);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void shouldGiveVideoDetailsById() {
|
public void shouldGiveVideoDetailsById() {
|
||||||
String details = resource.getDetails("1");
|
String details = resource.getDetails(1);
|
||||||
System.out.println(details);
|
|
||||||
|
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