From 3352c583345fd69ccbc7533d863618cbf59afd6d Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 1 Feb 2024 03:25:27 +0530 Subject: [PATCH 01/30] builder pattern implementation with TestNg & Exercises-1 --- .gitignore | 1 + pom.xml | 103 +++++++++--------- .../domain/DogBreederEntityBuilder.java | 23 ++++ .../tutorials/vetclinic/domain/DogEntity.java | 39 +++++++ .../domain/DogEntityImmutableType.java | 49 +++++++++ .../tutorials/vetclinic/package-info.java | 4 - .../tutorials/vetclinic => }/README.md | 0 .../vetclinic/domain/NewDogCreationTests.java | 82 ++++++++++++++ 8 files changed, 246 insertions(+), 55 deletions(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java delete mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/package-info.java rename src/test/java/{serenitylabs/tutorials/vetclinic => }/README.md (100%) create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java 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..adac687d 100644 --- a/pom.xml +++ b/pom.xml @@ -1,56 +1,57 @@ - - 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 - - - - - + + + org.testng + testng + 7.8.0 + 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 + + + + + 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..d7efb9a9 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java @@ -0,0 +1,23 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; + +public class DogBreederEntityBuilder { + + private String name; + private String breed; + + public DogBreederEntityBuilder(String name) { + this.name=name; + System.out.println("DogBreederEntityBuilder - builders object initialized."); + } + + public DogBreederEntityBuilder ofBreed(String breed) { + this.breed=breed; + return this; + } + + public DogEntityImmutableType bornOn(LocalDate localDate) { + return new DogEntityImmutableType(name, breed, localDate); + } + +} 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..3604ef42 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java @@ -0,0 +1,39 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDateTime; + +/** + * 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 LocalDateTime birthDateTime; + + public DogEntity(){ + System.out.println("Default constructor of Mutable DogEntity class called."); + } + + public String getDogName() { + return dogName; + } + public String getDogBreed() { + return dogBreed; + } + public LocalDateTime getBirthDateTime() { + return birthDateTime; + } + public void setDogName(String dogName) { + this.dogName = dogName; + } + public void setDogBreed(String dogBreed) { + this.dogBreed = dogBreed; + } + public void setBirthDateTime(LocalDateTime birthDateTime) { + this.birthDateTime = birthDateTime; + } + +} \ 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..60e5d1cc --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java @@ -0,0 +1,49 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; + +/** + * 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 final String dogName; + private final String dogBreed; + private final LocalDate dateOfBirth; + private final String favouriteFood; + + public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime) { + this(dogName, dogBreed, birthDateTime,null); + System.out.println("Parameterized constructor of Immutable DogEntityImmutableType class called."); + } + + public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime, String favouriteFood) { + this.dogName = dogName; + this.dogBreed = dogBreed; + this.dateOfBirth = birthDateTime; + this.favouriteFood = favouriteFood; + System.out.println("Parameterized constructor with new field added."); + } + + public String getDogName() { + return dogName; + } + public String getDogBreed() { + return dogBreed; + } + public LocalDate getBirthDate() { + return dateOfBirth; + } + + public String getFavouriteFood() { + return favouriteFood; + } + + public static DogBreederEntityBuilder called(String name) { + return new DogBreederEntityBuilder(name); + } + +} \ 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..13666ff4 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java @@ -0,0 +1,82 @@ +package serenitylabs.tutorials.vetclinic.domain; +import java.time.LocalDate; +import java.time.LocalDateTime; +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.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."); + } + + + @Test + public void isNameOfDogExits() + { + DogEntity dogObj=new DogEntity(); + dogObj.setDogName("Touchi"); + dogObj.setDogBreed("Lasa"); + LocalDateTime locDateTimeObj=LocalDateTime.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"); + + Assert.assertEquals("Touchi",dogObj.getDogName()); + Assert.assertEquals("Rasgulla",dogObj.getFavouriteFood()); + System.out.println("\nThis is 3rd Test methode."); + } + + +} \ No newline at end of file From 17cd76b92b98e15dae3aced736f8dd5579d49212 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Sun, 4 Feb 2024 03:08:18 +0530 Subject: [PATCH 02/30] adding solutions for Mandatory,Optional fields Excercise-1 , Excercise-2 completed --- .../domain/DogBreederEntityBuilder.java | 5 +- .../domain/DogEntityImmutableType.java | 74 ++++++++++++--- .../vetclinic/domain/IwithColourable.java | 7 ++ .../vetclinic/domain/WithIBreedable.java | 7 ++ .../vetclinic/domain/NewDogCreationTests.java | 89 ++++++++++++++++++- 5 files changed, 165 insertions(+), 17 deletions(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java index d7efb9a9..6d073912 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java @@ -5,6 +5,9 @@ public class DogBreederEntityBuilder { private String name; private String breed; + private String favouriteColour; + private String optFldFavouriteFood; + private String optFldFavouriteToy; public DogBreederEntityBuilder(String name) { this.name=name; @@ -17,7 +20,7 @@ public DogBreederEntityBuilder ofBreed(String breed) { } public DogEntityImmutableType bornOn(LocalDate localDate) { - return new DogEntityImmutableType(name, breed, localDate); + return new DogEntityImmutableType(name, breed, localDate,favouriteColour,optFldFavouriteFood,optFldFavouriteToy); } } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java index 60e5d1cc..b64c433f 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java @@ -7,27 +7,35 @@ * */ -public class DogEntityImmutableType { +public class DogEntityImmutableType implements WithIBreedable,IwithColourable { //marking fields with final soo that its state can not be change. - private final String dogName; - private final String dogBreed; - private final LocalDate dateOfBirth; - private final String favouriteFood; + private String dogName; + private String dogBreed; + private LocalDate dateOfBirth; + private String favouriteColor; + private String optFldFavouriteFood; + private String optFldFavouriteToy; public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime) { - this(dogName, dogBreed, birthDateTime,null); + this(dogName, dogBreed, birthDateTime,null,null,null); System.out.println("Parameterized constructor of Immutable DogEntityImmutableType class called."); } - public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime, String favouriteFood) { + public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDateTime, String favColour,String favFood,String favToys) { this.dogName = dogName; this.dogBreed = dogBreed; this.dateOfBirth = birthDateTime; - this.favouriteFood = favouriteFood; + this.favouriteColor = favColour; + this.optFldFavouriteFood=favFood; + this.optFldFavouriteToy=favToys; System.out.println("Parameterized constructor with new field added."); } + public DogEntityImmutableType(String name) { + this.dogName=name; + } + public String getDogName() { return dogName; } @@ -38,12 +46,54 @@ public LocalDate getBirthDate() { return dateOfBirth; } - public String getFavouriteFood() { - return favouriteFood; + public String getFavouriteColor() { + return favouriteColor; + } + + public String getOptFldFavouriteFood() { + return optFldFavouriteFood; + } + + public String getOptFldFavouriteToy() { + return optFldFavouriteToy; + } + + public static WithIBreedable called(String name) { + System.out.println("\nThis methode call is mandatory. called()"); + return new DogEntityImmutableType(name); + } + + + 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 static DogBreederEntityBuilder called(String name) { - return new DogBreederEntityBuilder(name); + + 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; + } + } \ 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..57247183 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public interface IwithColourable { + + DogEntityImmutableType ofColour(String favColour); + +} 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..281f4ab6 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public interface WithIBreedable { + + IwithColourable ofBreed(String breed); + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java index 13666ff4..277ad484 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java @@ -27,8 +27,8 @@ public class NewDogCreationTests { @Test public void a_new_dog_should_have_a_name() { - DogEntityImmutableType dogObj=DogEntityImmutableType.called("Fido") - .ofBreed("Labrador") + DogEntityImmutableType dogObj=((DogEntityImmutableType) DogEntityImmutableType.called("Fido") + .ofBreed("Labrador")) .bornOn(THE_FOURTH_OF_JULY); Assert.assertEquals("Fido",dogObj.getDogName()); @@ -38,6 +38,85 @@ public void a_new_dog_should_have_a_name() } + + /* + * 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() { + DogEntityImmutableType dogObj = DogEntityImmutableType.called("Fido") // mandatory + .ofBreed("Labrador") // mandatory + .ofColour("black") //ofColour is mandatory. + .setOptFldFavouriteFood("Pizza") //setOptFldFavouriteFood is optional + .bornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColor()); + Assert.assertEquals("Pizza", dogObj.getOptFldFavouriteFood()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + 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() { + DogEntityImmutableType dogObj=DogEntityImmutableType.called("Fido") // mandatory + .ofBreed("Labrador") // 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 7th Test methode."); + } + + + + /* + * 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() { + DogEntityImmutableType dogObj = DogEntityImmutableType.called("Fido") // mandatory + .ofBreed("Labrador") // mandatory + .ofColour("black") //ofColour is optional. + .bornOn(THE_FOURTH_OF_JULY); // mandatory + + Assert.assertEquals("Fido", dogObj.getDogName()); + Assert.assertEquals("Labrador", dogObj.getDogBreed()); + Assert.assertEquals("black", dogObj.getFavouriteColor()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + System.out.println("\nThis is 5th Test methode."); + } + + @Test public void isNameOfDogExits() { @@ -71,12 +150,14 @@ public void isDogsArrtibuteExits() public void isOptionalFavouriteFoodFieldExists() { LocalDate locDateTimeObj=LocalDate.now(); - DogEntityImmutableType dogObj=new DogEntityImmutableType("Touchi","Lasa",locDateTimeObj,"Rasgulla"); + DogEntityImmutableType dogObj=new DogEntityImmutableType("Touchi","Lasa",locDateTimeObj,"Rasgulla",null,null); Assert.assertEquals("Touchi",dogObj.getDogName()); - Assert.assertEquals("Rasgulla",dogObj.getFavouriteFood()); + Assert.assertEquals("Rasgulla",dogObj.getFavouriteColor()); System.out.println("\nThis is 3rd Test methode."); } + + } \ No newline at end of file From fc60856456e39fe4ef3da5b037e35102965dd38e Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Wed, 7 Feb 2024 00:05:34 +0530 Subject: [PATCH 03/30] expansion.serenity course 'Essential Design Patterns for Test Automation' 'The Builder Pattern' sub modules Exercises-1 , Exercises-2 & Exercises-3 full implementation --- .../domain/DogBreederEntityBuilder.java | 35 +++++- .../tutorials/vetclinic/domain/DogEntity.java | 54 ++++++-- .../domain/DogEntityImmutableType.java | 28 ++++- .../vetclinic/domain/IwithColourable.java | 1 + .../vetclinic/domain/WithIBreedable.java | 2 + .../vetclinic/domain/NewDogCreationTests.java | 115 ++++++++++++++---- 6 files changed, 199 insertions(+), 36 deletions(-) diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java index 6d073912..67a7197b 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogBreederEntityBuilder.java @@ -1,7 +1,7 @@ package serenitylabs.tutorials.vetclinic.domain; import java.time.LocalDate; -public class DogBreederEntityBuilder { +public class DogBreederEntityBuilder implements WithIBreedable,IwithColourable { private String name; private String breed; @@ -14,7 +14,7 @@ public DogBreederEntityBuilder(String name) { System.out.println("DogBreederEntityBuilder - builders object initialized."); } - public DogBreederEntityBuilder ofBreed(String breed) { + public DogBreederEntityBuilder ofDogBreed(String breed) { this.breed=breed; return this; } @@ -23,4 +23,35 @@ 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 index 3604ef42..e64dc1d1 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntity.java @@ -1,5 +1,5 @@ package serenitylabs.tutorials.vetclinic.domain; -import java.time.LocalDateTime; +import java.time.LocalDate; /** * Mutable DogEntity class as its fields values state can be modifyed with the @@ -11,7 +11,19 @@ public class DogEntity { private String dogName; private String dogBreed; - private LocalDateTime birthDateTime; + 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."); @@ -23,17 +35,41 @@ public String getDogName() { public String getDogBreed() { return dogBreed; } - public LocalDateTime getBirthDateTime() { + public LocalDate getBirthDateTime() { return birthDateTime; } - public void setDogName(String dogName) { - this.dogName = dogName; + + public String getFavouriteColour() { + return favouriteColour; } - public void setDogBreed(String dogBreed) { - this.dogBreed = dogBreed; + + public String getOptFldFavouriteFood() { + return optFldFavouriteFood; } - public void setBirthDateTime(LocalDateTime birthDateTime) { - this.birthDateTime = birthDateTime; + + 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 index b64c433f..d04e4a5c 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java @@ -7,7 +7,7 @@ * */ -public class DogEntityImmutableType implements WithIBreedable,IwithColourable { +public class DogEntityImmutableType { //marking fields with final soo that its state can not be change. private String dogName; @@ -17,6 +17,10 @@ public class DogEntityImmutableType implements WithIBreedable,IwithColourable { private String optFldFavouriteFood; private String optFldFavouriteToy; + 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."); @@ -32,6 +36,10 @@ public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDa System.out.println("Parameterized constructor with new field added."); } + public DogEntityImmutableType() { + + } + public DogEntityImmutableType(String name) { this.dogName=name; } @@ -58,11 +66,12 @@ public String getOptFldFavouriteToy() { return optFldFavouriteToy; } - public static WithIBreedable called(String name) { + + public DogEntityImmutableType called(String name) { + this.dogName=name; System.out.println("\nThis methode call is mandatory. called()"); - return new DogEntityImmutableType(name); + return this; } - public DogEntityImmutableType ofBreed(String breed) { System.out.println("\nThis methode call is mandatory. ofBreed()"); @@ -95,5 +104,16 @@ public DogEntityImmutableType setOptFldFavouriteToy(String optFldFavouriteToy) { 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"); + } } \ 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 index 57247183..c0ff2088 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/IwithColourable.java @@ -4,4 +4,5 @@ public interface IwithColourable { DogEntityImmutableType ofColour(String favColour); + DogBreederEntityBuilder ofDogColour(String strFavColour); } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java index 281f4ab6..d14908ed 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/WithIBreedable.java @@ -4,4 +4,6 @@ public interface WithIBreedable { IwithColourable ofBreed(String breed); + IwithColourable ofDogBreed(String breed); + } \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java index 277ad484..70bfcfb5 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java @@ -1,6 +1,5 @@ package serenitylabs.tutorials.vetclinic.domain; import java.time.LocalDate; -import java.time.LocalDateTime; import org.testng.Assert; import org.testng.annotations.Test; @@ -27,9 +26,10 @@ public class NewDogCreationTests { @Test public void a_new_dog_should_have_a_name() { - DogEntityImmutableType dogObj=((DogEntityImmutableType) DogEntityImmutableType.called("Fido") - .ofBreed("Labrador")) - .bornOn(THE_FOURTH_OF_JULY); + DogEntityImmutableType dogObj=DogEntityImmutableType.getImmutableInstance() + .called("Fido") + .ofBreed("Labrador") + .bornOn(THE_FOURTH_OF_JULY); Assert.assertEquals("Fido",dogObj.getDogName()); Assert.assertEquals("Labrador",dogObj.getDogBreed()); @@ -49,17 +49,17 @@ public void a_new_dog_should_have_a_name() */ @Test public void a_dog_can_have_an_optional_favourite_food() { - DogEntityImmutableType dogObj = DogEntityImmutableType.called("Fido") // mandatory - .ofBreed("Labrador") // mandatory - .ofColour("black") //ofColour is mandatory. - .setOptFldFavouriteFood("Pizza") //setOptFldFavouriteFood is optional - .bornOn(THE_FOURTH_OF_JULY); // mandatory + 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.getFavouriteColor()); + Assert.assertEquals("black", dogObj.getFavouriteColour()); Assert.assertEquals("Pizza", dogObj.getOptFldFavouriteFood()); - Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDateTime()); System.out.println("\nThis is 6th Test methode."); } @@ -75,8 +75,33 @@ public void a_dog_can_have_an_optional_favourite_food() { */ @Test public void a_dog_can_have_an_optional_favourite_toy() { - DogEntityImmutableType dogObj=DogEntityImmutableType.called("Fido") // mandatory - .ofBreed("Labrador") // mandatory + 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 @@ -86,7 +111,56 @@ public void a_dog_can_have_an_optional_favourite_toy() { Assert.assertEquals("black", dogObj.getFavouriteColor()); Assert.assertEquals("PingPong", dogObj.getOptFldFavouriteToy()); Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); - System.out.println("\nThis is 7th Test methode."); + 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()."); } @@ -104,15 +178,14 @@ public void a_dog_can_have_an_optional_favourite_toy() { */ @Test public void a_dog_can_have_an_optional_colour() { - DogEntityImmutableType dogObj = DogEntityImmutableType.called("Fido") // mandatory - .ofBreed("Labrador") // mandatory - .ofColour("black") //ofColour is optional. - .bornOn(THE_FOURTH_OF_JULY); // mandatory + 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.getFavouriteColor()); - Assert.assertEquals(THE_FOURTH_OF_JULY, dogObj.getBirthDate()); + Assert.assertEquals("black", dogObj.getFavouriteColour()); System.out.println("\nThis is 5th Test methode."); } @@ -123,7 +196,7 @@ public void isNameOfDogExits() DogEntity dogObj=new DogEntity(); dogObj.setDogName("Touchi"); dogObj.setDogBreed("Lasa"); - LocalDateTime locDateTimeObj=LocalDateTime.now(); + LocalDate locDateTimeObj=LocalDate.now(); dogObj.setBirthDateTime(locDateTimeObj); Assert.assertEquals("Touchi",dogObj.getDogName()); From 61d8ca4a6b21f096b5d09cf51aba63c4edce30c7 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 8 Feb 2024 03:25:00 +0530 Subject: [PATCH 04/30] adding depedency for hamcrest matchers --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index adac687d..26d914bd 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,16 @@ 3.1.0 test + + com.google.guava + guava + 23.0 + + + org.hamcrest + hamcrest-all + 1.3 + From b77979d34cc89f85b78bb06040685a8ebbf3805a Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 9 Feb 2024 03:28:44 +0530 Subject: [PATCH 05/30] Vet Clinic Tutorial 2 - Hamcrest Matchers - assignments Step 1 , Step 2 , Step 3 and Step 4 section implementations --- pom.xml | 7 ++- .../vetclinic/domain/AppointmentEntity.java | 5 ++ .../domain/DogEntityImmutableType.java | 26 ++++++++++ .../domain/TotalConsultationPrice.java | 13 +++++ .../vetclinic/domain/NewDogCreationTests.java | 51 +++++++++++++++++++ .../WhenCalculatingTotalPricesTests.java | 30 +++++++++++ .../domain/WhenWeBookAnAppointmentTests.java | 5 ++ 7 files changed, 136 insertions(+), 1 deletion(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/TotalConsultationPrice.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenCalculatingTotalPricesTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java diff --git a/pom.xml b/pom.xml index 26d914bd..76fffd0a 100644 --- a/pom.xml +++ b/pom.xml @@ -16,11 +16,16 @@ + + junit + junit + 4.12 + test + org.testng testng 7.8.0 - test org.assertj 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..9c1531e0 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public class AppointmentEntity { + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java index d04e4a5c..614b9167 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/DogEntityImmutableType.java @@ -1,5 +1,8 @@ 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 @@ -16,6 +19,7 @@ public class DogEntityImmutableType { private String favouriteColor; private String optFldFavouriteFood; private String optFldFavouriteToy; + private List strListOfColours; public static DogEntityImmutableType getImmutableInstance() { return new DogEntityImmutableType(); @@ -26,6 +30,13 @@ public DogEntityImmutableType(String dogName, String dogBreed, LocalDate birthDa 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; @@ -116,4 +127,19 @@ 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/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/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java index 70bfcfb5..013ea6d7 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/NewDogCreationTests.java @@ -1,4 +1,13 @@ 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; @@ -190,6 +199,48 @@ public void a_dog_can_have_an_optional_colour() { } + /* + * 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() { 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..234c7103 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.domain; + +public class WhenWeBookAnAppointmentTests { + +} From 5a1f6ec5b46fd863dfa4fde4c75c9033cd9b770d Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Wed, 14 Feb 2024 02:15:01 +0530 Subject: [PATCH 06/30] test script implementation for 'Vet Clinic Tutorial 2 - Hamcrest Matchers' Exercises Step 5 , Step 6 added --- .../AppointmentBookerBuilderEntity.java | 28 ++++++++++ .../vetclinic/domain/AppointmentEntity.java | 52 ++++++++++++++++++- .../domain/WhenWeBookAnAppointmentTests.java | 47 ++++++++++++++++- 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentBookerBuilderEntity.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 index 9c1531e0..baedf58c 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/domain/AppointmentEntity.java @@ -1,5 +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/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java index 234c7103..ca755cd6 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/domain/WhenWeBookAnAppointmentTests.java @@ -1,5 +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 From 07dab3f74eedd0d234d05aae532c436c75910125 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 23 Feb 2024 02:19:38 +0530 Subject: [PATCH 07/30] Working with Enumerations - Step 1,Step 2,Step 3 and Coding Kata - a colour calculator implementation --- pom.xml | 14 +- .../enumerations/colours/ColourEnum.java | 35 +++++ .../enumerations/exercises/BreedEnum.java | 21 +++ .../enumerations/exercises/GenderEnum.java | 5 + .../tutorials/vetclinic/katas/PetEntity.java | 76 +++++++++++ .../vetclinic/katas/PetEntityBuilder.java | 23 ++++ .../WhenCreatingAComplexEnumTests.java | 26 ++++ .../WhenCreatingASimpleEnumTests.java | 34 +++++ ...henWorkingWithASimpleEnumerationTests.java | 44 +++++++ .../WhenCalculatingWithColoursTests.java | 121 ++++++++++++++++++ 10 files changed, 395 insertions(+), 4 deletions(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/enumerations/colours/ColourEnum.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/BreedEnum.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/GenderEnum.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntityBuilder.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingAComplexEnumTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingASimpleEnumTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenWorkingWithASimpleEnumerationTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/enumerations/katas/WhenCalculatingWithColoursTests.java diff --git a/pom.xml b/pom.xml index 76fffd0a..7e8d5847 100644 --- a/pom.xml +++ b/pom.xml @@ -33,15 +33,21 @@ 3.1.0 test + + org.hamcrest + hamcrest-all + 1.3 + com.google.guava guava - 23.0 + 19.0 - org.hamcrest - hamcrest-all - 1.3 + pl.pragmatists + JUnitParams + 1.0.5 + test diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/colours/ColourEnum.java b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/colours/ColourEnum.java new file mode 100644 index 00000000..58a7d6e4 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/colours/ColourEnum.java @@ -0,0 +1,35 @@ +package serenitylabs.tutorials.vetclinic.enumerations.colours; +import java.util.Map; +import com.google.common.collect.Maps; + +public enum ColourEnum { + + Red(true), Orange(false), Yellow(true), Green(false), Blue(true), Violet(false), Black(false), White(false); + + private final boolean isPrimary; + private static final Map OPPOSITES = Maps.newHashMap(); + + ColourEnum(boolean isPrimary) { + this.isPrimary = isPrimary; + } + + public boolean isPrimary() { + return isPrimary; + } + + public ColourEnum opposite() { + return OPPOSITES.get(this); + } + + static { + OPPOSITES.put(Red, Green); + OPPOSITES.put(Green, Red); + OPPOSITES.put(Blue, Orange); + OPPOSITES.put(Orange, Blue); + OPPOSITES.put(Violet, Yellow); + OPPOSITES.put(Yellow, Violet); + OPPOSITES.put(Black, White); + OPPOSITES.put(White, Black); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/BreedEnum.java b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/BreedEnum.java new file mode 100644 index 00000000..2f527719 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/BreedEnum.java @@ -0,0 +1,21 @@ +package serenitylabs.tutorials.vetclinic.enumerations.exercises; + +public enum BreedEnum { + + Cat("Felis catus"), + Dog("Canis lupus familiaris"), + Rabbit("Oryctolagus cuniculus"), + Fish("Carassius auratus"), + Parrot("Psittaciformes"); + + private final String scientificName; + + BreedEnum(String scientificName) { + this.scientificName = scientificName; + } + + public String getScientificName() { + return scientificName; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/GenderEnum.java b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/GenderEnum.java new file mode 100644 index 00000000..dbbb2bf2 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/GenderEnum.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.enumerations.exercises; + +public enum GenderEnum { + Male, Female, Unknown; +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntity.java new file mode 100644 index 00000000..cf9cf51b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntity.java @@ -0,0 +1,76 @@ +package serenitylabs.tutorials.vetclinic.katas; +import java.util.Objects; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.BreedEnum; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.GenderEnum; + +public class PetEntity { + + private final String name; + private final BreedEnum breed; + private final GenderEnum gender; + + public PetEntity(String name, BreedEnum breed, GenderEnum gender) { + this.name = name; + this.breed = breed; + this.gender = gender; + } + + public PetEntity(String name, BreedEnum breed) { + this(name, breed, GenderEnum.Unknown); + } + + public String getName() { + return name; + } + + public BreedEnum getBreed() { + return breed; + } + + public GenderEnum getGender() { + return gender; + } + + @Override + public String toString() { + return "a " + breed + " called " + name; + } + + @Override + public int hashCode() { + return Objects.hash(breed, name); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof PetEntity)) { + return false; + } + PetEntity other = (PetEntity) obj; + return breed == other.breed && Objects.equals(name, other.name); + } + + public static PetEntityBuilder dog() { + return new PetEntityBuilder(BreedEnum.Dog); + } + + public static PetEntityBuilder cat() { + return new PetEntityBuilder(BreedEnum.Cat); + } + + public static PetEntityBuilder rabbit() { + return new PetEntityBuilder(BreedEnum.Rabbit); + } + + public static PetEntityBuilder parrot() { + return new PetEntityBuilder(BreedEnum.Parrot); + } + + public static PetEntityBuilder fish() { + return new PetEntityBuilder(BreedEnum.Fish); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntityBuilder.java new file mode 100644 index 00000000..238b8f3d --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/katas/PetEntityBuilder.java @@ -0,0 +1,23 @@ +package serenitylabs.tutorials.vetclinic.katas; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.BreedEnum; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.GenderEnum; + +public class PetEntityBuilder { + + private final BreedEnum breed; + private GenderEnum gender = GenderEnum.Unknown; + + public PetEntityBuilder(BreedEnum breed) { + this.breed = breed; + } + + public PetEntity named(String name) { + return new PetEntity(name, breed, gender); + } + + public PetEntityBuilder ofGender(GenderEnum gender) { + this.gender = gender; + return this; + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingAComplexEnumTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingAComplexEnumTests.java new file mode 100644 index 00000000..7a1b818e --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingAComplexEnumTests.java @@ -0,0 +1,26 @@ +package serenitylabs.tutorials.vetclinic.enumerations.exercises; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import org.testng.annotations.Test; + +public class WhenCreatingAComplexEnumTests { + + /** + * Add the scientific name to the animal breeds. + * Cat = "Felis catus" + * Dog = "Canis lupus familiaris" + * Rabbit = "Oryctolagus cuniculus" + * Fish = "Carassius auratus" + * Parrot = "Psittaciformes" + */ + @Test + public void should_be_able_to_find_the_scientific_names_of_an_animal_breed() { + + // TODO: Refactor the Breed enum so that it also stores the scientific name (see comment above). + assertThat(BreedEnum.Cat.getScientificName(), equalTo("Felis catus")); + assertThat(BreedEnum.Dog.getScientificName(), equalTo("Canis lupus familiaris")); + assertThat(BreedEnum.Rabbit.getScientificName(), equalTo("Oryctolagus cuniculus")); + System.out.println("\nThis is - TC-01 - should_be_able_to_find_the_scientific_names_of_an_animal_breed"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingASimpleEnumTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingASimpleEnumTests.java new file mode 100644 index 00000000..709bcbec --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenCreatingASimpleEnumTests.java @@ -0,0 +1,34 @@ +package serenitylabs.tutorials.vetclinic.enumerations.exercises; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class WhenCreatingASimpleEnumTests { + + @Test + public void the_gender_of_a_pet_should_be_considered_unknown_by_default() { + + // TODO: Add a gender field to the Pet class that takes two possible values: + // Male, Female and Unknown + + PetEntity unidentifiedTabby = PetEntity.cat().named("Spot"); + + assertThat(unidentifiedTabby.getGender(), equalTo(GenderEnum.Unknown)); + System.out.println("\nThis is - TC-01 - the_gender_of_a_pet_should_be_considered_unknown_by_default"); + } + + + @Test + public void the_gender_of_a_pet_can_be_provided() { + + // TODO: Refactor the Pet builder method to allow the following construct: + + PetEntity lassie = PetEntity.cat().ofGender(GenderEnum.Male).named("Lassie"); + + assertThat(lassie.getGender(), equalTo(GenderEnum.Male)); + System.out.println("\nThis is - TC-02 - the_gender_of_a_pet_can_be_provided"); + } + + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenWorkingWithASimpleEnumerationTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenWorkingWithASimpleEnumerationTests.java new file mode 100644 index 00000000..8ccd109c --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/exercises/WhenWorkingWithASimpleEnumerationTests.java @@ -0,0 +1,44 @@ +package serenitylabs.tutorials.vetclinic.enumerations.exercises; +import java.util.Arrays; +import java.util.List; +import java.util.stream.Collectors; +import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.contains; + +public class WhenWorkingWithASimpleEnumerationTests { + + @Test + public void finding_dogs() + { + List pets = ImmutableList.of(PetEntity.cat().named("Felix"), + PetEntity.dog().named("Rover"), + PetEntity.dog().named("Lassie"), + PetEntity.rabbit().named("Fiver")); + + // TODO: Extract all the dogs from the pets list + + List dogs = pets.stream() + .filter(pet -> pet.getBreed() == BreedEnum.Dog) + .collect(Collectors.toList()); + + assertThat(dogs,containsInAnyOrder(PetEntity.dog().named("Rover"), PetEntity.dog().named("Lassie"))); + System.out.println("\nThis is TC-01 - finding_dogs "); + } + + + @Test + public void list_all_known_breeds() + { + // TODO: List the names of all the known breeds + List breeds = Arrays.asList(BreedEnum.values()).stream().map(BreedEnum::toString) + .collect(Collectors.toList()); + + assertThat(breeds, contains("Cat", "Dog", "Rabbit", "Fish", "Parrot")); + System.out.println("\nThis is TC-02 - list_all_known_breeds "); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/katas/WhenCalculatingWithColoursTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/katas/WhenCalculatingWithColoursTests.java new file mode 100644 index 00000000..350aa45b --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/enumerations/katas/WhenCalculatingWithColoursTests.java @@ -0,0 +1,121 @@ +package serenitylabs.tutorials.vetclinic.enumerations.katas; +import static org.hamcrest.CoreMatchers.is; +import static org.hamcrest.Matchers.contains; +import static org.junit.Assert.assertThat; +import static com.google.common.collect.Lists.newArrayList; +import java.util.List; +import java.util.stream.Collectors; +import org.junit.runner.RunWith; +import org.testng.annotations.Parameters; +import org.testng.annotations.Test; +import com.google.common.collect.ImmutableList; +import junitparams.JUnitParamsRunner; +import serenitylabs.tutorials.vetclinic.enumerations.colours.ColourEnum; + +/* + * This Test class contains and runs test cases based on both TestNg and Junit Tests + * + */ +@RunWith(JUnitParamsRunner.class) +public class WhenCalculatingWithColoursTests { + + @Test + public void should_know_about_all_the_main_colours() { + List colours = newArrayList(ColourEnum.values()).stream() + .map(ColourEnum::toString) + .collect(Collectors.toList()); + assertThat(colours, contains("Red", "Orange", "Yellow", "Green", "Blue", "Violet", "Black", "White")); + System.out.println("\nTC-01 Executed - should_know_about_all_the_main_colours"); + } + + + @Test + public void should_identify_primary_colours() { + List expectedPrimaries = ImmutableList.of(ColourEnum.Red, ColourEnum.Yellow, ColourEnum.Blue); + + expectedPrimaries.forEach( + colour -> { + assertThat(colour.isPrimary(), is(true)); + } + ); + System.out.println("\nTC-02 Executed - should_identify_primary_colours"); + } + + + @Test + public void should_identify_non_primary_colours() { + List expectedPrimaries = ImmutableList.of(ColourEnum.Green, ColourEnum.Orange, ColourEnum.Violet); + + expectedPrimaries.forEach( + colour -> { + assertThat(colour.isPrimary(), is(false)); + } + ); + System.out.println("\nTC-03 Executed - should_identify_non_primary_colours"); + } + + + @Test + public void black_and_white_are_not_considered_primary() { + + assertThat(ColourEnum.Black.isPrimary(), is(false)); + assertThat(ColourEnum.White.isPrimary(), is(false)); + System.out.println("\nTC-04 Executed - black_and_white_are_not_considered_primary"); + } + + + @Test + public void red_is_the_opposite_of_green() { + assertThat(ColourEnum.Red.opposite(), is(ColourEnum.Green)); + System.out.println("\nTC-05 Executed - red_is_the_opposite_of_green"); + } + + + @Test + public void blue_is_the_opposite_of_orange() { + assertThat(ColourEnum.Blue.opposite(), is(ColourEnum.Orange)); + System.out.println("\nTC-06 Executed - blue_is_the_opposite_of_orange"); + } + + + @Test + public void yellow_is_the_opposite_of_violet() { + assertThat(ColourEnum.Yellow.opposite(), is(ColourEnum.Violet)); + System.out.println("\nTC-07 Executed - yellow_is_the_opposite_of_violet"); + } + + + @Test + public void black_is_the_opposite_of_white() { + assertThat(ColourEnum.Black.opposite(), is(ColourEnum.White)); + System.out.println("\nTC-08 Executed - black_is_the_opposite_of_white"); + } + + + /* + * This is junits parameterized test + */ + @Parameters({"Red,Green", + "Blue,Orange", + "Violet,Yellow", + "Black,White"}) + @org.junit.Test + public void should_identify_opposite_colours(ColourEnum colour, ColourEnum expectedOpposite) throws Exception { + assertThat(colour.opposite(),is(expectedOpposite)); + System.out.println("\nTC-09 Executed - should_identify_opposite_colours"); + } + + + @Test + public void opposite_colours_are_symmetric() { + newArrayList(ColourEnum.values()).stream() + .forEach( + colour -> { + assertThat(colour.opposite().opposite(),is(colour)); + } + ); + System.out.println("\nTC-10 Executed - opposite_colours_are_symmetric"); + } + + +} \ No newline at end of file From 8856dba79ba352d69176608aafc0b54732255778 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Sun, 25 Feb 2024 19:13:59 +0530 Subject: [PATCH 08/30] Collections Katas - Booking pets into a pet hotel - Working with collections - step-1,Step-2 ..,Step-10 implementation added --- .../collections/katas/APetHotelEntity.java | 14 ++ .../katas/BookingAcknowledgement.java | 9 + .../katas/BookingConfirmation.java | 20 ++ .../collections/katas/BookingResponse.java | 38 ++++ .../collections/katas/Calculator.java | 11 + .../collections/katas/CheckInStrategy.java | 8 + .../katas/ConfirmBookingStrategy.java | 19 ++ .../collections/katas/HotelAvailability.java | 7 + .../katas/PetAdderEntityBuilder.java | 37 ++++ .../vetclinic/collections/katas/PetHotel.java | 49 +++++ .../katas/PlacedOnWaitingList.java | 20 ++ .../katas/SpecialisedPetHotel.java | 22 ++ .../katas/WaitingListStrategy.java | 19 ++ .../WhenBookingPetsIntoAPetHotelTests.java | 208 ++++++++++++++++++ .../WhenWorkingWithAListOfPetNamesTests.java | 111 ++++++++++ .../WhenWorkingWithAListOfPetsTests.java | 25 +++ .../katas/WhenWorkingWithAPetMapTests.java | 108 +++++++++ .../katas/WhenWorkingWithAPetQueueTests.java | 40 ++++ .../katas/WhenWorkingWithASetOfPetsTests.java | 45 ++++ .../WhenWorkingWithAStackOfPetsTests.java | 44 ++++ 20 files changed, 854 insertions(+) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/APetHotelEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetAdderEntityBuilder.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/APetHotelEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/APetHotelEntity.java new file mode 100644 index 00000000..4a0774a4 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/APetHotelEntity.java @@ -0,0 +1,14 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; + +/** + * A utility class to generate pet hotels with pets already booked + * + */ + +public class APetHotelEntity { + + public static PetAdderEntityBuilder with(int petCount) { + return new PetAdderEntityBuilder(petCount); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java new file mode 100644 index 00000000..59300fb3 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java @@ -0,0 +1,9 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; + +public interface BookingAcknowledgement { + + boolean isConfirmed(); + + boolean isOnWaitingList(); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java new file mode 100644 index 00000000..6e1b152b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java @@ -0,0 +1,20 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class BookingConfirmation extends BookingResponse{ + + public BookingConfirmation(int number, PetEntity pet) { + super(number, pet); + } + + @Override + public boolean isConfirmed() { + return true; + } + + @Override + public boolean isOnWaitingList() { + return false; + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java new file mode 100644 index 00000000..369fec2b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java @@ -0,0 +1,38 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.concurrent.atomic.AtomicInteger; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public abstract class BookingResponse implements BookingAcknowledgement { + + private static AtomicInteger bookingNumberCounter = new AtomicInteger(); + private final int number; + private final PetEntity pet; + + public BookingResponse(int number, PetEntity pet) { + this.number = number; + this.pet = pet; + } + + public static BookingResponse confirmedFor(PetEntity pet) { + return new BookingConfirmation(bookingNumberCounter.incrementAndGet(), pet); + } + + public static BookingResponse waitingListFor(PetEntity pet) { + return new PlacedOnWaitingList(bookingNumberCounter.incrementAndGet(), pet); + } + + /** + * @return the number + */ + public int getNumber() { + return number; + } + + /** + * @return the pet + */ + public PetEntity getPet() { + return pet; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java new file mode 100644 index 00000000..4a4aa812 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java @@ -0,0 +1,11 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; + +public class Calculator { + + protected int field; + + public Integer calculate(String expression) { + return 0; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java new file mode 100644 index 00000000..e6eebd6b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java @@ -0,0 +1,8 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public interface CheckInStrategy { + + BookingResponse attemptToCheckIn(PetEntity pet); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java new file mode 100644 index 00000000..47147f63 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java @@ -0,0 +1,19 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.Collection; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class ConfirmBookingStrategy implements CheckInStrategy { + + private final Collection pets; + + public ConfirmBookingStrategy(Collection pets) { + this.pets = pets; + } + + @Override + public BookingResponse attemptToCheckIn(PetEntity pet) { + pets.add(pet); + return BookingResponse.confirmedFor(pet); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java new file mode 100644 index 00000000..75d9bef8 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; + +public enum HotelAvailability { + + Available, Full; + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetAdderEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetAdderEntityBuilder.java new file mode 100644 index 00000000..19949a3f --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetAdderEntityBuilder.java @@ -0,0 +1,37 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.List; +import java.util.Random; +import com.google.common.collect.ImmutableList; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.BreedEnum; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class PetAdderEntityBuilder { + + private final int petCount; + private final static Random random = new Random(); + private final static List PET_NAMES = ImmutableList.of("Fido","Felix","Rover","Spot"); + + public PetAdderEntityBuilder(int petCount) { + this.petCount = petCount; + } + + private PetEntity somePet(int petCount) { + return new PetEntity(someName(petCount), someBreed()); + } + + private BreedEnum someBreed() { + return BreedEnum.values()[ random.nextInt(BreedEnum.values().length) ]; + } + + private String someName(int petCount) { + return PET_NAMES.get(random.nextInt(PET_NAMES.size())) + " " + petCount; + } + + public PetHotel petsCheckedIn() { + PetHotel hotel = new PetHotel(); + for(int count = 0; count < petCount; count++) { + hotel.checkIn(somePet(count)); + } + return hotel; + } +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java new file mode 100644 index 00000000..674837ec --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java @@ -0,0 +1,49 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Comparator; +import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; +import java.util.Map; +import java.util.Queue; +import java.util.TreeSet; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class PetHotel { + + public static final int MAXIMUM_PETS = 20; + private Collection pets = new TreeSet<>(Comparator.comparing(PetEntity::getName)); + private Queue waitingList = new LinkedList<>(); + private static final Map CHECK_IN_STRATEGY = new HashMap<>(); + + { + CHECK_IN_STRATEGY.put(HotelAvailability.Available, new ConfirmBookingStrategy(pets)); + CHECK_IN_STRATEGY.put(HotelAvailability.Full, new WaitingListStrategy(waitingList)); + } + + public List getPets() { + return new ArrayList<>(pets); + } + + private HotelAvailability currentAvailability() { + return (pets.size() >= MAXIMUM_PETS) ? HotelAvailability.Full : HotelAvailability.Available; + } + + public BookingResponse checkIn(PetEntity pet) { + CheckInStrategy checkInStrategy = CHECK_IN_STRATEGY.get(currentAvailability()); + return checkInStrategy.attemptToCheckIn(pet); + } + + public Collection getWaitingList() { + return new ArrayList<>(waitingList); + } + + public void checkOut(PetEntity pet) { + pets.remove(pet); + if (!waitingList.isEmpty()) { + checkIn(waitingList.poll()); + } + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java new file mode 100644 index 00000000..a80a1e5b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java @@ -0,0 +1,20 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class PlacedOnWaitingList extends BookingResponse { + + public PlacedOnWaitingList(int number, PetEntity pet) { + super(number, pet); + } + + @Override + public boolean isConfirmed() { + return false; + } + + @Override + public boolean isOnWaitingList() { + return true; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java new file mode 100644 index 00000000..fb6cd1d7 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java @@ -0,0 +1,22 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.ArrayList; +import java.util.List; + +public class SpecialisedPetHotel { + + List pets = new ArrayList<>(); + + /** + * @return the pets + */ + public List getPets() { + return new ArrayList<>(pets); + } + + /** + * @param pets the pets to set + */ + public void checkIn(T pets) { + this.pets.add(pets); + } +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java new file mode 100644 index 00000000..12371843 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java @@ -0,0 +1,19 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.Collection; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; + +public class WaitingListStrategy implements CheckInStrategy { + + private final Collection relevantPets; + + public WaitingListStrategy(Collection relevantPets) { + this.relevantPets = relevantPets; + } + + @Override + public BookingResponse attemptToCheckIn(PetEntity pet) { + relevantPets.add(pet); + return BookingResponse.waitingListFor(pet); + } + +} diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java new file mode 100644 index 00000000..c9186e0d --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java @@ -0,0 +1,208 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.CoreMatchers.hasItem; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.not; + +public class WhenBookingPetsIntoAPetHotelTests { + + @Test + public void the_hotel_should_initially_have_no_pets_booked() { + // GIVEN + PetHotel hotel = new PetHotel(); + // THEN + assertThat(hotel.getPets(), hasSize(0)); + System.out.println("\nStep-1 - part 1 - Execution completed."); + } + + + @Test + public void should_be_able_to_check_a_pet_into_the_hotel() { + // GIVEN + PetHotel hotel = new PetHotel(); + PetEntity fido = PetEntity.dog().named("Fido"); + + // WHEN + hotel.checkIn(fido); + + // THEN + assertThat(hotel.getPets(), hasItem(fido)); + System.out.println("\nStep-2 - part 2 - Execution completed."); + } + + + @Test + public void should_be_able_to_check_in_several_pets() { + // GIVEN + PetHotel hotel = new PetHotel(); + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity felix = PetEntity.cat().named("Felix"); + + // WHEN + hotel.checkIn(fido); + hotel.checkIn(felix); + + // THEN + assertThat(hotel.getPets(), hasItems(fido, felix)); + System.out.println("\nStep-3 - part 3 - Execution completed."); + } + + + @Test + public void should_not_be_able_to_check_in_the_same_pet_twice() { + // GIVEN + PetHotel hotel = new PetHotel(); + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity felix = PetEntity.cat().named("Felix"); + + // AND + hotel.checkIn(fido); + hotel.checkIn(felix); + + // WHEN + hotel.checkIn(fido); + + // THEN + assertThat(hotel.getPets(),containsInAnyOrder(fido, felix)); + System.out.println("\nStep-4 - part 4 - Execution completed."); + } + + + @Test + public void should_be_able_to_retrieve_checked_in_pets_in_alphabetical_order() { + // GIVEN + PetHotel hotel = new PetHotel(); + PetEntity hazel = PetEntity.rabbit().named("Hazel"); + PetEntity rover = PetEntity.dog().named("Rover"); + PetEntity felix = PetEntity.cat().named("Felix"); + + // WHEN + hotel.checkIn(hazel); + hotel.checkIn(rover); + hotel.checkIn(felix); + + // THEN + assertThat(hotel.getPets(),contains(felix, hazel, rover)); + + System.out.println("\nStep-5 - part 4 - Execution completed."); + } + + + @Test + public void should_be_able_to_obtain_a_booking_confirmation_when_we_check_in_a_pet() { + // GIVEN + PetHotel hotel = new PetHotel(); + PetEntity fido = PetEntity.dog().named("Fido"); + + // WHEN + BookingResponse confirmation = hotel.checkIn(fido); + + // THEN + assertThat(confirmation.getNumber(), greaterThan(0)); + assertThat(confirmation.getPet(), equalTo(fido)); + assertThat(confirmation.isConfirmed(), equalTo(true)); + System.out.println("\nStep-6 - part 4 - Execution completed."); + } + + + @Test + public void should_not_be_able_to_check_in_pets_beyond_hotel_capacity() { + // GIVEN + PetHotel hotel = APetHotelEntity.with(PetHotel.MAXIMUM_PETS).petsCheckedIn(); + + // WHEN + hotel.checkIn(PetEntity.dog().named("Lassie")); + + assertThat(hotel.getPets(), hasSize(20)); + System.out.println("\nStep-7 - part 4 - Execution completed."); + } + + + /* + * + * Refactor checkIn method to return a BookingAcknowledgement interface, which + * has two methods: isConfirmed() and isOnWaitingList(). You will need to + * complete the APetHotel helper class used in the Given. + * + */ + @Test + public void should_notify_owner_that_the_hotel_is_full() { + // GIVEN + PetHotel hotel = APetHotelEntity.with(20).petsCheckedIn(); + + // WHEN + BookingResponse response = hotel.checkIn(PetEntity.dog().named("Lassie")); + + // THEN + assertThat(response.isConfirmed(),is(false)); + assertThat(response.isOnWaitingList(),is(true)); + System.out.println("\nStep-8 - part 4 - Execution completed."); + } + + + @Test + public void should_place_pets_on_a_waiting_list_when_the_hotel_is_full() { + // GIVEN + PetHotel hotel = APetHotelEntity.with(20).petsCheckedIn(); + PetEntity lassie = PetEntity.dog().named("Lassie"); + + // WHEN + hotel.checkIn(lassie); + + // THEN + assertThat(hotel.getWaitingList(), hasItem(lassie)); + System.out.println("\nStep-9 - part 4 - Execution completed."); + } + + + @Test + public void pets_on_the_waiting_list_should_be_added_to_the_hotel_when_a_place_is_freed() { + // GIVEN + PetHotel hotel = APetHotelEntity.with(19).petsCheckedIn(); + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity lassie = PetEntity.dog().named("Lassie"); + + hotel.checkIn(fido); + + // WHEN + hotel.checkIn(lassie); + // AND + hotel.checkOut(fido); + + // THEN + assertThat(hotel.getPets(), hasItem(lassie)); + System.out.println("\nStep-10 - part 4 - Execution completed."); + } + + + @Test + public void pets_on_the_waiting_list_should_be_admitted_on_a_first_come_first_served_basis() { + // GIVEN + PetHotel hotel = APetHotelEntity.with(19).petsCheckedIn(); + PetEntity felix = PetEntity.cat().named("Felix"); + + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity lassie = PetEntity.dog().named("Lassie"); + hotel.checkIn(felix); + + // WHEN + hotel.checkIn(fido); + hotel.checkIn(lassie); + // AND + hotel.checkOut(felix); + + // THEN + assertThat(hotel.getPets(), hasItem(fido)); + assertThat(hotel.getPets(), not(hasItem(lassie))); + System.out.println("\nStep-11 - part 4 - Execution completed."); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java new file mode 100644 index 00000000..3c888f15 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java @@ -0,0 +1,111 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import org.testng.annotations.Test; +import com.google.common.collect.Lists; +import static org.hamcrest.CoreMatchers.hasItems; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.MatcherAssert.assertThat; + +public class WhenWorkingWithAListOfPetNamesTests { + + @Test + public void should_add_Fido_to_the_list_of_pets() { + List names = Lists.newArrayList(); + // TODO + names.add("Fido"); + + assertThat(names, contains("Fido")); + System.out.println("\nStep-1 - TC-01 - executing - should_add_Fido_to_the_list_of_pets() "); + } + + + @Test + public void should_remove_Fido_from_the_list_of_pets() { + List names = Lists.newArrayList("Felix", "Fido", "Spot"); + // TODO + names.remove("Fido"); + + assertThat(names, contains("Felix", "Spot")); + System.out.println("\nStep-2 - TC-02 - executing - should_remove_Fido_from_the_list_of_pets() "); + } + + + @Test + public void should_remove_the_first_pet_from_the_list_of_pets() { + List names = Lists.newArrayList("Felix", "Fido", "Spot"); + + // TODO + names.remove(0); + + assertThat(names, contains("Fido", "Spot")); + System.out.println("\nStep-3 - TC-03 - executing - should_remove_the_first_pet_from_the_list_of_pets() "); + } + + + @Test + public void should_make_a_list_of_cats_and_dogs() { + List cats = Lists.newArrayList("Felix", "Spot"); + List dogs = Lists.newArrayList("Fido", "Rover"); + + // TODO + List catsAndDogs = new ArrayList(cats); + catsAndDogs.addAll(dogs); + + assertThat(catsAndDogs, contains("Felix", "Spot", "Fido", "Rover")); + System.out.println("\nStep-4 - TC-04 - executing - should_make_a_list_of_cats_and_dogs() "); + } + + + @Test + public void should_put_the_dogs_among_the_cats() { + List cats = Lists.newArrayList("Felix", "Spot"); + List dogs = Lists.newArrayList("Fido", "Rover"); + + // TODO + List catsAndDogs = new ArrayList(cats); + catsAndDogs.addAll(1, dogs); + + assertThat(catsAndDogs, contains("Felix", "Fido", "Rover", "Spot")); + System.out.println("\nStep-5 - TC-05 - executing - should_put_the_dogs_among_the_cats() "); + } + + + @Test + public void should_organise_pets_in_alphabetical_order() { + List pets = Lists.newArrayList("Felix", "Spot", "Fido", "Rover"); + + // TODO + pets.sort(Comparator.naturalOrder()); + + assertThat(pets, contains("Felix", "Fido", "Rover", "Spot")); + System.out.println("\nStep-6 - TC-06 - executing - should_organise_pets_in_alphabetical_order() "); + } + + + @Test + public void should_organise_pets_in_reverse_alphabetical_order() { + List pets = Lists.newArrayList("Felix", "Spot", "Fido", "Rover"); + + // TODO + pets.sort(Comparator.reverseOrder()); + + assertThat(pets, hasItems("Spot", "Rover", "Fido", "Felix")); + System.out.println("\nStep-7 - TC-07 - executing - should_organise_pets_in_reverse_alphabetical_order() "); + } + + + @Test + public void should_organise_pets_by_name_length() { + List pets = Lists.newArrayList("Felix", "Alfred", "Spot"); + + // TODO + pets.sort(Comparator.comparing(String::length)); + + assertThat(pets, contains("Spot", "Felix", "Alfred")); + System.out.println("\nStep-8 - TC-08 - executing - should_organise_pets_by_name_length() "); + } + + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java new file mode 100644 index 00000000..3383d072 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java @@ -0,0 +1,25 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.ArrayList; +import java.util.List; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.Matchers.hasItem; +import static org.hamcrest.MatcherAssert.assertThat; + +public class WhenWorkingWithAListOfPetsTests { + + @Test + public void should_store_a_list_of_pets() { + + List pets = new ArrayList<>(); + + pets.add(PetEntity.cat().named("Felix")); + pets.add(PetEntity.dog().named("Fido")); + + // TODO: Implement the equals and hashcode methods in the Pet class to make this + // work + assertThat(pets, hasItem(PetEntity.dog().named("Fido"))); + System.out.println("\nStep-1 - TC-01 - Executing should_store_a_list_of_pets()"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java new file mode 100644 index 00000000..dce9ddae --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java @@ -0,0 +1,108 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.EnumMap; +import java.util.HashMap; +import java.util.LinkedHashMap; +import java.util.Map; +import java.util.NavigableMap; +import java.util.TreeMap; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.enumerations.exercises.BreedEnum; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; +import static org.hamcrest.Matchers.contains; + +public class WhenWorkingWithAPetMapTests { + + @Test + public void pets_can_be_found_by_their_name() { + Map pets = new HashMap<>(); + + PetEntity fido = PetEntity.dog().named("Fido"); + + pets.put("Fido", fido); + + // TODO + assertThat(pets.get("Fido"), equalTo(fido)); + System.out.println("\nStep-1 - TC-01 - Executing pets_can_be_found_by_their_name() "); + } + + + @Test + public void should_be_able_to_get_a_default_value_if_no_matching_key_is_present() { + Map pets = new HashMap<>(); + + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity stray = PetEntity.dog().named("Stray"); + + pets.put("Fido", fido); + pets.put("Stray", stray); + + PetEntity retrievedPet = pets.getOrDefault("Rover", stray); + + // TODO + assertThat(retrievedPet, equalTo(stray)); + System.out.println("\nStep-2 - TC-02 - should_be_able_to_get_a_default_value_if_no_matching_key_is_present() "); + } + + + @Test + public void the_map_keys_should_be_the_pet_names() { + Map pets = new HashMap<>(); + + PetEntity fido = PetEntity.dog().named("Fido"); + PetEntity felix = PetEntity.cat().named("Felix"); + + pets.put("Fido", fido); + pets.put("Felix", felix); + + // TODO + assertThat(pets.keySet(), containsInAnyOrder("Fido","Felix")); + System.out.println("\nStep-3 - TC-03 - the_map_keys_should_be_the_pet_names() "); + } + + + @Test + public void the_map_should_store_pets_in_alphabetical_order() { + // TODO: Instantiate the correct type of Map + NavigableMap pets = new TreeMap<>(); + + pets.put("Rover", PetEntity.dog().named("Rover")); + pets.put("Felix", PetEntity.cat().named("Felix")); + pets.put("Spot", PetEntity.cat().named("Spot")); + + assertThat(pets.keySet(), contains("Felix","Rover","Spot")); + System.out.println("\nStep-4 - TC-04 - the_map_should_store_pets_in_alphabetical_order() "); + } + + + @Test + public void the_map_should_store_pets_in_the_order_they_where_added() { + // TODO: Instantiate the correct type of Map + Map pets = new LinkedHashMap<>(); + + pets.put("Spot", PetEntity.cat().named("Spot")); + pets.put("Rover", PetEntity.dog().named("Rover")); + pets.put("Felix", PetEntity.cat().named("Felix")); + pets.put("Fido", PetEntity.cat().named("Fido")); + + assertThat(pets.keySet(), contains("Spot", "Rover","Felix", "Fido")); + System.out.println("\nStep-5 - TC-05 - the_map_should_store_pets_in_the_order_they_where_added() "); + } + + + @Test + public void the_map_should_store_pet_leaders_by_breed() { + // TODO: Create an EnumMap to define a pet leader for each breed + EnumMap petLeaders = new EnumMap<>(BreedEnum.class); + + petLeaders.put(BreedEnum.Cat, PetEntity.cat().named("Felix")); + petLeaders.put(BreedEnum.Dog, PetEntity.dog().named("Lassie")); + petLeaders.put(BreedEnum.Rabbit, PetEntity.cat().named("Hazel")); + + assertThat(petLeaders.get(BreedEnum.Dog).getName(), equalTo("Lassie")); + System.out.println("\nStep-6 - TC-06 - the_map_should_store_pet_leaders_by_breed() "); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java new file mode 100644 index 00000000..0f8ce189 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java @@ -0,0 +1,40 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.LinkedList; +import java.util.Queue; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; + +public class WhenWorkingWithAPetQueueTests { + + @Test + public void should_add_Fido_to_the_end_of_the_queue() { + Queue waitingList = new LinkedList<>(); + + waitingList.add(PetEntity.cat().named("Felix")); + waitingList.add(PetEntity.dog().named("Fido")); + + PetEntity nextInLine = waitingList.poll(); + + // TODO + assertThat(nextInLine.getName(), equalTo("Felix")); + System.out.println("\nStep-1 - TC-01 - Executing - should_add_Fido_to_the_end_of_the_queue()"); + } + + + @Test + public void should_see_who_is_at_the_top_of_the_queue_without_removing_it() { + Queue waitingList = new LinkedList<>(); + + waitingList.add(PetEntity.cat().named("Felix")); + waitingList.add(PetEntity.dog().named("Fido")); + + PetEntity nextInLine = waitingList.peek(); + + // TODO + assertThat(nextInLine.getName(), equalTo("Felix")); + System.out.println("\nStep-2 - TC-02 - Executing - should_see_who_is_at_the_top_of_the_queue_without_removing_it()"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java new file mode 100644 index 00000000..8c5aaa10 --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java @@ -0,0 +1,45 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import java.util.Set; +import org.testng.annotations.Test; +import com.google.common.collect.Sets; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsInAnyOrder; + +public class WhenWorkingWithASetOfPetsTests { + + @Test + public void should_add_Fido_to_the_set_of_pets() { + Set names = Sets.newHashSet(); + // TODO + names.add("Fido"); + + assertThat(names, contains("Fido")); + System.out.println("\nStep-1 - TC-01 - Executing should_add_Fido_to_the_set_of_pets()"); + } + + + @Test + public void a_set_of_pets_should_not_contain_duplicates() { + Set names = Sets.newHashSet(); + names.add("Fido"); + names.add("Felix"); + names.add("Fido"); + + // TODO + assertThat(names, containsInAnyOrder("Fido", "Felix")); + System.out.println("\nStep-2 - TC-02 - Executing a_set_of_pets_should_not_contain_duplicates()"); + } + + + @Test + public void adding_several_pets() { + Set names = Sets.newHashSet("Fido", "Felix"); + names.addAll(Sets.newHashSet("Felix", "Spot")); + + // TODO + assertThat(names, containsInAnyOrder("Fido", "Felix", "Spot")); + System.out.println("\nStep-3 - TC-03 - Executing adding_several_pets()"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java new file mode 100644 index 00000000..63fc038a --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java @@ -0,0 +1,44 @@ +package serenitylabs.tutorials.vetclinic.collections.katas; +import static org.hamcrest.Matchers.equalTo; +import java.util.Deque; +import java.util.LinkedList; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.katas.PetEntity; +import static org.hamcrest.MatcherAssert.assertThat; + +public class WhenWorkingWithAStackOfPetsTests { + + @Test + public void should_store_pets_in_a_stack() { + + Deque pets = new LinkedList<>(); + + pets.push(PetEntity.cat().named("Felix")); + pets.push(PetEntity.dog().named("Fido")); + + // TODO: Retrieve the last pet put on the list + PetEntity lastPet = pets.pop(); + + assertThat(lastPet.getName(), equalTo("Fido")); + assertThat(pets.size(), equalTo(1)); + System.out.println("\nStep-1 - TC-01 - Executing should_store_pets_in_a_stack()"); + } + + + @Test + public void should_see_the_next_item_in_a_stack() { + + Deque pets = new LinkedList<>(); + + pets.push(PetEntity.cat().named("Felix")); + pets.push(PetEntity.dog().named("Fido")); + + // TODO: Retrieve the last pet put on the list + PetEntity lastPet = pets.peek(); + + assertThat(lastPet.getName(), equalTo("Fido")); + assertThat(pets.size(), equalTo(2)); + System.out.println("\nStep-2 - TC-02 - Executing should_see_the_next_item_in_a_stack()"); + } + +} \ No newline at end of file From 47d276259cb0804ac98e799bc5112bf4ffe5b4e8 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Sun, 25 Feb 2024 19:25:41 +0530 Subject: [PATCH 09/30] organizing by segregetting into new packages under both src/main/java , src/test/java with collections.exercises , collections.katas --- .../{katas => exercises}/BookingAcknowledgement.java | 2 +- .../{katas => exercises}/BookingConfirmation.java | 2 +- .../collections/{katas => exercises}/BookingResponse.java | 2 +- .../collections/{katas => exercises}/Calculator.java | 2 +- .../collections/{katas => exercises}/CheckInStrategy.java | 2 +- .../{katas => exercises}/ConfirmBookingStrategy.java | 2 +- .../vetclinic/collections/exercises/HotelAvailability.java | 7 +++++++ .../{katas => exercises}/PlacedOnWaitingList.java | 2 +- .../{katas => exercises}/SpecialisedPetHotel.java | 2 +- .../{katas => exercises}/WaitingListStrategy.java | 2 +- .../vetclinic/collections/katas/HotelAvailability.java | 7 ------- .../tutorials/vetclinic/collections/katas/PetHotel.java | 6 ++++++ .../WhenWorkingWithAListOfPetNamesTests.java | 2 +- .../WhenWorkingWithAListOfPetsTests.java | 2 +- .../{katas => exercises}/WhenWorkingWithAPetMapTests.java | 2 +- .../WhenWorkingWithAPetQueueTests.java | 2 +- .../WhenWorkingWithASetOfPetsTests.java | 2 +- .../WhenWorkingWithAStackOfPetsTests.java | 2 +- .../katas/WhenBookingPetsIntoAPetHotelTests.java | 1 + 19 files changed, 29 insertions(+), 22 deletions(-) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/BookingAcknowledgement.java (60%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/BookingConfirmation.java (83%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/BookingResponse.java (93%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/Calculator.java (64%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/CheckInStrategy.java (69%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/ConfirmBookingStrategy.java (86%) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/HotelAvailability.java rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/PlacedOnWaitingList.java (83%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/SpecialisedPetHotel.java (83%) rename src/main/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WaitingListStrategy.java (87%) delete mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithAListOfPetNamesTests.java (98%) rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithAListOfPetsTests.java (91%) rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithAPetMapTests.java (98%) rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithAPetQueueTests.java (94%) rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithASetOfPetsTests.java (95%) rename src/test/java/serenitylabs/tutorials/vetclinic/collections/{katas => exercises}/WhenWorkingWithAStackOfPetsTests.java (95%) diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingAcknowledgement.java similarity index 60% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingAcknowledgement.java index 59300fb3..8645adac 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingAcknowledgement.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingAcknowledgement.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; public interface BookingAcknowledgement { diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingConfirmation.java similarity index 83% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingConfirmation.java index 6e1b152b..be030664 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingConfirmation.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingConfirmation.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import serenitylabs.tutorials.vetclinic.katas.PetEntity; public class BookingConfirmation extends BookingResponse{ diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingResponse.java similarity index 93% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingResponse.java index 369fec2b..3de126e6 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/BookingResponse.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/BookingResponse.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.concurrent.atomic.AtomicInteger; import serenitylabs.tutorials.vetclinic.katas.PetEntity; diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/Calculator.java similarity index 64% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/Calculator.java index 4a4aa812..bc970080 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/Calculator.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/Calculator.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; public class Calculator { diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/CheckInStrategy.java similarity index 69% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/CheckInStrategy.java index e6eebd6b..bdb09880 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/CheckInStrategy.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/CheckInStrategy.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import serenitylabs.tutorials.vetclinic.katas.PetEntity; public interface CheckInStrategy { diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/ConfirmBookingStrategy.java similarity index 86% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/ConfirmBookingStrategy.java index 47147f63..be979e1a 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/ConfirmBookingStrategy.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/ConfirmBookingStrategy.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.Collection; import serenitylabs.tutorials.vetclinic.katas.PetEntity; diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/HotelAvailability.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/HotelAvailability.java new file mode 100644 index 00000000..f06a1b0e --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/HotelAvailability.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.collections.exercises; + +public enum HotelAvailability { + + Available, Full; + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/PlacedOnWaitingList.java similarity index 83% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/PlacedOnWaitingList.java index a80a1e5b..cc2c9aeb 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PlacedOnWaitingList.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/PlacedOnWaitingList.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import serenitylabs.tutorials.vetclinic.katas.PetEntity; public class PlacedOnWaitingList extends BookingResponse { diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/SpecialisedPetHotel.java similarity index 83% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/SpecialisedPetHotel.java index fb6cd1d7..c4263120 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/SpecialisedPetHotel.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/SpecialisedPetHotel.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/WaitingListStrategy.java similarity index 87% rename from src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java rename to src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/WaitingListStrategy.java index 12371843..415f7b0d 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/WaitingListStrategy.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/exercises/WaitingListStrategy.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.Collection; import serenitylabs.tutorials.vetclinic.katas.PetEntity; diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java deleted file mode 100644 index 75d9bef8..00000000 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/HotelAvailability.java +++ /dev/null @@ -1,7 +0,0 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; - -public enum HotelAvailability { - - Available, Full; - -} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java index 674837ec..bdadd25a 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/collections/katas/PetHotel.java @@ -8,6 +8,12 @@ import java.util.Map; import java.util.Queue; import java.util.TreeSet; + +import serenitylabs.tutorials.vetclinic.collections.exercises.BookingResponse; +import serenitylabs.tutorials.vetclinic.collections.exercises.CheckInStrategy; +import serenitylabs.tutorials.vetclinic.collections.exercises.ConfirmBookingStrategy; +import serenitylabs.tutorials.vetclinic.collections.exercises.HotelAvailability; +import serenitylabs.tutorials.vetclinic.collections.exercises.WaitingListStrategy; import serenitylabs.tutorials.vetclinic.katas.PetEntity; public class PetHotel { diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetNamesTests.java similarity index 98% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetNamesTests.java index 3c888f15..63101934 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetNamesTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetNamesTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.ArrayList; import java.util.Comparator; import java.util.List; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetsTests.java similarity index 91% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetsTests.java index 3383d072..63ee6f58 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAListOfPetsTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAListOfPetsTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.ArrayList; import java.util.List; import org.testng.annotations.Test; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetMapTests.java similarity index 98% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetMapTests.java index dce9ddae..76e7df11 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetMapTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetMapTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.EnumMap; import java.util.HashMap; import java.util.LinkedHashMap; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetQueueTests.java similarity index 94% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetQueueTests.java index 0f8ce189..e5d5defe 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAPetQueueTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAPetQueueTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.LinkedList; import java.util.Queue; import org.testng.annotations.Test; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithASetOfPetsTests.java similarity index 95% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithASetOfPetsTests.java index 8c5aaa10..6fae5528 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithASetOfPetsTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithASetOfPetsTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import java.util.Set; import org.testng.annotations.Test; import com.google.common.collect.Sets; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAStackOfPetsTests.java similarity index 95% rename from src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java rename to src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAStackOfPetsTests.java index 63fc038a..4f8bf8d2 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenWorkingWithAStackOfPetsTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/exercises/WhenWorkingWithAStackOfPetsTests.java @@ -1,4 +1,4 @@ -package serenitylabs.tutorials.vetclinic.collections.katas; +package serenitylabs.tutorials.vetclinic.collections.exercises; import static org.hamcrest.Matchers.equalTo; import java.util.Deque; import java.util.LinkedList; diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java index c9186e0d..1cfbe3cf 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/collections/katas/WhenBookingPetsIntoAPetHotelTests.java @@ -1,5 +1,6 @@ package serenitylabs.tutorials.vetclinic.collections.katas; import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.collections.exercises.BookingResponse; import serenitylabs.tutorials.vetclinic.katas.PetEntity; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.contains; From fc01bfb2250cc807e31294eb779c6b02eea66a19 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Sun, 25 Feb 2024 19:30:58 +0530 Subject: [PATCH 10/30] modifyed the pom.xml with surefire pluggin entry line no-71 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 7e8d5847..dac873af 100644 --- a/pom.xml +++ b/pom.xml @@ -68,7 +68,7 @@ **/When*.java - **/*Test.java + **/*Tests.java **/*TestSuite.java From 4aee7ef60df504add3cd1b1de44bdef923e80378 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Wed, 28 Feb 2024 02:31:25 +0530 Subject: [PATCH 11/30] adding strtegy with Functions+Strategy pattern initial test codes. --- .../playingball/model/ChildEntity.java | 10 +++ .../model/DontKnowThatGameException.java | 11 ++++ .../vetclinic/playingball/model/GameEnum.java | 7 ++ .../vetclinic/playingball/model/IPlayer.java | 5 ++ .../playingball/model/PlayCricket.java | 10 +++ .../playingball/model/PlayFootball.java | 10 +++ .../playingball/model/PlayHandball.java | 10 +++ .../playingball/model/PlayHockey.java | 10 +++ .../playingball/model/PlayTennis.java | 10 +++ .../playingball/model/PlayerForGame.java | 22 +++++++ .../playingball/model/SampleDates.java | 24 +++++++ .../playingball/sales/SalesTaxService.java | 5 ++ .../vetclinic/playingball/sales/TaxRate.java | 27 ++++++++ .../playingball/sales/TaxRateCalculator.java | 7 ++ .../playingball/sales/model/LineItem.java | 5 ++ .../sales/model/ProductCategoryEnum.java | 6 ++ .../playingball/sales/model/SalesTax.java | 5 ++ .../playingball/WhenToldToPlayBallTests.java | 66 +++++++++++++++++++ .../sales/WhenApplyingSalesTaxTests.java | 5 ++ 19 files changed, 255 insertions(+) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/GameEnum.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayer.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayerForGame.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SampleDates.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRate.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ProductCategoryEnum.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java new file mode 100644 index 00000000..7b370256 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class ChildEntity { + + public void goPlay(GameEnum game) { + IPlayer gameToPlay = PlayerForGame.called(game); + gameToPlay.play(); + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java new file mode 100644 index 00000000..545fff26 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java @@ -0,0 +1,11 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class DontKnowThatGameException extends RuntimeException { + + private static final long serialVersionUID = 1L; + private String strMessage; + public DontKnowThatGameException(String strMsg) { + this.strMessage=strMsg; + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/GameEnum.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/GameEnum.java new file mode 100644 index 00000000..66235fe8 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/GameEnum.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public enum GameEnum { + + Football, Tennis, Cricket, Handball, Hockey; + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayer.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayer.java new file mode 100644 index 00000000..e7299b37 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayer.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public interface IPlayer { + void play(); +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java new file mode 100644 index 00000000..042af5f2 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayCricket implements IPlayer { + + @Override + public void play() { + System.out.print("Hit the wicket"); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java new file mode 100644 index 00000000..d892aa58 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayFootball implements IPlayer { + + @Override + public void play() { + System.out.print("Kick the ball"); + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java new file mode 100644 index 00000000..ca0f65d8 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayHandball implements IPlayer { + + @Override + public void play() { + System.out.print("Throw the ball"); + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java new file mode 100644 index 00000000..43916ec9 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayHockey implements IPlayer { + + @Override + public void play() { + System.out.print("Hit the ball with the stick"); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java new file mode 100644 index 00000000..33292483 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java @@ -0,0 +1,10 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayTennis implements IPlayer { + + @Override + public void play() { + System.out.print("Serve the ball"); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayerForGame.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayerForGame.java new file mode 100644 index 00000000..ad8fb27b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayerForGame.java @@ -0,0 +1,22 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public class PlayerForGame { + + public static IPlayer called(GameEnum game) { + switch (game) { + case Football: + return new PlayFootball(); + case Tennis: + return new PlayTennis(); + case Cricket: + return new PlayCricket(); + case Handball: + return new PlayHandball(); + case Hockey: + return new PlayHockey(); + default: + throw new DontKnowThatGameException("Wrong!! choice.."); + } + } + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SampleDates.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SampleDates.java new file mode 100644 index 00000000..d5101667 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SampleDates.java @@ -0,0 +1,24 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; +import java.time.Month; + +public class SampleDates { + + public static final LocalDate A_SATURDAY = LocalDate.of(2016, Month.AUGUST, 27); + public static final LocalDate A_SUNDAY = LocalDate.of(2016, Month.AUGUST, 28); + public static final LocalDate A_MONDAY = LocalDate.of(2016, Month.AUGUST, 29); + public static final LocalDate A_TUESDAY = LocalDate.of(2016, Month.AUGUST, 30); + public static final LocalDate A_WEDNESDAY = LocalDate.of(2016, Month.AUGUST, 31); + public static final LocalDate A_THURSDAY = LocalDate.of(2016, Month.SEPTEMBER, 1); + public static final LocalDate A_FRIDAY = LocalDate.of(2016, Month.SEPTEMBER, 2); + + public static final LocalDate A_DATE_IN_JANUARY = LocalDate.of(2016, Month.JANUARY, 1); + public static final LocalDate A_DATE_IN_MAY = LocalDate.of(2016, Month.MAY, 31); + public static final LocalDate A_DATE_IN_JUNE = LocalDate.of(2016, Month.JUNE, 1); + public static final LocalDate A_DATE_IN_JULY = LocalDate.of(2016, Month.JULY, 15); + public static final LocalDate A_DATE_IN_AUGUST = LocalDate.of(2016, Month.AUGUST, 15); + public static final LocalDate A_DATE_IN_SEPTEMBER = LocalDate.of(2016, Month.SEPTEMBER, 30); + public static final LocalDate A_DATE_IN_OCTOBER = LocalDate.of(2016, Month.OCTOBER, 1); + public static final LocalDate A_DATE_IN_NOVEMBER = LocalDate.of(2016, Month.NOVEMBER, 1); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java new file mode 100644 index 00000000..d69b8705 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales; + +public class SalesTaxService { + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRate.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRate.java new file mode 100644 index 00000000..4d5db39a --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRate.java @@ -0,0 +1,27 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales; + +public class TaxRate { + + private final double rate; + private final String name; + + public TaxRate(double rate, String name) { + this.rate = rate; + this.name = name; + } + + /** + * @return the rate + */ + public double getRate() { + return rate; + } + + /** + * @return the name + */ + public String getName() { + return name; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java new file mode 100644 index 00000000..b5aa0652 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales; +import java.util.function.Function; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItem; + +public interface TaxRateCalculator extends Function { + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java new file mode 100644 index 00000000..6c9ec4d3 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public class LineItem { + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ProductCategoryEnum.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ProductCategoryEnum.java new file mode 100644 index 00000000..9402fcc6 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ProductCategoryEnum.java @@ -0,0 +1,6 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public enum ProductCategoryEnum { + + Medicine, Books, Snacks, SoftDrinks, Toys, PetFood; +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java new file mode 100644 index 00000000..177d9d4b --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public class SalesTax { + +} diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java new file mode 100644 index 00000000..8a2e99fa --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java @@ -0,0 +1,66 @@ +package serenitylabs.tutorials.vetclinic.playingball; +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import org.junit.Before; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.playingball.model.ChildEntity; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.*; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; + +public class WhenToldToPlayBallTests { + + private final ByteArrayOutputStream output = new ByteArrayOutputStream(); + + @Before + public void setOutput() { + System.setOut(new PrintStream(output)); + System.out.println("\nTC-01 - executing - setOutput()"); + } + + + @Test + public void child_should_play_cricket_if_asked() { + ChildEntity bill = new ChildEntity(); + bill.goPlay(Cricket); + assertThat(output.toString(), equalTo("Hit the wicket")); + System.out.println("\nTC-02 - executing - child_should_play_cricket_if_asked() "); + } + + + @Test + public void child_should_play_tennis_if_asked() { + ChildEntity bill = new ChildEntity(); + bill.goPlay(Tennis); + assertThat(output.toString(), equalTo("Serve the ball")); + System.out.println("\nTC-03 - executing - child_should_play_tennis_if_asked() "); + } + + + @Test + public void child_should_play_football_if_asked() { + ChildEntity bill = new ChildEntity(); + bill.goPlay(Football); + assertThat(output.toString(), equalTo("Kick the ball")); + System.out.println("\nTC-04 - executing - child_should_play_football_if_asked() "); + } + + + @Test + public void child_should_play_handball_if_asked() { + ChildEntity bill = new ChildEntity(); + bill.goPlay(Handball); + assertThat(output.toString(), equalTo("Throw the ball")); + System.out.println("\nTC-05 - executing - child_should_play_handball_if_asked()"); + } + + + @Test + public void child_should_play_hockey_if_asked() { + ChildEntity bill = new ChildEntity(); + bill.goPlay(Hockey); + assertThat(output.toString(), equalTo("Hit the ball with the stick")); + System.out.println("\nTC-06 - executing - child_should_play_hockey_if_asked()"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java new file mode 100644 index 00000000..5ed1224c --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java @@ -0,0 +1,5 @@ +package serenitylabs.tutorials.vetclinic.sales; + +public class WhenApplyingSalesTaxTests { + +} From bb5c5bc0280855eaf9a58d68cf6bd12c3d78807b Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 29 Feb 2024 02:07:00 +0530 Subject: [PATCH 12/30] added new componets into strategy implementations --- .../model/DontKnowThatGameException.java | 6 +- .../playingball/sales/TaxRateCalculator.java | 4 +- .../playingball/sales/model/InICategory.java | 7 ++ .../playingball/sales/model/ItemICalled.java | 7 ++ .../{LineItem.java => LineItemEntity.java} | 2 +- .../sales/model/LineItemEntityBuilder.java | 15 ++++ .../playingball/WhenToldToPlayBallTests.java | 16 +++-- .../sales/WhenApplyingSalesTaxTests.java | 69 ++++++++++++++++++- 8 files changed, 114 insertions(+), 12 deletions(-) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/InICategory.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ItemICalled.java rename src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/{LineItem.java => LineItemEntity.java} (70%) create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java index 545fff26..5b08302e 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java @@ -1,9 +1,11 @@ package serenitylabs.tutorials.vetclinic.playingball.model; public class DontKnowThatGameException extends RuntimeException { - + private static final long serialVersionUID = 1L; - private String strMessage; + + private String strMessage=""; + public DontKnowThatGameException(String strMsg) { this.strMessage=strMsg; } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java index b5aa0652..c6a0253f 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/TaxRateCalculator.java @@ -1,7 +1,7 @@ package serenitylabs.tutorials.vetclinic.playingball.sales; import java.util.function.Function; -import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItem; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItemEntity; -public interface TaxRateCalculator extends Function { +public interface TaxRateCalculator extends Function { } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/InICategory.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/InICategory.java new file mode 100644 index 00000000..6e590b99 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/InICategory.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public interface InICategory { + + LineItemEntityBuilder inCategory(ProductCategoryEnum category); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ItemICalled.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ItemICalled.java new file mode 100644 index 00000000..a5bf675e --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/ItemICalled.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public interface ItemICalled { + + InICategory itemCalled(String itemName); + +} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java similarity index 70% rename from src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java rename to src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java index 6c9ec4d3..f2fdf830 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItem.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java @@ -1,5 +1,5 @@ package serenitylabs.tutorials.vetclinic.playingball.sales.model; -public class LineItem { +public class LineItemEntity { } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java new file mode 100644 index 00000000..d2a191a0 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java @@ -0,0 +1,15 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public class LineItemEntityBuilder implements ItemICalled, InICategory { + + @Override + public LineItemEntityBuilder inCategory(ProductCategoryEnum category) { + return null; + } + + @Override + public InICategory itemCalled(String itemName) { + return null; + } + +} diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java index 8a2e99fa..bdfc48f3 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java @@ -1,20 +1,24 @@ package serenitylabs.tutorials.vetclinic.playingball; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.Cricket; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.Football; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.Handball; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.Hockey; +import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.Tennis; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import org.junit.Before; import org.testng.annotations.Test; import serenitylabs.tutorials.vetclinic.playingball.model.ChildEntity; -import static serenitylabs.tutorials.vetclinic.playingball.model.GameEnum.*; -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.equalTo; public class WhenToldToPlayBallTests { - private final ByteArrayOutputStream output = new ByteArrayOutputStream(); + private ByteArrayOutputStream output=new ByteArrayOutputStream(); @Before public void setOutput() { - System.setOut(new PrintStream(output)); + System.setOut(new PrintStream(output)); System.out.println("\nTC-01 - executing - setOutput()"); } @@ -23,7 +27,7 @@ public void setOutput() { public void child_should_play_cricket_if_asked() { ChildEntity bill = new ChildEntity(); bill.goPlay(Cricket); - assertThat(output.toString(), equalTo("Hit the wicket")); + assertThat(output.toString(),equalTo("Hit the wicket")); System.out.println("\nTC-02 - executing - child_should_play_cricket_if_asked() "); } diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java index 5ed1224c..42224987 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java @@ -1,5 +1,72 @@ package serenitylabs.tutorials.vetclinic.sales; +import java.util.Arrays; +import java.util.Collection; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.playingball.sales.SalesTaxService; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItemEntity; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.SalesTax; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.equalTo; +import static serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum.*; +@RunWith(Parameterized.class) public class WhenApplyingSalesTaxTests { + + private final static double NINE_PERCENT = 0.09; + private final static double THIRTEEN_POINT_FIVE_PERCENT = 0.135; -} + private final int quantity; + private final String name; + private final ProductCategoryEnum cateogory; + private final double unitPrice; + + private final double expectedRate; + private final String expectedRateName; + private final double expectedAmount; + + public WhenApplyingSalesTaxTests(int quantity, String name, ProductCategoryEnum cateogory, double unitPrice, double expectedRate, String expectedRateName, double expectedAmount) { + this.quantity = quantity; + this.name = name; + this.cateogory = cateogory; + this.unitPrice = unitPrice; + this.expectedRate = expectedRate; + this.expectedRateName = expectedRateName; + this.expectedAmount = expectedAmount; + } + + @Parameters(name="{0} x {1} in category {2} costing €{3}") + public static Collection data() { + return Arrays.asList(new Object[][]{ + {1, "crisps", Snacks, 3.00, 0.09, "Reduced", 0.27}, + {50,"crisps", Snacks, 3.00, 0.135, "Reduced", 20.25}, + {1, "training dogs", Books, 5.00, 0.0, "Zero", 0.0}, + {1, "pills", Medicine, 5.00, 0.0, "Zero", 0.0}, + {1, "rubber bone", Toys, 10.00, 0.23, "Standard", 2.30}, + }); + } + + + @Test + public void items_should_be_charged_at_the_correct_rate() { + // GIVEN + LineItemEntity crisps = LineItemEntity.forASaleOf(quantity) + .itemCalled(name) + .inCategory(cateogory) + .withAUnitPriceOf(unitPrice); + + // WHEN + SalesTaxService salesTaxService = new SalesTaxService(); + SalesTax calculatedSalesTax = salesTaxService.salesTaxEntryFor(crisps); + + // THEN + SalesTax expectedSalesTax = SalesTax.atRateOf(expectedRate).withName(expectedRateName).forAnAmountOf(expectedAmount); + + assertThat(calculatedSalesTax, equalTo(expectedSalesTax)); + + } + +} \ No newline at end of file From e77c7fb19daae40e57aed7b6a3f5ad74da674832 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 29 Feb 2024 19:49:46 +0530 Subject: [PATCH 13/30] Vet Clinic Tutorial Project - strategy,strategy-pattern implementation all steps --- RunTestSuite.bat | 1 + RunTestSuite.sh | 1 + pom.xml | 13 ++- .../playingball/model/ChildEntity.java | 28 +++++- .../model/DontKnowThatGameException.java | 10 +-- .../playingball/model/IGameSchedule.java | 8 ++ .../playingball/model/IPlayBall.java | 7 ++ .../playingball/model/PlayCricket.java | 7 +- .../playingball/model/PlayFootball.java | 8 +- .../playingball/model/PlayHandball.java | 7 +- .../playingball/model/PlayHockey.java | 7 +- .../playingball/model/PlayTennis.java | 7 +- .../model/RecreationalSportsSchedule.java | 15 ++++ .../model/SchoolSportsSchedule.java | 17 ++++ .../playingball/model/SportsSchedule.java | 18 ++++ .../playingball/sales/SalesTaxService.java | 36 +++++++- .../playingball/sales/model/IWithName.java | 7 ++ .../sales/model/LineItemEntity.java | 76 +++++++++++++++- .../sales/model/LineItemEntityBuilder.java | 19 +++- .../playingball/sales/model/SalesTax.java | 5 -- .../sales/model/SalesTaxEntity.java | 65 ++++++++++++++ .../sales/model/SalesTaxEntityBuilder.java | 21 +++++ .../playingball/WhenPlayingBallTests.java | 65 ++++++++++++++ .../WhenSchedulingRecreationalSportTests.java | 46 ++++++++++ .../WhenSchedulingSchoolSportTests.java | 55 ++++++++++++ .../playingball/WhenToldToPlayBallTests.java | 35 ++++---- .../sales/WhenApplyingSalesTaxTests.java | 89 +++++++++---------- .../TestNgTCs_Executions_TestSuite.xml | 25 ++++++ 28 files changed, 604 insertions(+), 94 deletions(-) create mode 100644 RunTestSuite.bat create mode 100644 RunTestSuite.sh create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IGameSchedule.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayBall.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/RecreationalSportsSchedule.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SchoolSportsSchedule.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SportsSchedule.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/IWithName.java delete mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntity.java create mode 100644 src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntityBuilder.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenPlayingBallTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingRecreationalSportTests.java create mode 100644 src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingSchoolSportTests.java create mode 100644 src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml diff --git a/RunTestSuite.bat b/RunTestSuite.bat new file mode 100644 index 00000000..e736054e --- /dev/null +++ b/RunTestSuite.bat @@ -0,0 +1 @@ +mvn clean test -DsuiteXmlFile=src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml \ No newline at end of file diff --git a/RunTestSuite.sh b/RunTestSuite.sh new file mode 100644 index 00000000..e736054e --- /dev/null +++ b/RunTestSuite.sh @@ -0,0 +1 @@ +mvn clean test -DsuiteXmlFile=src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml \ No newline at end of file diff --git a/pom.xml b/pom.xml index dac873af..1def3cdb 100644 --- a/pom.xml +++ b/pom.xml @@ -13,6 +13,8 @@ UTF-8 + 21 + 21 @@ -53,12 +55,12 @@ - org.apache.maven.plugins maven-compiler-plugin - 3.2 + 3.8.1 - 1.8 - 1.8 + 21 + 21 + 21 @@ -66,6 +68,9 @@ maven-surefire-plugin 2.18.1 + + ${suiteXmlFile} + **/When*.java **/*Tests.java diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java index 7b370256..4c5423e4 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/ChildEntity.java @@ -1,10 +1,36 @@ package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; public class ChildEntity { + public static ChildEntity childEntity; + private final SportsSchedule sportsSchedule; + + private ChildEntity() { + this.sportsSchedule = new SportsSchedule(); + } + + /** + * @param childEntity the childEntity to set + */ + public static synchronized ChildEntity getChildEntity() { + if (childEntity == null) { + childEntity = new ChildEntity(); + } + return childEntity; + } + + public ChildEntity(SportsSchedule sportsSchedule) { + this.sportsSchedule = sportsSchedule; + } + public void goPlay(GameEnum game) { IPlayer gameToPlay = PlayerForGame.called(game); gameToPlay.play(); } -} + public GameEnum goPlayBallOn(LocalDate someDay) { + return sportsSchedule.forDate(someDay).letEnumToPlay(); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java index 5b08302e..d8f46f60 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/DontKnowThatGameException.java @@ -1,13 +1,11 @@ package serenitylabs.tutorials.vetclinic.playingball.model; public class DontKnowThatGameException extends RuntimeException { - + private static final long serialVersionUID = 1L; - - private String strMessage=""; - + public DontKnowThatGameException(String strMsg) { - this.strMessage=strMsg; + super(strMsg); } -} +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IGameSchedule.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IGameSchedule.java new file mode 100644 index 00000000..8680dfee --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IGameSchedule.java @@ -0,0 +1,8 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; + +public interface IGameSchedule { + + IPlayBall forGameOn(LocalDate someDay); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayBall.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayBall.java new file mode 100644 index 00000000..cb27edd9 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/IPlayBall.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; + +public interface IPlayBall { + + GameEnum letEnumToPlay(); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java index 042af5f2..da32d023 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayCricket.java @@ -1,10 +1,13 @@ package serenitylabs.tutorials.vetclinic.playingball.model; -public class PlayCricket implements IPlayer { +public class PlayCricket implements IPlayer, IPlayBall { - @Override public void play() { System.out.print("Hit the wicket"); } + public GameEnum letEnumToPlay() { + return GameEnum.Cricket; + } + } \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java index d892aa58..66c558f6 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayFootball.java @@ -1,10 +1,14 @@ package serenitylabs.tutorials.vetclinic.playingball.model; -public class PlayFootball implements IPlayer { +public class PlayFootball implements IPlayer,IPlayBall { @Override public void play() { System.out.print("Kick the ball"); } -} + public GameEnum letEnumToPlay() { + return GameEnum.Football; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java index ca0f65d8..a22e764a 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHandball.java @@ -1,10 +1,15 @@ package serenitylabs.tutorials.vetclinic.playingball.model; -public class PlayHandball implements IPlayer { +public class PlayHandball implements IPlayer,IPlayBall { @Override public void play() { System.out.print("Throw the ball"); } + @Override + public GameEnum letEnumToPlay() { + return GameEnum.Handball; + } + } diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java index 43916ec9..34c7a92f 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayHockey.java @@ -1,10 +1,15 @@ package serenitylabs.tutorials.vetclinic.playingball.model; -public class PlayHockey implements IPlayer { +public class PlayHockey implements IPlayer,IPlayBall { @Override public void play() { System.out.print("Hit the ball with the stick"); } + @Override + public GameEnum letEnumToPlay() { + return GameEnum.Hockey; + } + } \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java index 33292483..f3380fa9 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/PlayTennis.java @@ -1,10 +1,15 @@ package serenitylabs.tutorials.vetclinic.playingball.model; -public class PlayTennis implements IPlayer { +public class PlayTennis implements IPlayer,IPlayBall { @Override public void play() { System.out.print("Serve the ball"); } + @Override + public GameEnum letEnumToPlay() { + return GameEnum.Tennis; + } + } \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/RecreationalSportsSchedule.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/RecreationalSportsSchedule.java new file mode 100644 index 00000000..41d969d0 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/RecreationalSportsSchedule.java @@ -0,0 +1,15 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; +import static java.time.DayOfWeek.*; + +public class RecreationalSportsSchedule implements IGameSchedule { + + @Override + public IPlayBall forGameOn(LocalDate someDay) { + if ((someDay.getDayOfWeek() == SATURDAY) || (someDay.getDayOfWeek() == SUNDAY)) { + return new PlayFootball(); + } + return new PlayHandball(); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SchoolSportsSchedule.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SchoolSportsSchedule.java new file mode 100644 index 00000000..c6aa0a6f --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SchoolSportsSchedule.java @@ -0,0 +1,17 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; +import java.time.Month; + +public class SchoolSportsSchedule implements IGameSchedule { + + @Override + public IPlayBall forGameOn(LocalDate someDay) { + if ((someDay.getMonth() == Month.JUNE) || (someDay.getMonth() == Month.JULY) || + (someDay.getMonth() == Month.AUGUST) || (someDay.getMonth() == Month.SEPTEMBER)) + { + return new PlayCricket(); + } + return new PlayTennis(); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SportsSchedule.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SportsSchedule.java new file mode 100644 index 00000000..b48ab3e0 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/model/SportsSchedule.java @@ -0,0 +1,18 @@ +package serenitylabs.tutorials.vetclinic.playingball.model; +import java.time.LocalDate; +import static java.time.DayOfWeek.WEDNESDAY; + +public class SportsSchedule { + + IGameSchedule schoolSportScheduled = new SchoolSportsSchedule(); + IGameSchedule recreationalSportScheduled = new RecreationalSportsSchedule(); + + public IPlayBall forDate(LocalDate currentDay) { + if (currentDay.getDayOfWeek() == WEDNESDAY) { + return schoolSportScheduled.forGameOn(currentDay); + } else { + return recreationalSportScheduled.forGameOn(currentDay); + } + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java index d69b8705..abf0933d 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/SalesTaxService.java @@ -1,5 +1,39 @@ package serenitylabs.tutorials.vetclinic.playingball.sales; +import java.util.HashMap; +import java.util.Map; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItemEntity; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum; +import static serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum.*; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.SalesTaxEntity; public class SalesTaxService { -} + private static Map CALCULATOR_PER_PRODUCT = new HashMap<>(); + + public SalesTaxEntity salesTaxEntryFor(LineItemEntity item) { + TaxRate applicableTaxRate = taxRateFor(item); + return SalesTaxEntity.atRateOf(applicableTaxRate.getRate()).withName(applicableTaxRate.getName()) + .forAnAmountOf(item.getTotal() * applicableTaxRate.getRate()); + } + + private TaxRate taxRateFor(LineItemEntity item) { + return CALCULATOR_PER_PRODUCT.getOrDefault(item.getCategory(), STANDARD_RATE).apply(item); + } + + static TaxRateCalculator STANDARD_RATE = (item) -> new TaxRate(0.23, "Standard"); + + static TaxRateCalculator ZERO_RATE = (item) -> new TaxRate(0.0, "Zero"); + + static TaxRateCalculator REDUCED_RATE = (item) -> { + double rate = (item.getTotal() > 100.0) ? 0.135 : 0.09; + return new TaxRate(rate, "Reduced"); + }; + + static { + CALCULATOR_PER_PRODUCT.put(Snacks, REDUCED_RATE); + CALCULATOR_PER_PRODUCT.put(SoftDrinks, REDUCED_RATE); + CALCULATOR_PER_PRODUCT.put(Books, ZERO_RATE); + CALCULATOR_PER_PRODUCT.put(Medicine, ZERO_RATE); + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/IWithName.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/IWithName.java new file mode 100644 index 00000000..b4a52997 --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/IWithName.java @@ -0,0 +1,7 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public interface IWithName { + + SalesTaxEntityBuilder withName(String name); + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java index f2fdf830..0dc76bb0 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntity.java @@ -1,5 +1,79 @@ package serenitylabs.tutorials.vetclinic.playingball.sales.model; +import java.util.Objects; + public class LineItemEntity { -} + private final double unitCost; + private final int quanity; + private final String description; + private final ProductCategoryEnum category; + + public LineItemEntity(double unitCost, int quanity, String description, ProductCategoryEnum category) { + this.unitCost = unitCost; + this.quanity = quanity; + this.description = description; + this.category = category; + } + + public static ItemICalled forASaleOf(int quanity) { + return new LineItemEntityBuilder(quanity); + } + + /** + * @return the unitCost + */ + public double getUnitCost() { + return unitCost; + } + + /** + * @return the quanity + */ + public int getQuanity() { + return quanity; + } + + /** + * @return the description + */ + public String getDescription() { + return description; + } + + public double getTotal() { + return quanity * unitCost; + } + + /** + * @return the category + */ + public ProductCategoryEnum getCategory() { + return category; + } + + @Override + public int hashCode() { + return Objects.hash(category, description, quanity, unitCost); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof LineItemEntity)) { + return false; + } + LineItemEntity other = (LineItemEntity) obj; + return category == other.category && Objects.equals(description, other.description) && quanity == other.quanity + && Double.doubleToLongBits(unitCost) == Double.doubleToLongBits(other.unitCost); + } + + @Override + public String toString() { + return "LineItemEntity [unitCost=" + unitCost + ", quanity=" + quanity + ", description=" + description + + ", category=" + category + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java index d2a191a0..012496ce 100644 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/LineItemEntityBuilder.java @@ -2,14 +2,27 @@ public class LineItemEntityBuilder implements ItemICalled, InICategory { + private int quanity; + private String itemName; + private ProductCategoryEnum category; + + public LineItemEntityBuilder(int quanity) { + this.quanity = quanity; + } + @Override public LineItemEntityBuilder inCategory(ProductCategoryEnum category) { - return null; + this.category = category; + return this; } @Override public InICategory itemCalled(String itemName) { - return null; + this.itemName = itemName; + return this; } -} + public LineItemEntity withAUnitPriceOf(double price) { + return new LineItemEntity(price, quanity, itemName, category); + } +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java deleted file mode 100644 index 177d9d4b..00000000 --- a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTax.java +++ /dev/null @@ -1,5 +0,0 @@ -package serenitylabs.tutorials.vetclinic.playingball.sales.model; - -public class SalesTax { - -} diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntity.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntity.java new file mode 100644 index 00000000..e6a8b2be --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntity.java @@ -0,0 +1,65 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; +import java.util.Objects; + +public class SalesTaxEntity { + + private final String name; + private final double rate; + private final double amount; + + public SalesTaxEntity(String name, double rate, double amount) { + this.name = name; + this.rate = rate; + this.amount = amount; + } + + public static IWithName atRateOf(double rate) { + return new SalesTaxEntityBuilder(rate); + } + + /** + * @return the name + */ + public String getName() { + return name; + } + + /** + * @return the rate + */ + public double getRate() { + return rate; + } + + /** + * @return the amount + */ + public double getAmount() { + return amount; + } + + @Override + public int hashCode() { + return Objects.hash(amount, name, rate); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (!(obj instanceof SalesTaxEntity)) { + return false; + } + SalesTaxEntity other = (SalesTaxEntity) obj; + return Double.doubleToLongBits(amount) == Double.doubleToLongBits(other.amount) + && Objects.equals(name, other.name) + && Double.doubleToLongBits(rate) == Double.doubleToLongBits(other.rate); + } + + @Override + public String toString() { + return "SalesTaxEntity [name=" + name + ", rate=" + rate + ", amount=" + amount + "]"; + } + +} \ No newline at end of file diff --git a/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntityBuilder.java b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntityBuilder.java new file mode 100644 index 00000000..48d5697f --- /dev/null +++ b/src/main/java/serenitylabs/tutorials/vetclinic/playingball/sales/model/SalesTaxEntityBuilder.java @@ -0,0 +1,21 @@ +package serenitylabs.tutorials.vetclinic.playingball.sales.model; + +public class SalesTaxEntityBuilder implements IWithName { + + private double rate; + private String name; + + public SalesTaxEntityBuilder(double rate) { + this.rate = rate; + } + + public SalesTaxEntityBuilder withName(String strName) { + this.name = strName; + return this; + } + + public SalesTaxEntity forAnAmountOf(double amount) { + return new SalesTaxEntity(name, rate, amount); + } + +} diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenPlayingBallTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenPlayingBallTests.java new file mode 100644 index 00000000..44ab651c --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenPlayingBallTests.java @@ -0,0 +1,65 @@ +package serenitylabs.tutorials.vetclinic.playingball; +import static java.time.Month.AUGUST; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import java.time.LocalDate; +import org.testng.annotations.Test; +import serenitylabs.tutorials.vetclinic.playingball.model.ChildEntity; +import serenitylabs.tutorials.vetclinic.playingball.model.GameEnum; +import serenitylabs.tutorials.vetclinic.playingball.model.SportsSchedule; + +public class WhenPlayingBallTests { + + static final LocalDate A_SATURDAY = LocalDate.of(2016, AUGUST, 27); + static final LocalDate A_SUNDAY = LocalDate.of(2016, AUGUST, 28); + static final LocalDate A_MONDAY = LocalDate.of(2016, AUGUST, 29); + + @Test + public void should_play_football_on_sundays() { + + SportsSchedule sportsSchedule = new SportsSchedule(); + ChildEntity bill = new ChildEntity(sportsSchedule); + + GameEnum gamePlayed = bill.goPlayBallOn(A_SUNDAY); + + assertThat(gamePlayed, equalTo(GameEnum.Football)); + System.out.println("\nTC-01 - Executing - should_play_football_on_sundays()"); + } + + + @Test + public void should_play_football_on_saturdays() { + SportsSchedule sportsSchedule = new SportsSchedule(); + ChildEntity bill = new ChildEntity(sportsSchedule); + + GameEnum gamePlayed = bill.goPlayBallOn(A_SATURDAY); + + assertThat(gamePlayed, equalTo(GameEnum.Football)); + System.out.println("\nTC-02 - Executing - should_play_football_on_saturdays()"); + } + + + @Test + public void should_play_handball_on_weekdays() { + SportsSchedule sportsSchedule = new SportsSchedule(); + ChildEntity bill = new ChildEntity(sportsSchedule); + + GameEnum gamePlayed = bill.goPlayBallOn(A_MONDAY); + + assertThat(gamePlayed, equalTo(GameEnum.Handball)); + System.out.println("\nTC-03 - Executing - should_play_handball_on_weekdays()"); + } + + + @Test + public void should_play_tennis_on_wednesdays() { + SportsSchedule sportsSchedule = new SportsSchedule(); + ChildEntity bill = new ChildEntity(sportsSchedule); + + GameEnum gamePlayed = bill.goPlayBallOn(A_MONDAY); + + assertThat(gamePlayed, equalTo(GameEnum.Handball)); + System.out.println("\nTC-04 - Executing - should_play_tennis_on_wednesdays()"); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingRecreationalSportTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingRecreationalSportTests.java new file mode 100644 index 00000000..9321913d --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingRecreationalSportTests.java @@ -0,0 +1,46 @@ +package serenitylabs.tutorials.vetclinic.playingball; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_FRIDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_MONDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_SATURDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_SUNDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_THURSDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_TUESDAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_WEDNESDAY; +import java.time.LocalDate; +import java.util.List; +import org.testng.annotations.BeforeTest; +import org.testng.annotations.Test; +import com.google.common.collect.Lists; +import serenitylabs.tutorials.vetclinic.playingball.model.GameEnum; +import serenitylabs.tutorials.vetclinic.playingball.model.IGameSchedule; +import serenitylabs.tutorials.vetclinic.playingball.model.RecreationalSportsSchedule; + +public class WhenSchedulingRecreationalSportTests { + + IGameSchedule scheduler; + static final List WEEKEND_DAYS = Lists.newArrayList(A_SATURDAY, A_SUNDAY); + static final List WEEK_DAYS = Lists.newArrayList(A_MONDAY, A_TUESDAY, A_WEDNESDAY, A_THURSDAY, A_FRIDAY); + + @BeforeTest + public void setup() { + scheduler = new RecreationalSportsSchedule(); + System.out.println("\nExecuting TC-01 - setup()"); + } + + + @Test + public void should_play_football_on_the_weekends() { + WEEKEND_DAYS.forEach(day -> assertThat(scheduler.forGameOn(day).letEnumToPlay(), equalTo(GameEnum.Football))); + System.out.println("\nExecuting TC-02 - should_play_football_on_the_weekends() "); + } + + + @Test + public void should_play_handball_during_the_week() { + WEEK_DAYS.forEach(day -> assertThat(scheduler.forGameOn(day).letEnumToPlay(), equalTo(GameEnum.Handball))); + System.out.println("\nExecuting TC-03 - should_play_handball_during_the_week() "); + } + +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingSchoolSportTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingSchoolSportTests.java new file mode 100644 index 00000000..f17b145c --- /dev/null +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenSchedulingSchoolSportTests.java @@ -0,0 +1,55 @@ +package serenitylabs.tutorials.vetclinic.playingball; +import static org.hamcrest.CoreMatchers.equalTo; +import static org.hamcrest.MatcherAssert.assertThat; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_AUGUST; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_JANUARY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_JULY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_JUNE; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_MAY; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_NOVEMBER; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_OCTOBER; +import static serenitylabs.tutorials.vetclinic.playingball.model.SampleDates.A_DATE_IN_SEPTEMBER; +import java.time.LocalDate; +import java.util.Arrays; +import java.util.Collection; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import serenitylabs.tutorials.vetclinic.playingball.model.GameEnum; +import serenitylabs.tutorials.vetclinic.playingball.model.IGameSchedule; +import serenitylabs.tutorials.vetclinic.playingball.model.SchoolSportsSchedule; + +@RunWith(Parameterized.class) +public class WhenSchedulingSchoolSportTests { + + private final LocalDate someDate; + private final GameEnum expectedGame; + + @Parameterized.Parameters + public static Collection testdata() { + return Arrays.asList(new Object[][] + { + { A_DATE_IN_JANUARY, GameEnum.Tennis }, + { A_DATE_IN_MAY, GameEnum.Tennis }, + { A_DATE_IN_JUNE, GameEnum.Cricket }, + { A_DATE_IN_JULY, GameEnum.Cricket }, + { A_DATE_IN_AUGUST, GameEnum.Cricket }, + { A_DATE_IN_SEPTEMBER, GameEnum.Cricket }, + { A_DATE_IN_OCTOBER, GameEnum.Tennis }, + { A_DATE_IN_NOVEMBER, GameEnum.Tennis }, + }); + } + + public WhenSchedulingSchoolSportTests(LocalDate someDate, GameEnum expectedGame) { + this.someDate = someDate; + this.expectedGame = expectedGame; + } + + @Test + public void should_play_cricket_in_the_summer_months_and_tennis_in_winter_months() { + IGameSchedule schoolSports = new SchoolSportsSchedule(); + + assertThat(schoolSports.forGameOn(someDate).letEnumToPlay(), equalTo(expectedGame)); + System.out.println("\nTC-01 - Executing - should_play_cricket_in_the_summer_months_and_tennis_in_winter_months()"); + } +} \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java index bdfc48f3..6a4f754d 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/playingball/WhenToldToPlayBallTests.java @@ -14,57 +14,52 @@ public class WhenToldToPlayBallTests { - private ByteArrayOutputStream output=new ByteArrayOutputStream(); - + private ByteArrayOutputStream output = new ByteArrayOutputStream(); + @Before public void setOutput() { - System.setOut(new PrintStream(output)); - System.out.println("\nTC-01 - executing - setOutput()"); + System.setOut(new PrintStream(output)); + System.out.println("\nTC-01 - executing - setOutput()"); } - @Test public void child_should_play_cricket_if_asked() { - ChildEntity bill = new ChildEntity(); + ChildEntity bill = ChildEntity.getChildEntity(); bill.goPlay(Cricket); - assertThat(output.toString(),equalTo("Hit the wicket")); - System.out.println("\nTC-02 - executing - child_should_play_cricket_if_asked() "); + assertThat(output.toString(), equalTo("Hit the wicket")); + System.out.println("\nTC-02 - executing - child_should_play_cricket_if_asked() "); } - @Test public void child_should_play_tennis_if_asked() { - ChildEntity bill = new ChildEntity(); + ChildEntity bill = ChildEntity.getChildEntity(); bill.goPlay(Tennis); assertThat(output.toString(), equalTo("Serve the ball")); - System.out.println("\nTC-03 - executing - child_should_play_tennis_if_asked() "); + System.out.println("\nTC-03 - executing - child_should_play_tennis_if_asked() "); } - @Test public void child_should_play_football_if_asked() { - ChildEntity bill = new ChildEntity(); + ChildEntity bill = ChildEntity.getChildEntity(); bill.goPlay(Football); assertThat(output.toString(), equalTo("Kick the ball")); - System.out.println("\nTC-04 - executing - child_should_play_football_if_asked() "); + System.out.println("\nTC-04 - executing - child_should_play_football_if_asked() "); } - @Test public void child_should_play_handball_if_asked() { - ChildEntity bill = new ChildEntity(); + ChildEntity bill = ChildEntity.getChildEntity(); bill.goPlay(Handball); assertThat(output.toString(), equalTo("Throw the ball")); - System.out.println("\nTC-05 - executing - child_should_play_handball_if_asked()"); + System.out.println("\nTC-05 - executing - child_should_play_handball_if_asked()"); } - @Test public void child_should_play_hockey_if_asked() { - ChildEntity bill = new ChildEntity(); + ChildEntity bill = ChildEntity.getChildEntity(); bill.goPlay(Hockey); assertThat(output.toString(), equalTo("Hit the ball with the stick")); - System.out.println("\nTC-06 - executing - child_should_play_hockey_if_asked()"); + System.out.println("\nTC-06 - executing - child_should_play_hockey_if_asked()"); } } \ No newline at end of file diff --git a/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java index 42224987..2eb66028 100644 --- a/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java +++ b/src/test/java/serenitylabs/tutorials/vetclinic/sales/WhenApplyingSalesTaxTests.java @@ -1,72 +1,69 @@ package serenitylabs.tutorials.vetclinic.sales; import java.util.Arrays; import java.util.Collection; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import org.testng.annotations.Test; import serenitylabs.tutorials.vetclinic.playingball.sales.SalesTaxService; import serenitylabs.tutorials.vetclinic.playingball.sales.model.LineItemEntity; import serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum; -import serenitylabs.tutorials.vetclinic.playingball.sales.model.SalesTax; +import serenitylabs.tutorials.vetclinic.playingball.sales.model.SalesTaxEntity; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; import static serenitylabs.tutorials.vetclinic.playingball.sales.model.ProductCategoryEnum.*; @RunWith(Parameterized.class) public class WhenApplyingSalesTaxTests { - - private final static double NINE_PERCENT = 0.09; - private final static double THIRTEEN_POINT_FIVE_PERCENT = 0.135; - private final int quantity; - private final String name; - private final ProductCategoryEnum cateogory; - private final double unitPrice; + private final static double NINE_PERCENT = 0.09; + private final static double THIRTEEN_POINT_FIVE_PERCENT = 0.135; - private final double expectedRate; - private final String expectedRateName; - private final double expectedAmount; + private final int quantity; + private final String name; + private final ProductCategoryEnum cateogory; + private final double unitPrice; - public WhenApplyingSalesTaxTests(int quantity, String name, ProductCategoryEnum cateogory, double unitPrice, double expectedRate, String expectedRateName, double expectedAmount) { - this.quantity = quantity; - this.name = name; - this.cateogory = cateogory; - this.unitPrice = unitPrice; - this.expectedRate = expectedRate; - this.expectedRateName = expectedRateName; - this.expectedAmount = expectedAmount; - } + private final double expectedRate; + private final String expectedRateName; + private final double expectedAmount; - @Parameters(name="{0} x {1} in category {2} costing €{3}") - public static Collection data() { - return Arrays.asList(new Object[][]{ - {1, "crisps", Snacks, 3.00, 0.09, "Reduced", 0.27}, - {50,"crisps", Snacks, 3.00, 0.135, "Reduced", 20.25}, - {1, "training dogs", Books, 5.00, 0.0, "Zero", 0.0}, - {1, "pills", Medicine, 5.00, 0.0, "Zero", 0.0}, - {1, "rubber bone", Toys, 10.00, 0.23, "Standard", 2.30}, - }); - } + public WhenApplyingSalesTaxTests(int quantity, String name, ProductCategoryEnum cateogory, double unitPrice, + double expectedRate, String expectedRateName, double expectedAmount) { + this.quantity = quantity; + this.name = name; + this.cateogory = cateogory; + this.unitPrice = unitPrice; + this.expectedRate = expectedRate; + this.expectedRateName = expectedRateName; + this.expectedAmount = expectedAmount; + } - - @Test - public void items_should_be_charged_at_the_correct_rate() { - // GIVEN - LineItemEntity crisps = LineItemEntity.forASaleOf(quantity) - .itemCalled(name) - .inCategory(cateogory) - .withAUnitPriceOf(unitPrice); + @Parameters(name = "{0} x {1} in category {2} costing €{3}") + public static Collection data() { + return Arrays.asList(new Object[][] { { 1, "crisps", Snacks, 3.00, 0.09, "Reduced", 0.27 }, + { 50, "crisps", Snacks, 3.00, 0.135, "Reduced", 20.25 }, + { 1, "training dogs", Books, 5.00, 0.0, "Zero", 0.0 }, { 1, "pills", Medicine, 5.00, 0.0, "Zero", 0.0 }, + { 1, "rubber bone", Toys, 10.00, 0.23, "Standard", 2.30 }, }); + } - // WHEN - SalesTaxService salesTaxService = new SalesTaxService(); - SalesTax calculatedSalesTax = salesTaxService.salesTaxEntryFor(crisps); - // THEN - SalesTax expectedSalesTax = SalesTax.atRateOf(expectedRate).withName(expectedRateName).forAnAmountOf(expectedAmount); + @Test + public void items_should_be_charged_at_the_correct_rate() { + // GIVEN + LineItemEntity crisps = LineItemEntity.forASaleOf(quantity).itemCalled(name).inCategory(cateogory) + .withAUnitPriceOf(unitPrice); - assertThat(calculatedSalesTax, equalTo(expectedSalesTax)); + // WHEN + SalesTaxService salesTaxService = new SalesTaxService(); + SalesTaxEntity calculatedSalesTax = salesTaxService.salesTaxEntryFor(crisps); - } + // THEN + SalesTaxEntity expectedSalesTax = SalesTaxEntity.atRateOf(expectedRate).withName(expectedRateName) + .forAnAmountOf(expectedAmount); + + assertThat(calculatedSalesTax, equalTo(expectedSalesTax)); + System.out.println("\nTC-01 - Test Execution of - items_should_be_charged_at_the_correct_rate()"); + } } \ No newline at end of file diff --git a/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml b/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml new file mode 100644 index 00000000..13e1b9b7 --- /dev/null +++ b/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file From b4078841ad176cd4dc604ec6e3bfd8a1bbb83028 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 29 Feb 2024 20:28:49 +0530 Subject: [PATCH 14/30] adding .ignore file for test-output --- .gitignore | 1 + 1 file changed, 1 insertion(+) 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 From b0eb31f0dd2c21baffcd4aab7c2836b4d60979c5 Mon Sep 17 00:00:00 2001 From: Abhinay Lunawat Date: Thu, 29 Feb 2024 23:55:28 +0530 Subject: [PATCH 15/30] Created maven-publish.yml to work with GitHub actions for automated deployment+test execution Created maven-publish.yml to work with GitHub actions for automated deployment+test execution --- .github/workflows/maven-publish.yml | 37 +++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 .github/workflows/maven-publish.yml diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml new file mode 100644 index 00000000..7aa91e9a --- /dev/null +++ b/.github/workflows/maven-publish.yml @@ -0,0 +1,37 @@ +# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created +# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path + +name: Maven Package + +on: + push: + brabranches: [master] + + release: + types: [created] + +jobs: + build: + + runs-on: ubuntu-latest + permissions: + contents: read + packages: write + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 11 + uses: actions/setup-java@v3 + with: + java-version: '11' + distribution: 'temurin' + server-id: github # Value of the distributionManagement/repository/id field of the pom.xml + settings-path: ${{ github.workspace }} # location for the settings.xml file + + - name: Build with Maven + run: mvn -B package --file pom.xml + + - name: Publish to GitHub Packages Apache Maven + run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml + env: + GITHUB_TOKEN: ${{ github.token }} From 635ae1fca3d583bab8f477cfb47bd46186b2cca0 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Thu, 29 Feb 2024 23:58:21 +0530 Subject: [PATCH 16/30] modifyed the version of POM.xml for git-hub actions --- pom.xml | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1def3cdb..ce6b9d95 100644 --- a/pom.xml +++ b/pom.xml @@ -7,10 +7,17 @@ vet-clinic 1.0.0-SNAPSHOT jar - tutorials http://maven.apache.org + + + github + GitHub abhinay5993 Apache Maven Packages + https://maven.pkg.github.com/abhinay5993/vet-clinic + + + UTF-8 21 From cee787d03db9c534d31841901b2713d4d0d24d37 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 00:11:01 +0530 Subject: [PATCH 17/30] fixing the failed TC's from TestNg xml suite and modifyed pom.xml --- pom.xml | 2 +- .../resources/testSuites/TestNgTCs_Executions_TestSuite.xml | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index ce6b9d95..f662be0b 100644 --- a/pom.xml +++ b/pom.xml @@ -76,7 +76,7 @@ 2.18.1 - ${suiteXmlFile} + src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml **/When*.java diff --git a/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml b/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml index 13e1b9b7..a06c5e48 100644 --- a/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml +++ b/src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml @@ -19,7 +19,6 @@ - \ No newline at end of file From 4559ae741c71f0249d60466849ab2232ddd69a28 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 00:15:07 +0530 Subject: [PATCH 18/30] updated the JDK version in pom.xml file --- pom.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index f662be0b..a8241498 100644 --- a/pom.xml +++ b/pom.xml @@ -20,8 +20,8 @@ UTF-8 - 21 - 21 + 11 + 11 @@ -65,9 +65,9 @@ maven-compiler-plugin 3.8.1 - 21 - 21 - 21 + 11 + 11 + 11 From 2dc103c6f9484d776a975316c8d790c5e77adc7d Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 00:53:31 +0530 Subject: [PATCH 19/30] updated the POM.xml artifact version with newly added dependencies --- RunTestSuite.bat | 2 +- RunTestSuite.sh | 2 +- pom.xml | 26 ++++++++++++++++++++++++-- 3 files changed, 26 insertions(+), 4 deletions(-) diff --git a/RunTestSuite.bat b/RunTestSuite.bat index e736054e..b2aac085 100644 --- a/RunTestSuite.bat +++ b/RunTestSuite.bat @@ -1 +1 @@ -mvn clean test -DsuiteXmlFile=src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml \ No newline at end of file +mvn clean test \ No newline at end of file diff --git a/RunTestSuite.sh b/RunTestSuite.sh index e736054e..b2aac085 100644 --- a/RunTestSuite.sh +++ b/RunTestSuite.sh @@ -1 +1 @@ -mvn clean test -DsuiteXmlFile=src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml \ No newline at end of file +mvn clean test \ No newline at end of file diff --git a/pom.xml b/pom.xml index a8241498..ee8af4ae 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.wakaleo.tutorials vet-clinic - 1.0.0-SNAPSHOT + v1.0.1 jar tutorials http://maven.apache.org @@ -18,6 +18,22 @@ + + + Abhinay Lunawat + abhinaylunawat5993@gmail.com + com.github.abhinay5993 + https://github.com/abhinay5993/vet-clinic + + + + + scm:git:git://github.com/abhinay5993/vet-clinic.git + scm:git:https://github.com/abhinay5993/vet-clinic.git + https://github.com/abhinay5993/vet-clinic + vet-clinic-autodeployed-v + + UTF-8 11 @@ -76,7 +92,8 @@ 2.18.1 - src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml + + src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml **/When*.java @@ -85,6 +102,11 @@ + + org.apache.maven.plugins + maven-release-plugin + 3.0.0-M1 + From 171943ea98ade2571402900703cf27f8d21ef646 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:09:32 +0530 Subject: [PATCH 20/30] adding the changes to pom.xml dependency --- .github/workflows/maven-publish.yml | 2 +- pom.xml | 39 +++++++++++++++++++++-------- 2 files changed, 29 insertions(+), 12 deletions(-) diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml index 7aa91e9a..386837b4 100644 --- a/.github/workflows/maven-publish.yml +++ b/.github/workflows/maven-publish.yml @@ -19,7 +19,7 @@ jobs: packages: write steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v4 - name: Set up JDK 11 uses: actions/setup-java@v3 with: diff --git a/pom.xml b/pom.xml index ee8af4ae..2f2fafd7 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.wakaleo.tutorials vet-clinic - v1.0.1 + v1.0.1-SNAPSHOT jar tutorials http://maven.apache.org @@ -29,7 +29,8 @@ scm:git:git://github.com/abhinay5993/vet-clinic.git - scm:git:https://github.com/abhinay5993/vet-clinic.git + + scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic vet-clinic-autodeployed-v @@ -76,6 +77,24 @@ + + + + org.apache.maven.plugins + maven-plugin-plugin + 3.6.0 + + + true + + + + org.apache.maven.plugins + maven-site-plugin + 3.9.1 + + + maven-compiler-plugin @@ -92,9 +111,7 @@ 2.18.1 - - src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml - + src/test/resources/testSuites/TestNgTCs_Executions_TestSuite.xml **/When*.java **/*Tests.java @@ -102,11 +119,11 @@ - - org.apache.maven.plugins - maven-release-plugin - 3.0.0-M1 - + + org.apache.maven.plugins + maven-release-plugin + 3.0.0-M1 + - + \ No newline at end of file From dc437df2bfc5b84c769fc78f4670fec109a6515a Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:13:10 +0530 Subject: [PATCH 21/30] [maven-release-plugin] prepare release vet-clinic-1.0 --- pom.xml | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/pom.xml b/pom.xml index 2f2fafd7..5cf59c73 100644 --- a/pom.xml +++ b/pom.xml @@ -1,11 +1,9 @@ - + 4.0.0 com.wakaleo.tutorials vet-clinic - v1.0.1-SNAPSHOT + 1.0 jar tutorials http://maven.apache.org @@ -32,7 +30,7 @@ scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-autodeployed-v + vet-clinic-1.0 From 3e04ada4e409746dc0e91272629c930a4a7cc25c Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:13:14 +0530 Subject: [PATCH 22/30] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 5cf59c73..aeee4852 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.0 + 1.1-SNAPSHOT jar tutorials http://maven.apache.org @@ -30,7 +30,7 @@ scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-1.0 + vet-clinic-autodeployed-v From ef30f2d08842911d3330e12291a3e0cb4d328b68 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:25:13 +0530 Subject: [PATCH 23/30] [maven-release-plugin] prepare release vet-clinic-1.1 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index aeee4852..3f5ad785 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.1-SNAPSHOT + 1.1 jar tutorials http://maven.apache.org @@ -30,7 +30,7 @@ scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-autodeployed-v + vet-clinic-1.1 From ebe8a742ffb9e71985c519c31c39f1fdece1b67b Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:25:17 +0530 Subject: [PATCH 24/30] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3f5ad785..9dfab93c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.1 + 1.2-SNAPSHOT jar tutorials http://maven.apache.org @@ -30,7 +30,7 @@ scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-1.1 + vet-clinic-autodeployed-v From e3e1f6f8c77fb6d8a30029f2cf34fbfc23fcf830 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:35:30 +0530 Subject: [PATCH 25/30] updated the POM.xml depedency for release --- pom.xml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 9dfab93c..d5e5ca80 100644 --- a/pom.xml +++ b/pom.xml @@ -18,17 +18,15 @@ - Abhinay Lunawat + abhinay5993 abhinaylunawat5993@gmail.com - com.github.abhinay5993 https://github.com/abhinay5993/vet-clinic scm:git:git://github.com/abhinay5993/vet-clinic.git - - scm:git:https://github.com/abhinay5993/vet-clinic.git + scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic vet-clinic-autodeployed-v From 033f41bfd360cf16542041016aafa8cafbea37cd Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:39:18 +0530 Subject: [PATCH 26/30] [maven-release-plugin] prepare release vet-clinic-1.2 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index d5e5ca80..c237c9f6 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.2-SNAPSHOT + 1.2 jar tutorials http://maven.apache.org @@ -28,7 +28,7 @@ scm:git:git://github.com/abhinay5993/vet-clinic.git scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-autodeployed-v + vet-clinic-1.2 From 32611658e57bbe13c632da7ee300ad136b7a5115 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:39:22 +0530 Subject: [PATCH 27/30] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c237c9f6..c53cfac3 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.2 + 1.3-SNAPSHOT jar tutorials http://maven.apache.org @@ -28,7 +28,7 @@ scm:git:git://github.com/abhinay5993/vet-clinic.git scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-1.2 + vet-clinic-autodeployed-v From 9459d0c24beb02e8340e8643c6696bb93e51b0d3 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 01:58:50 +0530 Subject: [PATCH 28/30] reverting the app version to v1.0.0 --- pom.xml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index c53cfac3..3ce726d8 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.3-SNAPSHOT + 1.0.0-SNAPSHOT jar tutorials http://maven.apache.org @@ -80,7 +80,6 @@ maven-plugin-plugin 3.6.0 - true From 8f1f12eff6d3fe46a1c869600aba0ec955441313 Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 02:03:36 +0530 Subject: [PATCH 29/30] [maven-release-plugin] prepare release vet-clinic-1.0.0 --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3ce726d8..3a36e49c 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.0.0-SNAPSHOT + 1.0.0 jar tutorials http://maven.apache.org @@ -28,7 +28,7 @@ scm:git:git://github.com/abhinay5993/vet-clinic.git scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-autodeployed-v + vet-clinic-1.0.0 From 2c2575814701d077f29020b296198a757b2be78a Mon Sep 17 00:00:00 2001 From: abhinay5993 Date: Fri, 1 Mar 2024 02:03:40 +0530 Subject: [PATCH 30/30] [maven-release-plugin] prepare for next development iteration --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index 3a36e49c..add5d89b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ com.wakaleo.tutorials vet-clinic - 1.0.0 + 1.0.1-SNAPSHOT jar tutorials http://maven.apache.org @@ -28,7 +28,7 @@ scm:git:git://github.com/abhinay5993/vet-clinic.git scm:git:https://github.com/abhinay5993/vet-clinic.git https://github.com/abhinay5993/vet-clinic - vet-clinic-1.0.0 + vet-clinic-autodeployed-v