-
Notifications
You must be signed in to change notification settings - Fork 195
Kata/collections/checkpoint/exercise #49
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
base: kata/collections/start
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class BookingResponse { | ||
| private boolean petsAdded; | ||
|
|
||
| public BookingResponse(boolean petsAdded) { | ||
| this.petsAdded = petsAdded; | ||
| } | ||
|
|
||
| public BookingResponse() { | ||
|
|
||
| } | ||
|
|
||
| public boolean isConfirmed() { | ||
| return petsAdded; | ||
| } | ||
|
|
||
| public boolean isOnWaitingList() { | ||
| return !petsAdded; | ||
| } | ||
|
|
||
|
|
||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas; | ||
|
|
||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
|
|
||
| import java.util.*; | ||
|
|
||
| import static java.util.Comparator.comparing; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class PetHotel { | ||
| private final Collection<Pet> registeredPets = new TreeSet<>(comparing(Pet::getName)); | ||
| private final Queue<Pet> waitingListOfPets = new LinkedList<>(); | ||
| private static final int DEFAULT_MAXIMUM_CAPACITY = 20; | ||
|
|
||
| private static String hotelName; | ||
|
|
||
| public List<Pet> getRegisteredPets() { | ||
| return new ArrayList<>(registeredPets); | ||
| } | ||
|
|
||
| public BookingResponse checkIn(Pet pet) { | ||
| return (registeredPets.size() < DEFAULT_MAXIMUM_CAPACITY) | ||
| ? new BookingResponse(registeredPets.add(pet)) | ||
| : new BookingResponse(waitingListOfPets.add(pet)); | ||
| } | ||
|
|
||
| public List<Pet> getWaitingList() { | ||
| return new ArrayList<>(waitingListOfPets); | ||
| } | ||
|
|
||
| public void checkOut(Pet pet) { | ||
| if (!waitingListOfPets.isEmpty()) { | ||
| registeredPets.remove(pet); | ||
| checkIn(waitingListOfPets.poll()); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.abilities; | ||
|
|
||
| import net.serenitybdd.screenplay.Ability; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.PetHotel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class ManageThehotel implements Ability { | ||
| private PetHotel petHotel; | ||
|
|
||
| public ManageThehotel(PetHotel petHotel) { | ||
| this.petHotel = petHotel; | ||
| } | ||
|
|
||
| // public void checkIn(Pet pet) { | ||
| // petHotel.checkIn(pet); | ||
| // } | ||
|
|
||
| public List<Pet> getRegisteredPets() { | ||
| return petHotel.getRegisteredPets(); | ||
| } | ||
|
|
||
| public List<Pet> getPetsOnWaitingList() { | ||
| return petHotel.getWaitingList(); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,41 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.questions; | ||
|
|
||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Question; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.BookingResponse; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class TheBookingStatus implements Question<Boolean> { | ||
|
|
||
| private BookingResponse bookingResponse = new BookingResponse(true); | ||
|
Contributor
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. Here, BookingResponse always created with a parameter of 'true', so the question will always return true. |
||
|
|
||
| private Pet pet; | ||
|
|
||
| public TheBookingStatus(Pet pet) { | ||
| this.pet = pet; | ||
|
Contributor
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 pet is never actually used. Remember, the booking status isn't directly related to the pet, but is the outcome the booking process when you try to book a pet into a hotel. |
||
| } | ||
|
|
||
| public static TheStatusBuilder of(Pet pet) { | ||
| return new TheStatusBuilder(pet); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean answeredBy(Actor actor) { | ||
| return bookingResponse.isConfirmed(); | ||
| } | ||
|
|
||
| public static class TheStatusBuilder { | ||
| private Pet pet; | ||
|
|
||
| public TheStatusBuilder(Pet pet) { | ||
| this.pet = pet; | ||
| } | ||
|
|
||
| public Question<Boolean> isConfirmed() { | ||
| return new TheBookingStatus(pet); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.questions; | ||
|
|
||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Question; | ||
| import net.serenitybdd.screenplay.annotations.Subject; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.PetHotel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| @Subject("the Pets in the hotel") | ||
| public class TheRegisteredGuest implements Question<List<Pet>> { | ||
| private PetHotel petHotel; | ||
|
|
||
| public TheRegisteredGuest(PetHotel petHotel) { | ||
| this.petHotel = petHotel; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Pet> answeredBy(Actor actor) { | ||
| return petHotel.getRegisteredPets(); | ||
| } | ||
|
|
||
| public static Question<List<Pet>> registeredIn(PetHotel petHotel) { | ||
| return new TheRegisteredGuest(petHotel); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.questions; | ||
|
|
||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Question; | ||
| import net.serenitybdd.screenplay.annotations.Subject; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.PetHotel; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| @Subject("the Waiting Pets in the hotel") | ||
| public class TheWaitingGuest implements Question<List<Pet>> { | ||
| private PetHotel petHotel; | ||
|
|
||
| public TheWaitingGuest(PetHotel petHotel) { | ||
| this.petHotel = petHotel; | ||
| } | ||
|
|
||
| @Override | ||
| public List<Pet> answeredBy(Actor actor) { | ||
| return petHotel.getWaitingList(); | ||
| } | ||
|
|
||
| public static Question<List<Pet>> isOnWaitingListIn(PetHotel petHotel) { | ||
| return new TheWaitingGuest(petHotel); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.questions; | ||
|
|
||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Question; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.BookingResponse; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class TheWaitingStatus implements Question<Boolean> { | ||
|
|
||
| private BookingResponse bookingResponse = new BookingResponse(); | ||
| private Pet pet; | ||
|
|
||
| public TheWaitingStatus(Pet pet) { | ||
| this.pet = pet; | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean answeredBy(Actor actor) { | ||
| return bookingResponse.isConfirmed(); | ||
| } | ||
|
|
||
| public static TheWaitingStatusBuilder of(Pet pet) { | ||
| return new TheWaitingStatusBuilder(pet); | ||
| } | ||
|
|
||
| public static class TheWaitingStatusBuilder { | ||
| private Pet pet; | ||
|
|
||
| public TheWaitingStatusBuilder(Pet pet) { | ||
| this.pet = pet; | ||
| } | ||
|
|
||
| public Question<Boolean> isConfirmed() { | ||
| return new TheWaitingStatus(pet); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.tasks; | ||
|
|
||
|
|
||
| import net.serenitybdd.core.steps.Instrumented; | ||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Performable; | ||
| import net.serenitybdd.screenplay.Task; | ||
| import net.thucydides.core.annotations.Step; | ||
| import org.jruby.ir.instructions.Instr; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.BookingResponse; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.PetHotel; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class CheckIn implements Performable { | ||
| private final Pet pet; | ||
| private final PetHotel petHotel; | ||
|
|
||
| public CheckIn(Pet pet, PetHotel petHotel) { | ||
| this.pet = pet; | ||
| this.petHotel = petHotel; | ||
| } | ||
|
|
||
| @Step("{0} checks-in #pet into #petHotel") | ||
| @Override | ||
| public <T extends Actor> void performAs(T actor) { | ||
| BookingResponse bookingResponse = petHotel.checkIn(pet); | ||
|
Contributor
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. Here, you never use the 'bookingResponse' variable, so you never actually check the response coming back from the hotel. |
||
| } | ||
|
|
||
| public static CheckInBuilder aPet(Pet pet) { | ||
| return new CheckInBuilder(pet); | ||
| } | ||
|
|
||
| public static class CheckInBuilder { | ||
| private Pet pet; | ||
|
|
||
| public CheckInBuilder(Pet pet) { | ||
| this.pet = pet; | ||
| } | ||
|
|
||
| public Performable in(PetHotel petHotel) { | ||
| //return new CheckIn(pet, petHotel); | ||
| return Instrumented.instanceOf(CheckIn.class).withProperties(pet, petHotel); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| package serenitylabs.tutorials.vetclinic.collections.katas.tasks; | ||
|
|
||
| import net.serenitybdd.core.steps.Instrumented; | ||
| import net.serenitybdd.screenplay.Actor; | ||
| import net.serenitybdd.screenplay.Performable; | ||
| import net.serenitybdd.screenplay.Task; | ||
| import net.thucydides.core.annotations.Step; | ||
| import serenitylabs.tutorials.vetclinic.Pet; | ||
| import serenitylabs.tutorials.vetclinic.collections.katas.PetHotel; | ||
|
|
||
| /** | ||
| * Created by vdheer on 9/20/2016. | ||
| */ | ||
| public class CheckOut implements Performable { | ||
| private final Pet pet; | ||
| private final PetHotel petHotel; | ||
|
|
||
| public CheckOut(Pet pet, PetHotel petHotel) { | ||
| this.pet = pet; | ||
| this.petHotel = petHotel; | ||
| } | ||
|
|
||
| @Step("{0} checks-in #pet into #petHotel") | ||
| @Override | ||
| public <T extends Actor> void performAs(T actor) { | ||
| petHotel.checkOut(pet); | ||
| } | ||
|
|
||
| public static CheckOutBuilder aPet(Pet pet) { | ||
| return new CheckOutBuilder(pet); | ||
| } | ||
|
|
||
| public static class CheckOutBuilder { | ||
| private Object pet; | ||
|
|
||
| public CheckOutBuilder(Object pet) { | ||
| this.pet = pet; | ||
| } | ||
|
|
||
| public Performable in(PetHotel petHotel) { | ||
| return Instrumented.instanceOf(CheckOut.class).withProperties(pet, petHotel); | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| Your test code goes here. |
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.
This will return a positive booking response in both cases, so there is no way for the customer to know if the pet was successfully booked or not.