Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

added review factory and refactored stubs

  • Loading branch information...
commit 026c68e3100660f35c467171d0572ad6893648c6 1 parent 00960b3
unknown authored
View
5 src/main/java/com/visionarysoftwaresolutions/reviewable/ReviewFactory.java
@@ -0,0 +1,5 @@
+package com.visionarysoftwaresolutions.reviewable;
+
+public interface ReviewFactory {
+ public Review create(Reviewer reviewer, Reviewable toReview, String description);
+}
View
9 src/test/java/com/visionarysoftwaresolutions/reviewable/ReviewableTest.java
@@ -21,7 +21,7 @@ public void testReview() {
@Test
- public void testDatedReview(){
+ public void testReviewDecorator(){
//Given I'm reviewing something today
java.util.Date today = new java.util.Date();
//When I have a reviewer rate a reviewable
@@ -32,8 +32,13 @@ public void testDatedReview(){
//Then it is rated
assertEquals(datedResult.getReviewer(), nick);
assertEquals(datedResult.getReviewed(), food);
- assertEquals(today.compareTo(datedResult.getDate()),-1);
+ assertEquals(-1, today.compareTo(datedResult.getDate()));
assertEquals("It is so creamy and delicious! on " + today,
datedResult.getDescription());
}
+
+ @Test
+ public void testReviewFactory(){
+ assertNotNull(new StubReviewFactory().create(nick, food, "can be created!"));
+ }
}
View
11 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/BasicFoodReview.java
@@ -1,11 +0,0 @@
-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);
- }
-}
View
10 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/FoodReview.java
@@ -4,12 +4,12 @@
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 final class FoodReview implements Review {
+ private final String description;
+ private final Reviewer reviewer;
+ private final Reviewable reviewed;
- public FoodReview(Reviewer reviewer, Reviewable reviewed, String description){
+ FoodReview(Reviewer reviewer, Reviewable reviewed, String description){
this.reviewer = reviewer;
this.reviewed = reviewed;
this.description = description;
View
25 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/StubReviewFactory.java
@@ -0,0 +1,25 @@
+package com.visionarysoftwaresolutions.reviewable.stubs;
+
+import com.visionarysoftwaresolutions.reviewable.Review;
+import com.visionarysoftwaresolutions.reviewable.ReviewFactory;
+import com.visionarysoftwaresolutions.reviewable.Reviewable;
+import com.visionarysoftwaresolutions.reviewable.Reviewer;
+
+public class StubReviewFactory implements ReviewFactory {
+ private boolean wantsDate = true;
+
+ @Override
+ public Review create(Reviewer reviewer, Reviewable reviewed, String description){
+ return pickReview(reviewer, reviewed, description);
+ }
+
+ public void doNotWant(){
+ wantsDate = false;
+ }
+
+ private Review pickReview(Reviewer reviewer, Reviewable reviewed, String description){
+ return (wantsDate) ?
+ new FoodReview(reviewer, reviewed, description) :
+ new DatedReview(new FoodReview(reviewer, reviewed, description));
+ }
+}
View
2  src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/User.java
@@ -13,6 +13,6 @@ public User(String string) {
@Override
public Review review(Reviewable toReview, String description) {
- return new BasicFoodReview(this, toReview, description);
+ return new StubReviewFactory().create(this, toReview, description);
}
}

0 comments on commit 026c68e

Please sign in to comment.
Something went wrong with that request. Please try again.