Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added review factory and refactored stubs

  • Loading branch information...
commit 026c68e3100660f35c467171d0572ad6893648c6 1 parent 00960b3
unknown authored
5 src/main/java/com/visionarysoftwaresolutions/reviewable/ReviewFactory.java
... ... @@ -0,0 +1,5 @@
  1 +package com.visionarysoftwaresolutions.reviewable;
  2 +
  3 +public interface ReviewFactory {
  4 + public Review create(Reviewer reviewer, Reviewable toReview, String description);
  5 +}
9 src/test/java/com/visionarysoftwaresolutions/reviewable/ReviewableTest.java
@@ -21,7 +21,7 @@ public void testReview() {
21 21
22 22
23 23 @Test
24   - public void testDatedReview(){
  24 + public void testReviewDecorator(){
25 25 //Given I'm reviewing something today
26 26 java.util.Date today = new java.util.Date();
27 27 //When I have a reviewer rate a reviewable
@@ -32,8 +32,13 @@ public void testDatedReview(){
32 32 //Then it is rated
33 33 assertEquals(datedResult.getReviewer(), nick);
34 34 assertEquals(datedResult.getReviewed(), food);
35   - assertEquals(today.compareTo(datedResult.getDate()),-1);
  35 + assertEquals(-1, today.compareTo(datedResult.getDate()));
36 36 assertEquals("It is so creamy and delicious! on " + today,
37 37 datedResult.getDescription());
38 38 }
  39 +
  40 + @Test
  41 + public void testReviewFactory(){
  42 + assertNotNull(new StubReviewFactory().create(nick, food, "can be created!"));
  43 + }
39 44 }
11 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/BasicFoodReview.java
... ... @@ -1,11 +0,0 @@
1   -package com.visionarysoftwaresolutions.reviewable.stubs;
2   -
3   -import com.visionarysoftwaresolutions.reviewable.Reviewable;
4   -import com.visionarysoftwaresolutions.reviewable.Reviewer;
5   -
6   -public class BasicFoodReview extends FoodReview {
7   -
8   - public BasicFoodReview(Reviewer reviewer, Reviewable reviewed, String description){
9   - super(reviewer, reviewed, description);
10   - }
11   -}
10 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/FoodReview.java
@@ -4,12 +4,12 @@
4 4 import com.visionarysoftwaresolutions.reviewable.Reviewable;
5 5 import com.visionarysoftwaresolutions.reviewable.Reviewer;
6 6
7   -public abstract class FoodReview implements Review {
8   - private String description;
9   - private Reviewer reviewer;
10   - private Reviewable reviewed;
  7 +public final class FoodReview implements Review {
  8 + private final String description;
  9 + private final Reviewer reviewer;
  10 + private final Reviewable reviewed;
11 11
12   - public FoodReview(Reviewer reviewer, Reviewable reviewed, String description){
  12 + FoodReview(Reviewer reviewer, Reviewable reviewed, String description){
13 13 this.reviewer = reviewer;
14 14 this.reviewed = reviewed;
15 15 this.description = description;
25 src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/StubReviewFactory.java
... ... @@ -0,0 +1,25 @@
  1 +package com.visionarysoftwaresolutions.reviewable.stubs;
  2 +
  3 +import com.visionarysoftwaresolutions.reviewable.Review;
  4 +import com.visionarysoftwaresolutions.reviewable.ReviewFactory;
  5 +import com.visionarysoftwaresolutions.reviewable.Reviewable;
  6 +import com.visionarysoftwaresolutions.reviewable.Reviewer;
  7 +
  8 +public class StubReviewFactory implements ReviewFactory {
  9 + private boolean wantsDate = true;
  10 +
  11 + @Override
  12 + public Review create(Reviewer reviewer, Reviewable reviewed, String description){
  13 + return pickReview(reviewer, reviewed, description);
  14 + }
  15 +
  16 + public void doNotWant(){
  17 + wantsDate = false;
  18 + }
  19 +
  20 + private Review pickReview(Reviewer reviewer, Reviewable reviewed, String description){
  21 + return (wantsDate) ?
  22 + new FoodReview(reviewer, reviewed, description) :
  23 + new DatedReview(new FoodReview(reviewer, reviewed, description));
  24 + }
  25 +}
2  src/test/java/com/visionarysoftwaresolutions/reviewable/stubs/User.java
@@ -13,6 +13,6 @@ public User(String string) {
13 13
14 14 @Override
15 15 public Review review(Reviewable toReview, String description) {
16   - return new BasicFoodReview(this, toReview, description);
  16 + return new StubReviewFactory().create(this, toReview, description);
17 17 }
18 18 }

0 comments on commit 026c68e

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