From cdd802eeee36f8083580a6cd0368b007cb4a0bad Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Wed, 21 Feb 2018 10:48:01 +0100 Subject: [PATCH 01/12] Update webjars-locator dependency --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index bdb939f31..a68944300 100644 --- a/pom.xml +++ b/pom.xml @@ -84,7 +84,7 @@ org.webjars - webjars-locator + webjars-locator-core org.webjars From a52cbe93a25dce015be5d63a17988bdfa0aeb992 Mon Sep 17 00:00:00 2001 From: Dave Syer Date: Wed, 21 Feb 2018 09:09:48 +0000 Subject: [PATCH 02/12] Add ignores for vscode --- .gitignore | 6 ++++++ .vscode/launch.json | 26 ++++++++++++++++++++++++++ .vscode/settings.json | 3 +++ .vscode/tasks.json | 19 +++++++++++++++++++ 4 files changed, 54 insertions(+) create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 100644 .vscode/tasks.json diff --git a/.gitignore b/.gitignore index b00af803d..8cdbd1ff4 100644 --- a/.gitignore +++ b/.gitignore @@ -5,4 +5,10 @@ target/* .idea *.iml /target +.sts4-cache/ +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json _site/ diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..559c53805 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,26 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "type": "java", + "name": "Debug (Launch)-PetClinicApplication", + "request": "launch", + "cwd": "${workspaceFolder}", + "console": "internalConsole", + "stopOnEntry": false, + "mainClass": "org.springframework.samples.petclinic.PetClinicApplication", + "projectName": "spring-petclinic", + "args": "" + }, + { + "type": "java", + "name": "Debug (Attach)", + "request": "attach", + "hostName": "localhost", + "port": 0 + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 000000000..c5f3f6b9c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "java.configuration.updateBuildConfiguration": "interactive" +} \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 000000000..fabd5c416 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,19 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "verify", + "type": "shell", + "command": "mvn -B verify", + "group": "build" + }, + { + "label": "test", + "type": "shell", + "command": "mvn -B test", + "group": "test" + } + ] +} From c5abf45cbc78ca997a1a5934673b93077ca4e907 Mon Sep 17 00:00:00 2001 From: Ray Tsang Date: Mon, 5 Feb 2018 19:19:38 +0100 Subject: [PATCH 03/12] Fix datasource initialization property Closes gh-301 --- src/main/resources/application-mysql.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/resources/application-mysql.properties b/src/main/resources/application-mysql.properties index fd561fa90..c2c654fe4 100644 --- a/src/main/resources/application-mysql.properties +++ b/src/main/resources/application-mysql.properties @@ -3,5 +3,5 @@ database=mysql spring.datasource.url=jdbc:mysql://localhost/test spring.datasource.username=root spring.datasource.password=root - # Uncomment this the first time the app runs -# spring.datasource.initialize=true \ No newline at end of file +# Uncomment this the first time the app runs +# spring.datasource.initialization-mode=always From dfcd30be601439c933785456a5551578467b9573 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 22 Feb 2018 10:46:09 +0100 Subject: [PATCH 04/12] Fix project's version --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index a68944300..fe07d59b6 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ 4.0.0 org.springframework.samples spring-petclinic - 2.0.0 + 2.0.0.BUILD-SNAPSHOT org.springframework.boot From 106226929b527c27359b0215bc2569121cd80401 Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Thu, 22 Feb 2018 10:57:12 +0100 Subject: [PATCH 05/12] Fix actuator exposure --- src/main/resources/application.properties | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index ed5392afe..c8d5a5c1a 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -14,8 +14,7 @@ spring.messages.basename=messages/messages # Actuator / Management management.endpoints.web.base-path=/manage -# Spring Boot 1.5 makes actuator secure by default -management.endpoints.web.enabled=true +management.endpoints.web.exposure.include=* # Logging logging.level.org.springframework=INFO From 0d847edfdb6447c45e98205a102980f7e3a9c4ea Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Sat, 4 Nov 2017 11:59:48 +0100 Subject: [PATCH 06/12] Add spring-petclinic-rest URL Closes gh-278 --- readme.md | 1 + 1 file changed, 1 insertion(+) diff --git a/readme.md b/readme.md index 3f4c376ec..78e4ac828 100644 --- a/readme.md +++ b/readme.md @@ -117,3 +117,4 @@ The Spring PetClinic sample application is released under version 2.0 of the [Ap [spring-petclinic-reactjs]: https://github.com/spring-petclinic/spring-petclinic-reactjs [spring-petclinic-graphql]: https://github.com/spring-petclinic/spring-petclinic-graphql [spring-petclinic-kotlin]: https://github.com/spring-petclinic/spring-petclinic-kotlin +[spring-petclinic-rest]: https://github.com/spring-petclinic/spring-petclinic-rest From d92a4218dd6678261f17b4b8a3ab0838d6241ea1 Mon Sep 17 00:00:00 2001 From: Antoine Rey Date: Thu, 15 Feb 2018 17:44:48 +0100 Subject: [PATCH 07/12] Add placeholder YYYY-MM-DD for date input field Closes gh-303 --- src/main/resources/templates/fragments/inputField.html | 10 +++++++--- .../templates/owners/createOrUpdateOwnerForm.html | 10 +++++----- .../templates/pets/createOrUpdatePetForm.html | 4 ++-- .../templates/pets/createOrUpdateVisitForm.html | 4 ++-- 4 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/main/resources/templates/fragments/inputField.html b/src/main/resources/templates/fragments/inputField.html index 7cef1ee9e..c3373bea0 100644 --- a/src/main/resources/templates/fragments/inputField.html +++ b/src/main/resources/templates/fragments/inputField.html @@ -1,14 +1,18 @@
- +
- +
+ + +
diff --git a/src/main/resources/templates/owners/createOrUpdateOwnerForm.html b/src/main/resources/templates/owners/createOrUpdateOwnerForm.html index a34a39c7f..ca22d9de1 100644 --- a/src/main/resources/templates/owners/createOrUpdateOwnerForm.html +++ b/src/main/resources/templates/owners/createOrUpdateOwnerForm.html @@ -7,15 +7,15 @@
+ th:replace="~{fragments/inputField :: input ('First Name', 'firstName', 'text')}" /> + th:replace="~{fragments/inputField :: input ('Last Name', 'lastName', 'text')}" /> + th:replace="~{fragments/inputField :: input ('Address', 'address', 'text')}" /> + th:replace="~{fragments/inputField :: input ('City', 'city', 'text')}" /> + th:replace="~{fragments/inputField :: input ('Telephone', 'telephone', 'text')}" />
diff --git a/src/main/resources/templates/pets/createOrUpdatePetForm.html b/src/main/resources/templates/pets/createOrUpdatePetForm.html index e4726e155..a0c182aa5 100644 --- a/src/main/resources/templates/pets/createOrUpdatePetForm.html +++ b/src/main/resources/templates/pets/createOrUpdatePetForm.html @@ -17,9 +17,9 @@
+ th:replace="~{fragments/inputField :: input ('Name', 'name', 'text')}" /> + th:replace="~{fragments/inputField :: input ('Birth Date', 'birthDate', 'date')}" />
diff --git a/src/main/resources/templates/pets/createOrUpdateVisitForm.html b/src/main/resources/templates/pets/createOrUpdateVisitForm.html index 26a71378f..4401d36ce 100644 --- a/src/main/resources/templates/pets/createOrUpdateVisitForm.html +++ b/src/main/resources/templates/pets/createOrUpdateVisitForm.html @@ -31,9 +31,9 @@
+ th:replace="~{fragments/inputField :: input ('Date', 'date', 'date')}" /> + th:replace="~{fragments/inputField :: input ('Description', 'description', 'text')}" />
From 38121c46457f2f368ba1b2d8e6e6cd7bd6f1cb11 Mon Sep 17 00:00:00 2001 From: Jad Malek Date: Fri, 23 Feb 2018 12:52:10 -0500 Subject: [PATCH 08/12] [TEST] Added tests for all the methods in the Pet.java (they were all mainly getters and setters). Will attempt to add more tests for this class or others. --- src/main/resources/application.properties | 3 + .../samples/petclinic/owner/PetTests.java | 81 +++++++++++++++++++ .../system/ProductionConfigurationTests.java | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 src/test/java/org/springframework/samples/petclinic/owner/PetTests.java diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index c8d5a5c1a..300538118 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -23,3 +23,6 @@ logging.level.org.springframework=INFO # Active Spring profiles spring.profiles.active=production + +# Adjusting local host to 8090 for application launch +server.port = 8090 diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java new file mode 100644 index 000000000..2c7ac15f4 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java @@ -0,0 +1,81 @@ +package org.springframework.samples.petclinic.owner; + +import static org.junit.Assert.*; +import org.junit.Before; +import org.junit.Test; +import org.springframework.samples.petclinic.visit.Visit; + +import java.util.List; +import java.util.Set; +import java.util.LinkedHashSet; +import java.time.*; +import java.util.Date; + +public class PetTests { + + private Pet pet; + private Date birthDate; + + private void establishCurrentDateForTesting() { + LocalDateTime timePoint = LocalDateTime.now(); + LocalDate localDate = timePoint.toLocalDate(); + birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + } + + @Before + public void testSetUp() { + this.pet = new Pet(); + PetType dog = new PetType(); + dog.setId(9); + dog.setName("Duncan Jones"); + } + + @Test + public void testSetAndGetBirthDate() { + //Converting the current time to a local date and ultimately a date to be input into setBirthDate + this.establishCurrentDateForTesting(); + pet.setBirthDate(this.birthDate); + Date resultOfGetDate = pet.getBirthDate(); + assertEquals(this.birthDate, resultOfGetDate); + } + + @Test + public void testSetAndGetType() { + //Creating a new pet type to test the setters and getters for pet's type + PetType walrus = new PetType(); + walrus.setId(36); + walrus.setName("Alex Garland"); + pet.setType(walrus); + PetType resultOfGetType = pet.getType(); + assertEquals(walrus, resultOfGetType); + } + + @Test + public void testSetAndGetOwner() { + //Creating a new owner type to test the setters and getters for the pet's owner + Owner amandeepBhandal = new Owner(); + pet.setOwner(amandeepBhandal); + Owner resultOfGetOwner = pet.getOwner(); + assertEquals(amandeepBhandal, resultOfGetOwner); + } + + @Test + public void testSetAndGetVisitsInternal() { + //Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits + Set visitsForTesting = new LinkedHashSet<>(); + pet.setVisitsInternal(visitsForTesting); + Set resultOfGetVisitsInternal = pet.getVisitsInternal(); + assertEquals(visitsForTesting, resultOfGetVisitsInternal); + } + + @Test + public void testAddVisitAndGetVisits() { + //Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits + Visit visitForTesting = new Visit(); + pet.addVisit(visitForTesting); + List resultOfGetVisits = pet.getVisits(); + Visit onlyVisitInCollection = resultOfGetVisits.iterator().next(); + assertEquals(1, resultOfGetVisits.size()); + assertEquals(visitForTesting, onlyVisitInCollection); + } +} \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java index 9636e3623..d247d178e 100644 --- a/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java +++ b/src/test/java/org/springframework/samples/petclinic/system/ProductionConfigurationTests.java @@ -14,7 +14,7 @@ public class ProductionConfigurationTests { @Autowired private VetRepository vets; - + //Test error introduced by addition of 10 commits since forking of our repo from original repo @Test public void testFindAll() throws Exception { vets.findAll(); From 6fbaa583cb108f15ccb7f6d09af71fa69ac8d922 Mon Sep 17 00:00:00 2001 From: Jad Malek Date: Fri, 23 Feb 2018 14:26:59 -0500 Subject: [PATCH 09/12] [TEST] Added tests for the PetValidator.java class. These tests will ensure that the proper validation of name, type and birthDate by testing valid and invalid parameter inputs. --- .../petclinic/owner/PetValidatorTests.java | 112 ++++++++++++++++++ 1 file changed, 112 insertions(+) create mode 100644 src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java new file mode 100644 index 000000000..7551b3e62 --- /dev/null +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java @@ -0,0 +1,112 @@ +package org.springframework.samples.petclinic.owner; +import static org.junit.Assert.*; + +import java.time.LocalDate; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; + +import org.junit.Test; +import org.springframework.validation.BeanPropertyBindingResult; +import org.springframework.validation.Errors; + +public class PetValidatorTests { + + @Test + public void testValidationWithValidName() { + //given + PetValidator petValidator = new PetValidator(); + Pet validPet = new Pet(); + validPet.setName("Peter"); + Errors errors = new BeanPropertyBindingResult(validPet, ""); + + //when + petValidator.validate(validPet, errors); + + //then + assertNull(errors.getFieldError("name")); + } + + @Test + public void testValidationWithInvalidName() { + //given + PetValidator petValidator = new PetValidator(); + Pet invalidPet = new Pet(); + invalidPet.setName(""); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + + //when + petValidator.validate(invalidPet, errors); + + //then + assertTrue(errors.hasErrors()); + } + + @Test + public void testValidationWithValidType() { + //given + PetValidator petValidator = new PetValidator(); + Pet validPet = new Pet(); + PetType tiger = new PetType(); + tiger.setId(24); + validPet.setType(tiger); + Errors errors = new BeanPropertyBindingResult(validPet, ""); + + //when + petValidator.validate(validPet, errors); + + //then + assertNull(errors.getFieldError("type")); + } + + @Test + public void testValidationWithInvalidType() { + //given + PetValidator petValidator = new PetValidator(); + Pet invalidPet = new Pet(); + PetType emptyType = null; + invalidPet.setType(emptyType); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + + //when + petValidator.validate(invalidPet, errors); + + //then + assertTrue(errors.hasErrors()); + } + + @Test + public void testValidationWithValidBirthDate() { + //given + PetValidator petValidator = new PetValidator(); + Pet validPet = new Pet(); + LocalDateTime timePoint = LocalDateTime.now(); + LocalDate localDate = timePoint.toLocalDate(); + Date birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); + validPet.setBirthDate(birthDate); + Errors errors = new BeanPropertyBindingResult(validPet, ""); + + //when + petValidator.validate(validPet, errors); + + //then + assertNull(errors.getFieldError("birthDate")); + } + + @Test + public void testValidationWithInvalidBirthDate() { + //given + PetValidator petValidator = new PetValidator(); + Pet invalidPet = new Pet(); + Date birthDate = null; + invalidPet.setBirthDate(birthDate); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + + //when + petValidator.validate(invalidPet, errors); + + //then + assertTrue(errors.hasErrors()); + } +} + From 36d98e594971dd6118a4258f9b09a38b736eb198 Mon Sep 17 00:00:00 2001 From: Jad Malek Date: Sat, 24 Feb 2018 16:58:23 -0500 Subject: [PATCH 10/12] [FIX] Adjusted some of the code formatting and an assertEquals in the PetTests. Also, attempted to mock out the storage dependency purely for testing; however, since isolating the core application's spring-based use of db was more difficult than expected; the code was removed. --- .../samples/petclinic/owner/PetTests.java | 20 ++-- .../petclinic/owner/PetValidatorTests.java | 104 +++++++++--------- 2 files changed, 62 insertions(+), 62 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java index 2c7ac15f4..c2388d0b7 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java @@ -12,22 +12,22 @@ import java.time.*; import java.util.Date; public class PetTests { - + private Pet pet; private Date birthDate; - + private void establishCurrentDateForTesting() { LocalDateTime timePoint = LocalDateTime.now(); LocalDate localDate = timePoint.toLocalDate(); birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } - + @Before public void testSetUp() { this.pet = new Pet(); PetType dog = new PetType(); - dog.setId(9); - dog.setName("Duncan Jones"); + dog.setId(9); + dog.setName("Duncan Jones"); } @Test @@ -38,7 +38,7 @@ public class PetTests { Date resultOfGetDate = pet.getBirthDate(); assertEquals(this.birthDate, resultOfGetDate); } - + @Test public void testSetAndGetType() { //Creating a new pet type to test the setters and getters for pet's type @@ -49,7 +49,7 @@ public class PetTests { PetType resultOfGetType = pet.getType(); assertEquals(walrus, resultOfGetType); } - + @Test public void testSetAndGetOwner() { //Creating a new owner type to test the setters and getters for the pet's owner @@ -58,7 +58,7 @@ public class PetTests { Owner resultOfGetOwner = pet.getOwner(); assertEquals(amandeepBhandal, resultOfGetOwner); } - + @Test public void testSetAndGetVisitsInternal() { //Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits @@ -67,7 +67,7 @@ public class PetTests { Set resultOfGetVisitsInternal = pet.getVisitsInternal(); assertEquals(visitsForTesting, resultOfGetVisitsInternal); } - + @Test public void testAddVisitAndGetVisits() { //Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits @@ -76,6 +76,6 @@ public class PetTests { List resultOfGetVisits = pet.getVisits(); Visit onlyVisitInCollection = resultOfGetVisits.iterator().next(); assertEquals(1, resultOfGetVisits.size()); - assertEquals(visitForTesting, onlyVisitInCollection); + assertEquals(visitForTesting.getId(), onlyVisitInCollection.getId()); } } \ No newline at end of file diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java index 7551b3e62..220429ed8 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetValidatorTests.java @@ -16,97 +16,97 @@ public class PetValidatorTests { public void testValidationWithValidName() { //given PetValidator petValidator = new PetValidator(); - Pet validPet = new Pet(); - validPet.setName("Peter"); - Errors errors = new BeanPropertyBindingResult(validPet, ""); + Pet validPet = new Pet(); + validPet.setName("Peter"); + Errors errors = new BeanPropertyBindingResult(validPet, ""); - //when - petValidator.validate(validPet, errors); + //when + petValidator.validate(validPet, errors); - //then - assertNull(errors.getFieldError("name")); + //then + assertNull(errors.getFieldError("name")); } - + @Test public void testValidationWithInvalidName() { //given PetValidator petValidator = new PetValidator(); - Pet invalidPet = new Pet(); - invalidPet.setName(""); - Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + Pet invalidPet = new Pet(); + invalidPet.setName(""); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); - //when - petValidator.validate(invalidPet, errors); + //when + petValidator.validate(invalidPet, errors); - //then - assertTrue(errors.hasErrors()); + //then + assertTrue(errors.hasErrors()); } - + @Test public void testValidationWithValidType() { - //given + //given PetValidator petValidator = new PetValidator(); - Pet validPet = new Pet(); - PetType tiger = new PetType(); + Pet validPet = new Pet(); + PetType tiger = new PetType(); tiger.setId(24); validPet.setType(tiger); - Errors errors = new BeanPropertyBindingResult(validPet, ""); + Errors errors = new BeanPropertyBindingResult(validPet, ""); - //when - petValidator.validate(validPet, errors); + //when + petValidator.validate(validPet, errors); - //then - assertNull(errors.getFieldError("type")); + //then + assertNull(errors.getFieldError("type")); } - + @Test public void testValidationWithInvalidType() { - //given + //given PetValidator petValidator = new PetValidator(); - Pet invalidPet = new Pet(); - PetType emptyType = null; + Pet invalidPet = new Pet(); + PetType emptyType = null; invalidPet.setType(emptyType); - Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); - //when - petValidator.validate(invalidPet, errors); + //when + petValidator.validate(invalidPet, errors); - //then - assertTrue(errors.hasErrors()); + //then + assertTrue(errors.hasErrors()); } - + @Test public void testValidationWithValidBirthDate() { - //given + //given PetValidator petValidator = new PetValidator(); - Pet validPet = new Pet(); - LocalDateTime timePoint = LocalDateTime.now(); + Pet validPet = new Pet(); + LocalDateTime timePoint = LocalDateTime.now(); LocalDate localDate = timePoint.toLocalDate(); Date birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); - validPet.setBirthDate(birthDate); - Errors errors = new BeanPropertyBindingResult(validPet, ""); + validPet.setBirthDate(birthDate); + Errors errors = new BeanPropertyBindingResult(validPet, ""); - //when - petValidator.validate(validPet, errors); + //when + petValidator.validate(validPet, errors); - //then - assertNull(errors.getFieldError("birthDate")); + //then + assertNull(errors.getFieldError("birthDate")); } - + @Test public void testValidationWithInvalidBirthDate() { - //given + //given PetValidator petValidator = new PetValidator(); - Pet invalidPet = new Pet(); + Pet invalidPet = new Pet(); Date birthDate = null; - invalidPet.setBirthDate(birthDate); - Errors errors = new BeanPropertyBindingResult(invalidPet, ""); + invalidPet.setBirthDate(birthDate); + Errors errors = new BeanPropertyBindingResult(invalidPet, ""); - //when - petValidator.validate(invalidPet, errors); + //when + petValidator.validate(invalidPet, errors); - //then - assertTrue(errors.hasErrors()); + //then + assertTrue(errors.hasErrors()); } } From b6d3dd1c117abd177a567517068c235b7e95cbba Mon Sep 17 00:00:00 2001 From: Jad Malek Date: Sat, 24 Feb 2018 17:11:11 -0500 Subject: [PATCH 11/12] [FIX] Further adjusted the assertEquals in PetTests to better compare the two parameters (as pointed out by @amawai) --- .../springframework/samples/petclinic/owner/PetTests.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java index c2388d0b7..c4af2f534 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java @@ -47,7 +47,7 @@ public class PetTests { walrus.setName("Alex Garland"); pet.setType(walrus); PetType resultOfGetType = pet.getType(); - assertEquals(walrus, resultOfGetType); + assertEquals(walrus.getName(), resultOfGetType.getName()); } @Test @@ -56,7 +56,7 @@ public class PetTests { Owner amandeepBhandal = new Owner(); pet.setOwner(amandeepBhandal); Owner resultOfGetOwner = pet.getOwner(); - assertEquals(amandeepBhandal, resultOfGetOwner); + assertEquals(amandeepBhandal.getAddress(), resultOfGetOwner.getAddress()); } @Test @@ -65,7 +65,7 @@ public class PetTests { Set visitsForTesting = new LinkedHashSet<>(); pet.setVisitsInternal(visitsForTesting); Set resultOfGetVisitsInternal = pet.getVisitsInternal(); - assertEquals(visitsForTesting, resultOfGetVisitsInternal); + assertEquals(visitsForTesting.size(), resultOfGetVisitsInternal.size()); } @Test From 2b1ea2a3d61ced8199a34db644817733b95a681b Mon Sep 17 00:00:00 2001 From: Jad Malek Date: Sat, 24 Feb 2018 23:06:43 -0500 Subject: [PATCH 12/12] [FIX] As per the requested changes, removed the private method for establishing the current date and made it part of the test setup. Also, made the testSetAndGetOwner more comprehensive by checking that each of the attributes particular to the owner were set and retrieved appropriately. --- .../samples/petclinic/owner/PetTests.java | 29 +++++++++++-------- 1 file changed, 17 insertions(+), 12 deletions(-) diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java index c4af2f534..18d0c3b18 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTests.java @@ -16,24 +16,22 @@ public class PetTests { private Pet pet; private Date birthDate; - private void establishCurrentDateForTesting() { + @Before + public void testSetUp() { + //Initialization of pet + this.pet = new Pet(); + PetType dog = new PetType(); + dog.setId(9); + dog.setName("Duncan Jones"); + //Initialization of birthDate + //Converting the current time to a local date and ultimately a date to be input into setBirthDate; LocalDateTime timePoint = LocalDateTime.now(); LocalDate localDate = timePoint.toLocalDate(); birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant()); } - @Before - public void testSetUp() { - this.pet = new Pet(); - PetType dog = new PetType(); - dog.setId(9); - dog.setName("Duncan Jones"); - } - @Test public void testSetAndGetBirthDate() { - //Converting the current time to a local date and ultimately a date to be input into setBirthDate - this.establishCurrentDateForTesting(); pet.setBirthDate(this.birthDate); Date resultOfGetDate = pet.getBirthDate(); assertEquals(this.birthDate, resultOfGetDate); @@ -54,9 +52,16 @@ public class PetTests { public void testSetAndGetOwner() { //Creating a new owner type to test the setters and getters for the pet's owner Owner amandeepBhandal = new Owner(); + amandeepBhandal.setAddress("Off-world Colony"); + amandeepBhandal.setCity("Beirut"); + amandeepBhandal.setTelephone("514-333-3333"); + //Attach the newly created owner to the pet pet.setOwner(amandeepBhandal); Owner resultOfGetOwner = pet.getOwner(); - assertEquals(amandeepBhandal.getAddress(), resultOfGetOwner.getAddress()); + assertEquals(resultOfGetOwner.getAddress(), "Off-world Colony"); + assertEquals(resultOfGetOwner.getCity(), "Beirut"); + assertEquals(resultOfGetOwner.getTelephone(), "514-333-3333"); + assertEquals(resultOfGetOwner.getPetsInternal().size(), 0); } @Test