diff --git a/.gitignore b/.gitignore index 12d2e159..a823f531 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,7 @@ # Created by .ignore support plugin (hsz.mobi) ### Maven template target/ +test-output/ pom.xml.tag pom.xml.releaseBackup pom.xml.versionsBackup diff --git a/pom.xml b/pom.xml index 8e537898..76fffd0a 100644 --- a/pom.xml +++ b/pom.xml @@ -1,56 +1,72 @@ - - 4.0.0 + + 4.0.0 - com.wakaleo.tutorials - vet-clinic - 1.0.0-SNAPSHOT - jar + com.wakaleo.tutorials + vet-clinic + 1.0.0-SNAPSHOT + jar - tutorials - http://maven.apache.org + tutorials + http://maven.apache.org - - UTF-8 - + + UTF-8 + - - - junit - junit - 4.12 - test - - - org.assertj - assertj-core - 3.1.0 - test - - - - - - org.apache.maven.plugins - maven-compiler-plugin - 3.2 - - 1.8 - 1.8 - - - - org.apache.maven.plugins - maven-surefire-plugin - 2.18.1 - - - **/When*.java - **/*Test.java - **/*TestSuite.java - - - - - + + + junit + junit + 4.12 + test + + + org.testng + testng + 7.8.0 + + + org.assertj + assertj-core + 3.1.0 + test + + + com.google.guava + guava + 23.0 + + + org.hamcrest + hamcrest-all + 1.3 + + + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.2 + + 1.8 + 1.8 + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.18.1 + + + **/When*.java + **/*Test.java + **/*TestSuite.java + + + + + diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentBookerBuilderEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentBookerBuilderEntity.java new file mode 100644 index 00000000..e8a2f163 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentBookerBuilderEntity.java @@ -0,0 +1,28 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDateTime; + +public class AppointmentBookerBuilderEntity { + + private final String petName; + private String owner; + private String reason; + + public AppointmentBookerBuilderEntity(String petName) { + this.petName = petName; + } + + public AppointmentBookerBuilderEntity ownedBy(String owner) { + this.owner = owner; + return this; + } + + public AppointmentBookerBuilderEntity because(String reason) { + this.reason = reason; + return this; + } + + public AppointmentEntity at(LocalDateTime appointmentTime) { + return new AppointmentEntity(petName, owner, appointmentTime, reason); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java new file mode 100644 index 00000000..baedf58c --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java @@ -0,0 +1,55 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDateTime; +import java.util.Optional; + +public class AppointmentEntity { + + private final String petName; + private final String owner; + private final LocalDateTime appointmentTime; + private final Optional reason; + + public AppointmentEntity(String petName, String owner, LocalDateTime appointmentTime,String reason) { + this.petName = petName; + this.owner = owner; + this.appointmentTime = appointmentTime; + this.reason = Optional.ofNullable(reason); + } + + public AppointmentEntity(String petName, String owner, LocalDateTime appointmentTime) { + this(petName, owner, appointmentTime, null); + } + + public String getPetName() { + return petName; + } + + public String getOwner() { + return owner; + } + + public LocalDateTime getAppointmentTime() { + return appointmentTime; + } + + public Optional getReason() { + return reason; + } + + public boolean isBefore(LocalDateTime isBeforeLocatDt) + { + return true; + } + + public boolean isAfter(LocalDateTime isAfterLocatDt) + { + return true; + } + + + public static AppointmentBookerBuilderEntity forPetCalled(String petName) { + return new AppointmentBookerBuilderEntity(petName); + + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java new file mode 100644 index 00000000..67a7197b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java @@ -0,0 +1,57 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; + +public class DogBreederEntityBuilder implements WithIBreedable,IwithColourable { + + private String name; + private String breed; + private String favouriteColour; + private String optFldFavouriteFood; + private String optFldFavouriteToy; + + public DogBreederEntityBuilder(String name) { + this.name=name; + System.out.println("DogBreederEntityBuilder - builders object initialized."); + } + + public DogBreederEntityBuilder ofDogBreed(String breed) { + this.breed=breed; + return this; + } + + public DogEntityImmutableType bornOn(LocalDate localDate) { + return new DogEntityImmutableType(name, breed, localDate,favouriteColour,optFldFavouriteFood,optFldFavouriteToy); + } + + + public DogEntity dgEntityBornOn(LocalDate localDate) { + return new DogEntity(name, breed, localDate,favouriteColour,optFldFavouriteFood,optFldFavouriteToy); + } + + @Override + public IwithColourable ofBreed(String breed) { + return new DogBreederEntityBuilder(breed); + } + + public DogBreederEntityBuilder ofDogColour(String strFavColour) { + this.favouriteColour=strFavColour; + return this; + } + + + public DogEntityImmutableType ofColour(String favColour) { + return new DogEntityImmutableType(favColour); + } + + public DogBreederEntityBuilder setOptFldFavouriteFood(String strOptFavFood) { + this.optFldFavouriteFood=strOptFavFood; + return this; + } + + public DogBreederEntityBuilder setOptFldFavouriteToy(String strOptFavToy) { + this.optFldFavouriteToy=strOptFavToy; + return this; + } + + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java new file mode 100644 index 00000000..e64dc1d1 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java @@ -0,0 +1,75 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; + +/** + * Mutable DogEntity class as its fields values state can be modifyed with the + * help of setter methods. + * + */ + +public class DogEntity { + + private String dogName; + private String dogBreed; + private LocalDate birthDateTime; + private String favouriteColour; + private String optFldFavouriteFood; + private String optFldFavouriteToy; + + DogEntity(String dogName, String dogBreed, LocalDate birthDateTime,String favColour,String strFavFood,String strFavToy) { + this.dogName = dogName; + this.dogBreed = dogBreed; + this.birthDateTime = birthDateTime; + this.favouriteColour=favColour; + this.optFldFavouriteFood=strFavFood; + this.optFldFavouriteToy=strFavToy; + } + + public DogEntity(){ + System.out.println("Default constructor of Mutable DogEntity class called."); + } + + public String getDogName() { + return dogName; + } + public String getDogBreed() { + return dogBreed; + } + public LocalDate getBirthDateTime() { + return birthDateTime; + } + + public String getFavouriteColour() { + return favouriteColour; + } + + public String getOptFldFavouriteFood() { + return optFldFavouriteFood; + } + + public String getOptFldFavouriteToy() { + return optFldFavouriteToy; + } + + public static WithIBreedable called(String name) + { + return new DogBreederEntityBuilder(name); + } + + public DogEntity dgEntityBornOn(LocalDate localDate) { + return new DogEntity(dogName, dogBreed, localDate,favouriteColour,optFldFavouriteFood,optFldFavouriteToy); + } + + public void setDogName(String strDgName) { + this.dogName=strDgName; + } + + public void setDogBreed(String strDgBreed) { + this.dogBreed=strDgBreed; + } + + public void setBirthDateTime(LocalDate locDateTimeObj) { + this.birthDateTime=locDateTimeObj; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java new file mode 100644 index 00000000..614b9167 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java @@ -0,0 +1,145 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; +import java.util.ArrayList; +import java.util.List; +import com.google.common.collect.ImmutableList; + +/** + * Immutable DogEntityImmutableType class as its fields values state can not be + * modified. + * + */ + +public class DogEntityImmutableType { + + //marking fields with final soo that its state can not be change. + private String dogName; + private String dogBreed; + private LocalDate dateOfBirth; + private String favouriteColor; + private String optFldFavouriteFood; + private String optFldFavouriteToy; + private List strListOfColours; + + public static DogEntityImmutableType getImmutableInstance() { + return new DogEntityImmutableType(); + } + + public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime) { + this(dogName, dogBreed, birthDateTime,null,null,null); + System.out.println("Parameterized constructor of Immutable DogEntityImmutableType class called."); + } + + public DogEntityImmutableType(String dogName, String dogBreed,List localLstColorStr) { + this.dogName=dogName; + this.dogBreed=dogBreed; + this.strListOfColours=localLstColorStr; + System.out.println("Parameterized constructor of Immutable DogEntityImmutableType class called."); + } + + public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime, String favColour,String favFood,String favToys) { + this.dogName = dogName; + this.dogBreed = dogBreed; + this.dateOfBirth = birthDateTime; + this.favouriteColor = favColour; + this.optFldFavouriteFood=favFood; + this.optFldFavouriteToy=favToys; + System.out.println("Parameterized constructor with new field added."); + } + + public DogEntityImmutableType() { + + } + + public DogEntityImmutableType(String name) { + this.dogName=name; + } + + public String getDogName() { + return dogName; + } + public String getDogBreed() { + return dogBreed; + } + public LocalDate getBirthDate() { + return dateOfBirth; + } + + public String getFavouriteColor() { + return favouriteColor; + } + + public String getOptFldFavouriteFood() { + return optFldFavouriteFood; + } + + public String getOptFldFavouriteToy() { + return optFldFavouriteToy; + } + + + public DogEntityImmutableType called(String name) { + this.dogName=name; + System.out.println("\nThis methode call is mandatory. called()"); + return this; + } + + public DogEntityImmutableType ofBreed(String breed) { + System.out.println("\nThis methode call is mandatory. ofBreed()"); + this.dogBreed=breed; + return this; + } + + public DogEntityImmutableType ofColour(String favColour) { + this.favouriteColor=favColour; + System.out.println("\nThis methode called. ofColour()"); + return this; + } + + + public DogEntityImmutableType bornOn(LocalDate theFourthOfJuly) { + System.out.println("\nThis methode call is mandatory. bornOn()"); + return new DogEntityImmutableType(dogName, dogBreed, theFourthOfJuly,favouriteColor,optFldFavouriteFood,optFldFavouriteToy); + } + + + public DogEntityImmutableType setOptFldFavouriteFood(String optFldFavouriteFood) { + this.optFldFavouriteFood = optFldFavouriteFood; + System.out.println("\nThis methode call is optional setOptFldFavouriteFood() "); + return this; + } + + public DogEntityImmutableType setOptFldFavouriteToy(String optFldFavouriteToy) { + this.optFldFavouriteToy = optFldFavouriteToy; + System.out.println("\nThis methode call is optional setOptFldFavouriteToy() "); + return this; + } + + public static DogEntityImmutableType aLargeDog() { + return getImmutableInstance().ofBreed("Labrador"); + } + + public static DogEntityImmutableType aSmallDog() { + return getImmutableInstance().ofBreed("Lasa"); + } + + public static DogEntityImmutableType aGuardDog() { + return getImmutableInstance().ofBreed("German Shepherd"); + } + + public DogEntityImmutableType andOfColour(String... favColour) { + System.out.println("\nThis methode called. andOfColour()"); + return new DogEntityImmutableType(dogName, dogBreed, ImmutableList.copyOf(favColour)); + } + + @Override + public String toString() { + return ""+dogName+" the "+favouriteColor+" "+dogBreed+""; + } + + public List getStrListOfColours() { + return new ArrayList(strListOfColours); + } + + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java new file mode 100644 index 00000000..c0ff2088 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java @@ -0,0 +1,8 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public interface IwithColourable { + + DogEntityImmutableType ofColour(String favColour); + + DogBreederEntityBuilder ofDogColour(String strFavColour); +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/TotalConsultationPrice.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/TotalConsultationPrice.java new file mode 100644 index 00000000..e99b277c --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/TotalConsultationPrice.java @@ -0,0 +1,13 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public class TotalConsultationPrice { + + public static TotalConsultationPrice includingTax() { + return new TotalConsultationPrice(); + } + + public int forANetPriceOf(double netPrice) { + return (int) (netPrice * 1.20); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java new file mode 100644 index 00000000..d14908ed --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java @@ -0,0 +1,9 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public interface WithIBreedable { + + IwithColourable ofBreed(String breed); + + IwithColourable ofDogBreed(String breed); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/package-info.java b/src/main/java/serenitylabs/tutorials/vetclinic/package-info.java deleted file mode 100644 index cf2e5f53..00000000 --- a/src/main/java/serenitylabs/tutorials/vetclinic/package-info.java +++ /dev/null @@ -1,4 +0,0 @@ -/** - * Our fantastic Vet Clinic app starts here - **/ - package serenitylabs.tutorials.vetclinic; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/README.md b/src/test/java/README.md similarity index 100% rename from src/test/java/serenitylabs/tutorials/vetclinic/README.md rename to src/test/java/README.md diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java new file mode 100644 index 00000000..013ea6d7 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java @@ -0,0 +1,287 @@ +package serenitylabs.tutorials.vetclinic.domain; +import static org.hamcrest.CoreMatchers.containsString; +import static org.hamcrest.CoreMatchers.endsWith; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.CoreMatchers.not; +import static org.hamcrest.CoreMatchers.startsWith; +import static org.hamcrest.Matchers.contains; +import static org.junit.Assert.assertThat; +import java.time.LocalDate; +import org.testng.Assert; +import org.testng.annotations.Test; + +/** + * Limitations of Default constructor and over come through Builder pattern. + * + */ + +public class NewDogCreationTests { + + private static final LocalDate THE_FOURTH_OF_JULY=LocalDate.of(2024,07,04); + + + /* + * This TestNg test is representing test validation with builder pattern + * implementation. + * + * see : Exercises-1 + * Step 1 - Creating a Dog with a name. + * Step 2 - Adding a date of birth. + * Step 3 - Adding a breed. + * + */ + @Test + public void a_new_dog_should_have_a_name() + { + DogEntityImmutableType dogObj=DogEntityImmutableType.getImmutableInstance() + .called("Fido") + .ofBreed("Labrador") + .bornOn(THE_FOURTH_OF_JULY); + + Assert.assertEquals("Fido",dogObj.getDogName()); + Assert.assertEquals("Labrador",dogObj.getDogBreed()); + Assert.assertEquals(THE_FOURTH_OF_JULY,dogObj.getBirthDate()); + System.out.println("\nThis is 4th Test methode."); + } + + + + /* + * This TestNg test is representing test validation for colour should be a + * mandatory field, and optional fields for Favourite Food with builder pattern + * implementation. + * + * see : Exercises-2 Step 5 + * + */ + @Test + public void a_dog_can_have_an_optional_favourite_food() { + DogEntity dogObj = DogEntity.called("Fido") // mandatory + .ofDogBreed("Labrador") // mandatory + .ofDogColour("black") //ofColour is mandatory. + .setOptFldFavouriteFood("Pizza") //setOptFldFavouriteFood is optional + .dgEntityBornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColour()); + Assert.assertEquals("Pizza", dogObj.getOptFldFavouriteFood()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDateTime()); + System.out.println("\nThis is 6th Test methode."); + } + + + + /* + * This TestNg test is representing test validation for colour should be a + * mandatory field, and optional fields for Favourite Toy with builder pattern + * implementation. + * + * see : Exercises-2 Step 5 + * + */ + @Test + public void a_dog_can_have_an_optional_favourite_toy() { + DogEntity dogObj=DogEntity.called("Fido") // mandatory + .ofDogBreed("Labrador") // mandatory + .ofDogColour("black") //ofColour is mandatory. + .setOptFldFavouriteToy("PingPong") // setOptFldFavouriteToy optional + .dgEntityBornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColour()); + Assert.assertEquals("PingPong", dogObj.getOptFldFavouriteToy()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDateTime()); + System.out.println("\nThis is 7th Test methode."); + } + + + + /* + * This TestNg test is implementation for external entity builder class w.r.t + * builder prototype method for aLargeDog + * + * see : Exercises-3 + * + */ + @Test + public void a_aLargeDog_can_have_an_optional_favourite_toy() { + DogEntityImmutableType dogObj=DogEntityImmutableType.aLargeDog() + .called("Fido") // mandatory + .ofColour("black") //ofColour is mandatory. + .setOptFldFavouriteToy("PingPong") // setOptFldFavouriteToy optional + .bornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColor()); + Assert.assertEquals("PingPong", dogObj.getOptFldFavouriteToy()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + System.out.println("\nThis is 8th Test methode with prototype method aLargeDog()."); + } + + + /* + * This TestNg test is implementation for external entity builder class w.r.t + * builder prototype method for aSmallDog + * + * see : Exercises-3 + * + */ + @Test + public void a_aSmallDog_can_have_an_optional_favourite_food() { + DogEntityImmutableType dogObj = DogEntityImmutableType.aSmallDog() + .called("Spot") // mandatory + .ofColour("white") // ofColour is mandatory. + .setOptFldFavouriteFood("Pizza") // setOptFldFavouriteFood is optional + .bornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Spot", dogObj.getDogName()); + Assert.assertEquals("Lasa", dogObj.getDogBreed()); + Assert.assertEquals("white", dogObj.getFavouriteColor()); + Assert.assertEquals("Pizza", dogObj.getOptFldFavouriteFood()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + System.out.println("\nThis is 9th Test methode with prototype method aSmallDog()."); + } + + + + /* + * This TestNg test is implementation for external entity builder class w.r.t + * builder prototype method for aGuardDog + * + * see : Exercises-3 + * + */ + @Test + public void a_aGuardDog_can_have_an_optional_favourite_food() { + DogEntityImmutableType dogObj = DogEntityImmutableType.aGuardDog() + .called("Jimmy") // mandatory + .ofColour("browny-blackish") // ofColour is mandatory. + .setOptFldFavouriteFood("hot dog") // setOptFldFavouriteFood is optional + .bornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Jimmy", dogObj.getDogName()); + Assert.assertEquals("German Shepherd", dogObj.getDogBreed()); + Assert.assertEquals("browny-blackish", dogObj.getFavouriteColor()); + Assert.assertEquals("hot dog", dogObj.getOptFldFavouriteFood()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + System.out.println("\nThis is 10th Test methode with prototype method aGuardDog()."); + } + + + + /* + * This TestNg test is representing test validation for mandatory & optional + * field/data member implementation with builder pattern implementation. + * + * see : Exercises-2 Step 4 - Colour is an optional field.Use an interface + * called WithIBreedable to allow the builder to cater for the mandatory fields + * (name, breed and date of birth) and the optional one (colour). + * + * This will be deleted once Exercises-2 'Step 5' will be implemented. + * + */ + @Test + public void a_dog_can_have_an_optional_colour() { + DogEntity dogObj = DogEntity.called("Fido") // mandatory + .ofDogBreed("Labrador") // mandatory + .ofDogColour("black") //ofColour is optional. + .dgEntityBornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColour()); + System.out.println("\nThis is 5th Test methode."); + } + + + /* + * This TestNg test is representing test validation for 'Vet Clinic Tutorial 2 - + * Hamcrest Matchers' modules Exercise - 'Step 4 - Hamcrest collection matchers' + * implementation + * + */ + @Test + public void a_dog_can_have_several_colours() { + System.out.println("\nThis is 'Step 4 - Hamcrest collection matchers' Test methode-12th implementation"); + DogEntityImmutableType dogObj=DogEntityImmutableType.getImmutableInstance() + .called("Fido") + .ofBreed("labrador") + .andOfColour("Red","black","green","blue");//ofColour is mandatory. + + assertThat(dogObj.getStrListOfColours(),contains("Red","black","green","blue")); + assertThat(dogObj.getStrListOfColours(),hasItem("green")); + assertThat(dogObj.getStrListOfColours(),not(hasItem("yellow"))); + } + + + /* + * This TestNg test is representing test validation for 'Vet Clinic Tutorial 2 - + * Hamcrest Matchers' modules Exercise - 'Step 3 - Hamcrest String matchers' + * implementation + * + */ + @Test + public void a_new_dog_should_be_printed_in_a_readable_form() { + System.out.println("\nThis is 'Step 3 - Hamcrest String matchers' Test methode-11th implementation"); + DogEntityImmutableType dogObj=DogEntityImmutableType.getImmutableInstance() + .called("Fido") + .ofBreed("labrador") + .ofColour("black");//ofColour is mandatory. + + assertThat(dogObj.toString(),is(equalTo("Fido the black labrador"))); + assertThat(dogObj.toString(),startsWith("Fido")); + assertThat(dogObj.toString(),endsWith("labrador")); + assertThat(dogObj.toString(),containsString("black")); + } + + + + @Test + public void isNameOfDogExits() + { + DogEntity dogObj=new DogEntity(); + dogObj.setDogName("Touchi"); + dogObj.setDogBreed("Lasa"); + LocalDate locDateTimeObj=LocalDate.now(); + dogObj.setBirthDateTime(locDateTimeObj); + + Assert.assertEquals("Touchi",dogObj.getDogName()); + Assert.assertEquals("Lasa",dogObj.getDogBreed()); + Assert.assertEquals(locDateTimeObj,dogObj.getBirthDateTime()); + System.out.println("\nThis is 1st Test methode."); + } + + + @Test + public void isDogsArrtibuteExits() + { + LocalDate locDateTimeObj=LocalDate.now(); + DogEntityImmutableType dogObj=new DogEntityImmutableType("Touchi","Lasa",locDateTimeObj); + + Assert.assertEquals("Touchi",dogObj.getDogName()); + Assert.assertEquals("Lasa",dogObj.getDogBreed()); + Assert.assertEquals(locDateTimeObj,dogObj.getBirthDate()); + System.out.println("\nThis is 2nd Test methode."); + } + + + @Test + public void isOptionalFavouriteFoodFieldExists() + { + LocalDate locDateTimeObj=LocalDate.now(); + DogEntityImmutableType dogObj=new DogEntityImmutableType("Touchi","Lasa",locDateTimeObj,"Rasgulla",null,null); + + Assert.assertEquals("Touchi",dogObj.getDogName()); + Assert.assertEquals("Rasgulla",dogObj.getFavouriteColor()); + System.out.println("\nThis is 3rd Test methode."); + } + + + + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenCalculatingTotalPricesTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenCalculatingTotalPricesTests.java new file mode 100644 index 00000000..4d8a3226 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenCalculatingTotalPricesTests.java @@ -0,0 +1,30 @@ +package serenitylabs.tutorials.vetclinic.domain; +import static org.hamcrest.Matchers.greaterThan; +import static org.junit.Assert.assertThat; +import org.testng.annotations.Test; + +public class WhenCalculatingTotalPricesTests { + + /* + * This TestNg test is representing test validation for 'Vet Clinic Tutorial 2 - + * Hamcrest Matchers' modules Exercise - 'Step 1 - Replace JUnit asserts with + * Hamcrest asserts' and 'Step 2 - Hamcrest comparison assertions' + * implementation + * + */ + @Test + public void total_consultation_price_should_include_20_percent_tax() { + System.out.println("\nThis is 'Step 1 & Step 2 - simple Hamcrest asserts' Test methode-13th implementation"); + // Arrange - GIVEN + int netPrice = 250; + + // Act - WHEN + int totalPrice = TotalConsultationPrice.includingTax().forANetPriceOf(netPrice); + System.out.println("\nCalculated Total Net price : " + totalPrice); + + // Assert - THEN + assertThat(totalPrice,greaterThan(150)); + } + + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java new file mode 100644 index 00000000..ca755cd6 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java @@ -0,0 +1,50 @@ +package serenitylabs.tutorials.vetclinic.domain; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.CoreMatchers.is; +import static org.junit.Assert.assertThat; +import java.time.LocalDateTime; +import org.testng.annotations.Test; + +public class WhenWeBookAnAppointmentTests { + + private static final LocalDateTime TODAY_AT_2_PM = LocalDateTime.now().withHour(2).withMinute(0); + + /* + * This TestNg test is representing test validation for 'Vet Clinic Tutorial 2 - + * Hamcrest Matchers' modules Exercise - 'Step 5 - Updating the + * WhenWeBookAnAppointmentTests test' implementation + * + */ + @Test + public void an_appointment_has_a_patient_name_an_owner_and_a_date() { + AppointmentEntity appointObj = AppointmentEntity.forPetCalled("Fido") + .ownedBy("Fred") + .at(TODAY_AT_2_PM); + + assertThat(appointObj.getPetName(),is(equalTo("Fido"))); + assertThat(appointObj.getOwner(),is(equalTo("Fred"))); + assertThat(appointObj.getAppointmentTime(),is(equalTo(TODAY_AT_2_PM))); + System.out.println("Execution of - 'Step 5 - Updating the WhenWeBookAnAppointment tests' completed."); + } + + + /* + * This TestNg test is representing test validation for 'Vet Clinic Tutorial 2 - + * Hamcrest Matchers' modules Exercise - 'Step 6 - comparing appointments' + * implementation + * + */ + @Test + public void an_appointment_can_have_an_optional_reason() { + AppointmentEntity appointObj = AppointmentEntity.forPetCalled("Fido") + .ownedBy("Fred") + .because("He is sick") + .at(TODAY_AT_2_PM); + + assertThat(appointObj.getReason().isPresent(),is(true)); + assertThat(appointObj.getReason().get(),is(equalTo("He is sick"))); + System.out.println("Execution of - 'Step 6 - comparing appointments' tests completed."); + } + + +} \ No newline at end of file