LOAD REVIEW
Add support to persistence for loading reviews.
Similarly to the previous task, we only need to concern ourselves with reading a MovieList that contains a review.
Test 102. Reading an XML stream that contains text for a rating element results in that rating having an attached review.
We need to add a test to TestMovieListReading. Just for fun, we'll take a slightly different approach this time. The existing test for reading a movie uses a fixture that uses a movie with two ratings. Let's add a review to one of them.
Test 102: Reading an XML stream that contains text for a rating element results in that rating having an attached review
First, a tweak to setUp():
oneMoviePrefix = "<movielist>" + "<movie name=\"Star Wars\" " + "category=\"Science Fiction\">" + "<ratings>" + "<rating value=\"3\" " + "source=\"Dave\" />" + "<rating value=\"5\" " + "source=\"Jason\">" + "Great movie!" + "</rating>" + "</ratings>" + "</movie>";
This needs a corresponding tweak to the test:
public void testReadingOneMovie() throws Exception { //... Rating firstRating =(Rating)ratingIterator.next();
//... assertFalse("First rating should not have a review.", firstRating.hasReview()); //... Rating secondRating =(Rating)ratingIterator.next();
//... assertTrue("Second rating should have a review.", secondRating.hasReview());
assertEquals("Second rating's review is wrong.", "Great movie!", secondRating.getReview()); //... }
As expected, this test fails on the assertion that the second rating has a review. To correct that, we need to revisit processRating() in XMLMovieListReader:
private Rating processRating(Element ratingElement) throws IOException { //... String review = ratingElement.getTextTrim(); return new Rating(value, source, review); }
Green.
|
No comments:
Post a Comment