-
Notifications
You must be signed in to change notification settings - Fork 193
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Kata/collections/test #47
Open
saket88
wants to merge
17
commits into
serenity-dojo:kata/collections/start
Choose a base branch
from
saket88:kata/collections/test
base: kata/collections/start
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
6ea9e68
Replaced duplicate packag-info with a readme
wakaleo 38ab879
Replaced duplicate packag-info with a readme
wakaleo 858547c
Added Serenity outputs for CircleCI
wakaleo 72de6b7
Configured Java 8 in the CircleCI build config
wakaleo 11ef263
Configured Java 8 in the CircleCI build config
wakaleo 2f500d8
Added first test case
a20d881
Added second test case
1eb2eb1
Added third test case and Refactored first test case too
376f0a8
A failed test case for fourth scenario
09bbedb
Added a passing test for fourth test case. Just replaced collection w…
975631b
Added a passing test for fifth test case. Just replaced collection wi…
8613da2
Added sixth test case
9bf2771
Added failed test case for seventh item
3e0278d
Added passing test case for seventh item
4714bd9
Added passing test case for eightht item
6ccf818
Added passing test case for 9,10 and 11 test case
08a003d
Code commenting and refactored. Added Strategy pattern after reviewin…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
machine: | ||
java: | ||
version: oraclejdk8 | ||
|
||
test: | ||
post: | ||
- mkdir -p $CIRCLE_TEST_REPORTS/junit/ | ||
- find . -type f -regex ".*/target/surefire-reports/.*xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; | ||
- find . -type f -regex ".*/target/site/serenity/SERENITY-JUNIT-*.xml" -exec cp {} $CIRCLE_TEST_REPORTS/junit/ \; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package vetclinic; | ||
|
||
public enum Breed { | ||
Cat, Dog, Rabbit, Fish, Parrot | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package vetclinic; | ||
|
||
import com.google.common.base.Objects; | ||
|
||
public class Pet { | ||
private final String name; | ||
private final Breed breed; | ||
|
||
public Pet(String name, Breed breed) { | ||
this.name = name; | ||
this.breed = breed; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public Breed getBreed() { | ||
return breed; | ||
} | ||
|
||
public static PetBuilder dog() { return new PetBuilder(Breed.Dog);} | ||
public static PetBuilder cat() { return new PetBuilder(Breed.Cat);} | ||
public static PetBuilder rabbit() { return new PetBuilder(Breed.Rabbit);} | ||
public static PetBuilder parrot() { return new PetBuilder(Breed.Parrot);} | ||
public static PetBuilder fish() { return new PetBuilder(Breed.Fish);} | ||
|
||
public static class PetBuilder { | ||
private final Breed breed; | ||
|
||
public PetBuilder(Breed breed) { | ||
this.breed = breed; | ||
} | ||
|
||
public Pet named(String name) { | ||
return new Pet(name, breed); | ||
} | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "a " + breed + " called " + name; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) return true; | ||
if (o == null || getClass() != o.getClass()) return false; | ||
Pet pet = (Pet) o; | ||
return Objects.equal(name, pet.name) && breed == pet.breed; | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(name, breed); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,88 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import com.google.common.collect.ImmutableList; | ||
import vetclinic.Breed; | ||
import vetclinic.Pet; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* A utility class to generate pet hotels with pets already booked | ||
*/ | ||
public class APetHotel { | ||
private final String name; | ||
private final int count; | ||
private Collection<Pet> pets = new TreeSet<>(Comparator.comparing(Pet::getName)); | ||
private Queue<Pet> waitingPets = new LinkedList<>(); | ||
|
||
public Queue<Pet> getWaitingPets() { | ||
return waitingPets; | ||
} | ||
|
||
public APetHotel(String hotelName, int petCount) { | ||
this.name=hotelName; | ||
this.count=petCount; | ||
} | ||
|
||
public static PetHotelBuilder with(int petCount) { | ||
return new PetHotelBuilder(petCount); | ||
} | ||
|
||
public Collection<Pet> getPets() { | ||
return pets; | ||
} | ||
|
||
public BookingConfirmation checkIn(Pet pet) { | ||
BookingStratgey bookingStrategy = BOOKING_STARTEGY.get(currentAvailability()); | ||
return bookingStrategy.checkIn(pet); | ||
} | ||
|
||
|
||
private static final Map<HotelAvailability,BookingStratgey> BOOKING_STARTEGY= new HashMap<>();{ | ||
BOOKING_STARTEGY.put(HotelAvailability.AVAILABLE,new ConfirmBookingStrategy(pets)); | ||
BOOKING_STARTEGY.put(HotelAvailability.FULL,new WaitingStrategy(waitingPets)); | ||
} | ||
|
||
private HotelAvailability currentAvailability() { | ||
return ((pets.size() < count)) ? HotelAvailability.AVAILABLE : HotelAvailability.FULL; | ||
} | ||
|
||
public void checkOut(Pet pet) { | ||
pets.remove(pet); | ||
if(!waitingPets.isEmpty()){ | ||
pets.add(waitingPets.poll()); | ||
} | ||
|
||
} | ||
|
||
public static class PetHotelBuilder { | ||
private final int petCount; | ||
|
||
public PetHotelBuilder(int petCount) { | ||
this.petCount=petCount; | ||
} | ||
|
||
public APetHotel named(String hotelName) { | ||
return new APetHotel(hotelName,petCount); | ||
} | ||
|
||
private Pet somePet(int petCount) { | ||
return new Pet(someName(petCount), someBreed()); | ||
} | ||
|
||
private final static Random random = new Random(); | ||
|
||
private Breed someBreed() { | ||
return Breed.values()[ random.nextInt(Breed.values().length) ]; | ||
} | ||
|
||
private final static List<String> PET_NAMES = ImmutableList.of("Fido","Felix","Rover","Spot"); | ||
|
||
public void checkInDefaultPets() { | ||
somePet(petCount); | ||
} | ||
private String someName(int petCount) { | ||
return PET_NAMES.get(random.nextInt(PET_NAMES.size())) + " " + petCount; | ||
} | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/vetclinic/collections/katas/BookingConfirmation.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
import java.util.concurrent.atomic.AtomicInteger; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public abstract class BookingConfirmation implements BookingResponse{ | ||
private static AtomicInteger bookingNumberCounter = new AtomicInteger(); | ||
private final int number; | ||
private final Pet pet; | ||
|
||
public BookingConfirmation (int number, Pet pet) { | ||
this.number = number; | ||
this.pet = pet; | ||
} | ||
|
||
public static BookingConfirmation confirmedFor(Pet pet) { | ||
return new ConfirmedBooking(bookingNumberCounter.get(),pet); | ||
} | ||
|
||
public static BookingConfirmation waitingFor(Pet pet) { | ||
return new PlacedOnWaitingList(bookingNumberCounter.get(),pet); | ||
} | ||
|
||
public Pet getPet() { | ||
return pet; | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/vetclinic/collections/katas/BookingResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package vetclinic.collections.katas; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public interface BookingResponse { | ||
public boolean isConfirmed(); | ||
public boolean isWaiting(); | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/vetclinic/collections/katas/BookingStratgey.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public interface BookingStratgey { | ||
|
||
public BookingConfirmation checkIn( Pet pet); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The "public" keyword on methods is not required for an interface. |
||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/vetclinic/collections/katas/ConfirmBookingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
import java.util.Collection; | ||
import java.util.Comparator; | ||
import java.util.TreeSet; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public class ConfirmBookingStrategy implements BookingStratgey { | ||
private Collection pets= new TreeSet<>(Comparator.comparing(Pet::getName)); | ||
|
||
public ConfirmBookingStrategy(Collection<Pet> pets) { | ||
this.pets=pets; | ||
} | ||
|
||
public Collection getPets() { | ||
return pets; | ||
} | ||
|
||
@Override | ||
public BookingConfirmation checkIn(Pet pet) { | ||
pets.add(pet); | ||
return BookingConfirmation.confirmedFor(pet); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/vetclinic/collections/katas/ConfirmedBooking.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public class ConfirmedBooking extends BookingConfirmation { | ||
public ConfirmedBooking(int incrementAndget, Pet pet) { | ||
super(incrementAndget,pet); | ||
} | ||
|
||
@Override | ||
public boolean isConfirmed() { | ||
return true; | ||
} | ||
|
||
@Override | ||
public boolean isWaiting() { | ||
return false; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/vetclinic/collections/katas/HotelAvailability.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package vetclinic.collections.katas; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public enum HotelAvailability { | ||
AVAILABLE,FULL; | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/vetclinic/collections/katas/PlacedOnWaitingList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public class PlacedOnWaitingList extends BookingConfirmation { | ||
|
||
public PlacedOnWaitingList(int incrementAndget, Pet pet) { | ||
super(incrementAndget,pet); | ||
} | ||
@Override | ||
public boolean isConfirmed() { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean isWaiting() { | ||
return true; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/vetclinic/collections/katas/WaitingStrategy.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package vetclinic.collections.katas; | ||
|
||
import vetclinic.Pet; | ||
|
||
import java.util.LinkedList; | ||
import java.util.Queue; | ||
|
||
/** | ||
* Created by sapurani on 9/20/2016. | ||
*/ | ||
public class WaitingStrategy implements BookingStratgey { | ||
private Queue<Pet> pets = new LinkedList<>(); | ||
|
||
public WaitingStrategy(Queue<Pet> waitingPets) { | ||
this.pets=waitingPets; | ||
} | ||
|
||
@Override | ||
public BookingConfirmation checkIn(Pet pet) { | ||
pets.add(pet); | ||
return PlacedOnWaitingList.waitingFor(pet); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
/** | ||
* Our fantastic Vet Clinic app starts here | ||
**/ | ||
package vetclinic; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Your test code goes here. |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great use of the strategy pattern, well done!