Permalink
Browse files

broke out rating into separate project

  • Loading branch information...
1 parent 996d332 commit 00960b3ad5c8e871c3e255bd5f3089716aff8514 unknown committed Aug 12, 2012
@@ -1,18 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.rating;
-
-import com.visionarysoftwaresolutions.reviewable.Review;
-
-/**
- *
- * @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();
-}
@@ -1,8 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.rating;
-
-import com.visionarysoftwaresolutions.reviewable.Reviewable;
-import com.visionarysoftwaresolutions.reviewable.Reviewer;
-
-public interface Rater extends Reviewer {
- public abstract RatedReview rate(Reviewable toReview, String description, RatingScale scale);
-}
@@ -1,5 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.rating;
-
-public interface Rating {
- public abstract RatingScale getScale();
-}
@@ -1,15 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.rating;
-
-import com.visionarysoftwaresolutions.reviewable.rating.Rating;
-
-/**
- *
- * @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();
-}
@@ -1,14 +1,11 @@
package com.visionarysoftwaresolutions.reviewable;
-import com.visionarysoftwaresolutions.reviewable.rating.Rater;
-import com.visionarysoftwaresolutions.reviewable.rating.RatingScale;
-import com.visionarysoftwaresolutions.reviewable.rating.RatedReview;
import com.visionarysoftwaresolutions.reviewable.stubs.*;
import org.junit.Test;
import static org.junit.Assert.*;
public class ReviewableTest {
- Rater nick = new User("nick");
+ Reviewer nick = new User("nick");
Reviewable food = new Food("Phonecian Cafe Hummus");
@Test
@@ -22,29 +19,14 @@ public void testReview() {
assertEquals(result.getDescription(), "It is so creamy and delicious!");
}
- @Test
- public void testRatedReview(){
- //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(){
//Given I'm reviewing something today
java.util.Date today = new java.util.Date();
//When I have a reviewer rate a reviewable
- RatedReview result = nick.rate(food,
- "It is so creamy and delicious!",
- FiveStarRatingScale.five());
+ Review result = nick.review(food,
+ "It is so creamy and delicious!");
//And I want a Dated Review
DatedReview datedResult = new DatedReview(result);
//Then it is rated
@@ -1,13 +1,14 @@
package com.visionarysoftwaresolutions.reviewable.stubs;
-import com.visionarysoftwaresolutions.reviewable.rating.RatedReview;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
import com.visionarysoftwaresolutions.reviewable.ReviewDecorator;
import java.util.Date;
public class DatedReview extends ReviewDecorator {
private Date date;
- public DatedReview(RatedReview review){
+ public DatedReview(Review review){
super(review);
date = new java.util.Date();
}
@@ -1,50 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.stubs;
-
-import com.visionarysoftwaresolutions.reviewable.rating.Rating;
-import com.visionarysoftwaresolutions.reviewable.rating.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;
- }
-}
@@ -1,38 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.stubs;
-
-import com.visionarysoftwaresolutions.reviewable.rating.Rating;
-import com.visionarysoftwaresolutions.reviewable.rating.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;
- }
-}
@@ -1,28 +0,0 @@
-package com.visionarysoftwaresolutions.reviewable.stubs;
-
-import com.visionarysoftwaresolutions.reviewable.rating.RatedReview;
-import com.visionarysoftwaresolutions.reviewable.rating.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;
- }
-}
@@ -1,12 +1,10 @@
package com.visionarysoftwaresolutions.reviewable.stubs;
-import com.visionarysoftwaresolutions.reviewable.rating.RatedReview;
-import com.visionarysoftwaresolutions.reviewable.rating.Rater;
-import com.visionarysoftwaresolutions.reviewable.rating.RatingScale;
import com.visionarysoftwaresolutions.reviewable.Review;
import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
-public class User implements Rater {
+public class User implements Reviewer {
private String name;
public User(String string) {
@@ -17,9 +15,4 @@ public User(String string) {
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 00960b3

Please sign in to comment.