Permalink
Browse files

all tests passing, refactor for packages

  • Loading branch information...
1 parent 5ac19be commit cd8d531788080539d3a9d1afe362ec38485aeba9 @leadVisionary committed Apr 27, 2012
@@ -6,4 +6,19 @@
public ReviewDecorator(Review toDecorate){
this.decoratedReview = toDecorate;
}
+
+ @Override
+ public String getDescription() {
+ return decoratedReview.getDescription();
+ }
+
+ @Override
+ public Reviewer getReviewer() {
+ return decoratedReview.getReviewer();
+ }
+
+ @Override
+ public Reviewable getReviewed() {
+ return decoratedReview.getReviewed();
+ }
}
@@ -1,14 +1,15 @@
package com.visionarysoftwaresolutions.reviewable;
+import com.visionarysoftwaresolutions.reviewable.stubs.*;
import org.junit.Test;
import static org.junit.Assert.*;
public class ReviewableTests {
+ Reviewer nick = new User("nick");
+ Reviewable food = new Food("Phonecian Cafe Hummus");
+
@Test
public void testReview() {
- //Given I have a Reviewer and a Reviewable
- Reviewer nick = new User("nick");
- Reviewable food = new Food("Phonecian Cafe Hummus");
//When I have the Reviewer review the Reviewable
Review result = nick.review(food,
"It is so creamy and delicious!");
@@ -20,9 +21,6 @@ public void testReview() {
@Test
public void testRatedReview(){
- //Given I have a Reviewer and a Reviewable
- Reviewer nick = new User("nick");
- Reviewable food = new Food("Phonecian Cafe Hummus");
//When I have the Reviewer rate the Reviewable
RatedReview result = nick.rate(food,
"It is so creamy and delicious!",
@@ -38,7 +36,19 @@ public void testRatedReview(){
@Test
public void testDatedReview(){
+ //Given I'm reviewing something today
java.util.Date today = new java.util.Date();
- fail("do something");
+ //When I have a reviewer rate a reviewable
+ RatedReview result = nick.rate(food,
+ "It is so creamy and delicious!",
+ FiveStarRatingScale.five());
+ //And I want a Dated Review
+ DatedReview datedResult = new DatedReview(result);
+ //Then it is rated
+ assertEquals(datedResult.getReviewer(), nick);
+ assertEquals(datedResult.getReviewed(), food);
+ assertTrue(today.equals(datedResult.getDate()));
+ assertEquals("It is so creamy and delicious! on " + today,
+ datedResult.getDescription());
}
}
@@ -0,0 +1,11 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class BasicFoodReview extends FoodReview {
+
+ public BasicFoodReview(Reviewer reviewer, Reviewable reviewed, String description){
+ super(reviewer, reviewed, description);
+ }
+}
@@ -0,0 +1,23 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+import com.visionarysoftwaresolutions.reviewable.RatedReview;
+import com.visionarysoftwaresolutions.reviewable.ReviewDecorator;
+import java.util.Date;
+
+public class DatedReview extends ReviewDecorator {
+
+ private Date date;
+
+ public DatedReview(RatedReview review){
+ super(review);
+ date = new java.util.Date();
+ }
+
+ @Override
+ public String getDescription() {
+ return super.getDescription() + " on " + date.toString();
+ }
+
+ public Date getDate(){
+ return date;
+ }
+}
@@ -0,0 +1,50 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Rating;
+import com.visionarysoftwaresolutions.reviewable.RatingScale;
+
+public class FiveStarRatingScale implements RatingScale {
+ private Rating stars;
+
+ public static RatingScale five() {
+ FiveStarRatingScale five = new FiveStarRatingScale(5);
+ return five;
+ }
+
+ private FiveStarRatingScale(int i) {
+ rate(i);
+ }
+
+ public final void rate(int stars){
+ if(stars < 0){
+ throw new IllegalArgumentException("Must be greater than 0 stars");
+ }
+ if(stars > 5){
+ throw new IllegalArgumentException("Can't be more than 5 stars");
+ }
+ this.stars = new NumericalRating(stars, this);
+ }
+
+ @Override
+ public String[] range() {
+ return new String[] { "0", "1", "2", "3", "4", "5" };
+ }
+
+ @Override
+ public Rating getRating() {
+ return stars;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ return !(object instanceof FiveStarRatingScale) &&
+ stars == ((FiveStarRatingScale) object).stars;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 3;
+ hash = 17 * hash + this.stars.hashCode();
+ return hash;
+ }
+}
@@ -0,0 +1,18 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class Food implements Reviewable {
+ private String name;
+
+ public Food(String string) {
+ name = string;
+ }
+
+ @Override
+ public Review getReview(Reviewer reviewer) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+}
@@ -0,0 +1,32 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public abstract class FoodReview implements Review {
+ private String description;
+ private Reviewer reviewer;
+ private Reviewable reviewed;
+
+ public FoodReview(Reviewer reviewer, Reviewable reviewed, String description){
+ this.reviewer = reviewer;
+ this.reviewed = reviewed;
+ this.description = description;
+ }
+
+ @Override
+ public String getDescription() {
+ return description;
+ }
+
+ @Override
+ public Reviewable getReviewed() {
+ return reviewed;
+ }
+
+ @Override
+ public Reviewer getReviewer() {
+ return reviewer;
+ }
+}
@@ -0,0 +1,38 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Rating;
+import com.visionarysoftwaresolutions.reviewable.RatingScale;
+
+public class NumericalRating implements Rating {
+ private RatingScale scale;
+ private int number;
+ // No external construction!
+ private NumericalRating(){}
+
+ public NumericalRating(int number, RatingScale scale){
+ this.number = number;
+ this.scale = scale;
+ }
+
+ @Override
+ public RatingScale getScale() {
+ return scale;
+ }
+
+ @Override
+ public boolean equals(Object object) {
+ if(!(object instanceof NumericalRating)){
+ return false;
+ }
+ NumericalRating rating = (NumericalRating) object;
+ return number == rating.number;
+ }
+
+ @Override
+ public int hashCode() {
+ int hash = 3;
+ hash = 17 * hash + this.number;
+ hash = 17 * hash + (this.getScale() != null ? this.getScale().hashCode() : 0);
+ return hash;
+ }
+}
@@ -0,0 +1,28 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.RatedReview;
+import com.visionarysoftwaresolutions.reviewable.RatingScale;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+/**
+ *
+ * @author master
+ */
+public class RatedFoodReview extends FoodReview implements RatedReview {
+ private RatingScale scale;
+
+ public RatedFoodReview(Reviewer reviewer,
+ Reviewable reviewed,
+ String description,
+ RatingScale scale)
+ {
+ super(reviewer, reviewed, description);
+ this.scale = scale;
+ }
+
+ @Override
+ public RatingScale getRatingScale() {
+ return scale;
+ }
+}
@@ -0,0 +1,25 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.RatedReview;
+import com.visionarysoftwaresolutions.reviewable.RatingScale;
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class User implements Reviewer {
+ private String name;
+
+ public User(String string) {
+ name = string;
+ }
+
+ @Override
+ public Review review(Reviewable toReview, String description) {
+ return new BasicFoodReview(this, toReview, description);
+ }
+
+ @Override
+ public RatedReview rate(Reviewable toReview, String description, RatingScale scale) {
+ return new RatedFoodReview(this,toReview,description,scale);
+ }
+}

0 comments on commit cd8d531

Please sign in to comment.