Permalink
Browse files

got rated reviews tested

  • Loading branch information...
1 parent 99f1a70 commit 5ac19beb705c73386d415d4d43e93fad1c99ab3c @leadVisionary committed Apr 27, 2012
@@ -0,0 +1,16 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description RatedReview is a simple interface for a review that an entity that
+ * reviews other entities on a scale.
+ * We try to make it as generalizable as possible so it can apply in multiple situations
+ * Scenario: A Reviewer creates a RatedReview for a Reviewable with a description on a RatingScale
+ * Example: Nick creates a RatedReview of YourBody
+ * with a RatingScale of OneToTenRatingScale
+ * with a rating of 10 and a description "It's awesome!"
+ */
+public interface RatedReview extends Review {
+ public RatingScale getRatingScale();
+}
@@ -0,0 +1,5 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+public interface Rating {
+ public abstract RatingScale getScale();
+}
@@ -0,0 +1,13 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description RatingScale is a simple interface for a rating scale used in a review.
+ * We try to make it as generalizable as possible so it can apply in multiple situations
+ * Scenario: A Reviewer creates a Review for a Reviewable, rating it on a RatingScale with a Description
+ */
+public interface RatingScale {
+ public abstract String[] range();
+ public abstract Rating getRating();
+}
@@ -0,0 +1,16 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description Review is a simple interface for a review that an entity that
+ * reviews other entities would take. We try to make it as generalizable as
+ * possible so it can apply in multiple situations
+ * Scenario: A Reviewer creates a Review for a Reviewable with a description
+ * Example: Nick creates a Review of YourFace with a description "It's awesome!"
+ */
+public interface Review {
+ public abstract String getDescription();
+ public abstract Reviewer getReviewer();
+ public abstract Reviewable getReviewed();
+}
@@ -0,0 +1,9 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+public abstract class ReviewDecorator implements Review {
+ protected final Review decoratedReview;
+
+ public ReviewDecorator(Review toDecorate){
+ this.decoratedReview = toDecorate;
+ }
+}
@@ -0,0 +1,14 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description Reviewable is a simple interface for a role that an entity that
+ * is reviewable would take. We try to make it as generalizable as
+ * possible so it can apply in multiple situations.
+ * We assert a reviewable should know about its review from a Reviewer, and should be able to retrieve it.
+ * Scenario: A Reviewer creates a Review for a Reviewable, rating it on a Scale with a Description
+ */
+public interface Reviewable {
+ public abstract Review getReview(Reviewer reviewer);
+}
@@ -0,0 +1,14 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @author Nicholas Vaidyanathan, Lead Visionary of Visionary Software Solutions
+ * @description Reviewer is a simple interface for a role that an entity that
+ * reviews other entities would take. We try to make it as generalizable as
+ * possible so it can apply in multiple situations
+ * Scenario: A Reviewer creates a Review for a Reviewable, rating it on a RatingScale with a Description
+ */
+public interface Reviewer {
+ public abstract Review review(Reviewable toReview, String description);
+ public abstract RatedReview rate(Reviewable toReview, String description, RatingScale scale);
+}
@@ -0,0 +1,8 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+public class BasicFoodReview extends FoodReview {
+
+ public BasicFoodReview(Reviewer reviewer, Reviewable reviewed, String description){
+ super(reviewer, reviewed, description);
+ }
+}
@@ -0,0 +1,47 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+class FiveStarRatingScale implements RatingScale {
+ private Rating stars;
+
+ 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,14 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+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,28 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+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,35 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+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,23 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+/**
+ *
+ * @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,44 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+import org.junit.Test;
+import static org.junit.Assert.*;
+
+public class ReviewableTests {
+ @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!");
+ //Then it is reviewed
+ assertEquals(result.getReviewer(), nick);
+ assertEquals(result.getReviewed(), food);
+ assertEquals(result.getDescription(), "It is so creamy and delicious!");
+ }
+
+ @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!",
+ FiveStarRatingScale.five());
+ //Then it is rated
+ assertEquals(result.getReviewer(), nick);
+ assertEquals(result.getReviewed(), food);
+ RatingScale howRated = result.getRatingScale();
+ assertEquals(howRated.getRating(), new NumericalRating(5,howRated));
+ assertArrayEquals(howRated.range(),
+ new String[] { "0", "1", "2", "3", "4", "5" });
+ }
+
+ @Test
+ public void testDatedReview(){
+ java.util.Date today = new java.util.Date();
+ fail("do something");
+ }
+}
@@ -0,0 +1,19 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+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 5ac19be

Please sign in to comment.