-
Notifications
You must be signed in to change notification settings - Fork 195
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/practice #48
Open
kiran1552
wants to merge
8
commits into
serenity-dojo:kata/collections/start
Choose a base branch
from
kiran1552:kata/collections/practice
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
8 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 2a4dec4
Merge pull request #1 from serenity-dojo/kata/collections/start
kiran1552 ebf5486
Kata/Collections/practice
358db26
Kata/Collections/practice completed all test cases
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
21 changes: 21 additions & 0 deletions
21
src/main/java/serenitylabs/tutorials/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,21 @@ | ||
package serenitylabs.tutorials.vetclinic.collections.katas; | ||
|
||
/** | ||
* Created by kimahale on 9/20/2016. | ||
*/ | ||
public class BookingResponse { | ||
|
||
private final boolean confirmedStatus; | ||
|
||
public BookingResponse(boolean confirmedStatus) { | ||
this.confirmedStatus = confirmedStatus; | ||
} | ||
|
||
public boolean isConfirmed() { | ||
return confirmedStatus; | ||
} | ||
|
||
public boolean isOnWaitingList() { | ||
return !confirmedStatus; | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.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,41 @@ | ||
package serenitylabs.tutorials.vetclinic.collections.katas; | ||
|
||
import serenitylabs.tutorials.vetclinic.Pet; | ||
|
||
import java.util.*; | ||
|
||
/** | ||
* Created by kimahale on 9/20/2016. | ||
*/ | ||
public class PetHotel { | ||
|
||
private Collection<Pet> pets= new TreeSet<>(Comparator.comparing(Pet::getName)); | ||
public static int DEFAULT_MAXIMUM_CAPACITY = 20; | ||
private Queue<Pet> waitingList = new LinkedList<>(); | ||
|
||
public List<Pet> getPets() { | ||
return new ArrayList(pets); | ||
} | ||
|
||
public BookingResponse checkIn(Pet pet) { | ||
boolean confirmStatus= false; | ||
if (pets.size() <DEFAULT_MAXIMUM_CAPACITY) { | ||
pets.add(pet); | ||
confirmStatus=true; | ||
} | ||
else | ||
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. Always put curly brackets around statements. |
||
waitingList.add(pet); | ||
return new BookingResponse(confirmStatus); | ||
} | ||
|
||
public List<Pet> getWaitingList() { | ||
return new ArrayList<>(waitingList); | ||
} | ||
|
||
public void checkOut(Pet pet) { | ||
pets.remove(pet); | ||
if (!waitingList.isEmpty()) { | ||
checkIn(waitingList.poll()); | ||
} | ||
} | ||
} |
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. |
124 changes: 124 additions & 0 deletions
124
...java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotel.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 |
---|---|---|
@@ -1,54 +1,178 @@ | ||
package serenitylabs.tutorials.vetclinic.collections.katas; | ||
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. Good clean tests. |
||
|
||
import org.junit.Test; | ||
import serenitylabs.tutorials.vetclinic.Pet; | ||
|
||
import static org.hamcrest.Matchers.*; | ||
import static org.junit.Assert.assertThat; | ||
|
||
public class WhenBookingPetsIntoAPetHotel { | ||
|
||
|
||
@Test | ||
public void the_hotel_should_initially_have_no_pets_booked() { | ||
// When | ||
PetHotel petHotel = new PetHotel(); | ||
// Then | ||
assertThat(petHotel.getPets(), hasSize(0)); | ||
} | ||
|
||
@Test | ||
public void should_be_able_to_check_a_pet_into_the_hotel() throws Exception { | ||
// Given | ||
PetHotel petHotel=new PetHotel(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
//When | ||
petHotel.checkIn(fido); | ||
// Then | ||
assertThat(petHotel.getPets(), hasItems(fido)); | ||
} | ||
|
||
@Test | ||
public void should_be_able_to_check_in_several_pets() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=new PetHotel(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
Pet felix= Pet.cat().named("Felix"); | ||
|
||
//When | ||
petHotel.checkIn(fido); | ||
petHotel.checkIn(felix); | ||
// Then | ||
assertThat(petHotel.getPets(), hasItems(fido, felix)); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void should_not_be_able_to_check_in_the_same_pet_twice() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=new PetHotel(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
Pet felix= Pet.cat().named("Felix"); | ||
|
||
petHotel.checkIn(fido); | ||
petHotel.checkIn(felix); | ||
|
||
// When | ||
petHotel.checkIn(fido); | ||
// Then | ||
assertThat(petHotel.getPets(), containsInAnyOrder(fido, felix)); | ||
|
||
} | ||
|
||
@Test | ||
public void should_be_able_to_retrieve_checked_in_pets_in_alphabetical_order() throws Exception { | ||
// Given | ||
PetHotel petHotel=new PetHotel(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
Pet felix= Pet.cat().named("Felix"); | ||
Pet tommy= Pet.dog().named("Tommy"); | ||
|
||
|
||
// When | ||
petHotel.checkIn(fido); | ||
petHotel.checkIn(felix); | ||
petHotel.checkIn(tommy); | ||
// Then | ||
assertThat(petHotel.getPets(), contains(felix, fido, tommy)); | ||
|
||
|
||
} | ||
|
||
@Test | ||
public void should_be_able_to_obtain_a_booking_confirmation_when_we_check_in_a_pet() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=new PetHotel(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
// When | ||
BookingResponse bookingResponse= petHotel.checkIn(fido); | ||
// Then | ||
assertThat(bookingResponse.isConfirmed(), equalTo(true)); | ||
} | ||
|
||
@Test | ||
public void should_not_be_able_to_check_in_pets_beyond_hotel_capacity() throws Exception { | ||
// Given | ||
PetHotel petHotel=APetHotel.with(20).petsCheckIn(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
|
||
// When | ||
petHotel.checkIn(fido); | ||
|
||
// Then | ||
assertThat(petHotel.getPets(), hasSize(20)); | ||
|
||
} | ||
|
||
@Test | ||
public void should_notify_owner_that_the_hotel_is_full() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=APetHotel.with(20).petsCheckIn(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
// When | ||
BookingResponse bookingResponse= petHotel.checkIn(fido); | ||
// Then | ||
assertThat(bookingResponse.isConfirmed(), is(false)); | ||
assertThat(bookingResponse.isOnWaitingList(), is(true)); | ||
|
||
|
||
} | ||
|
||
|
||
@Test | ||
public void should_place_pets_on_a_waiting_list_when_the_hotel_is_full() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=APetHotel.with(20).petsCheckIn(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
// When | ||
petHotel.checkIn(fido); | ||
// Then | ||
assertThat(petHotel.getWaitingList(), hasItem(fido)); | ||
|
||
} | ||
|
||
@Test | ||
public void pets_on_the_waiting_list_should_be_added_to_the_hotel_when_a_place_is_freed() throws Exception { | ||
|
||
// Given | ||
PetHotel petHotel=APetHotel.with(19).petsCheckIn(); | ||
Pet fido= Pet.dog().named("Fido"); | ||
Pet felix= Pet.cat().named("Felix"); | ||
// Pet roger= Pet.rabbit().named("Roger"); | ||
|
||
petHotel.checkIn(fido); | ||
petHotel.checkIn(felix); | ||
// petHotel.checkIn(roger); | ||
petHotel.checkOut(fido); | ||
// Then | ||
assertThat(petHotel.getPets(), hasItem(felix)); | ||
|
||
} | ||
|
||
|
||
@Test | ||
public void pets_on_the_waiting_list_should_be_admitted_on_a_first_come_first_served_basis() throws Exception { | ||
|
||
PetHotel hotel = APetHotel.with(19).petsCheckIn(); | ||
Pet felix = Pet.cat().named("FELIX"); | ||
Pet fido = Pet.dog().named("FIDO"); | ||
Pet roger = Pet.rabbit().named("ROGER"); | ||
|
||
hotel.checkIn(felix); | ||
hotel.checkIn(fido); | ||
hotel.checkIn(roger); | ||
|
||
//WHEN | ||
hotel.checkOut(felix); | ||
|
||
//Then | ||
assertThat(hotel.getPets(), hasItem(fido)); | ||
} | ||
|
||
} |
4 changes: 0 additions & 4 deletions
4
src/test/java/serenitylabs/tutorials/vetclinic/package-info.java
This file was deleted.
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.
You could refactor this nicely using the Strategy pattern.