diff --git a/src/main/java/org/springframework/samples/petclinic/model/Person.java b/src/main/java/org/springframework/samples/petclinic/model/Person.java index 4cb7481e0ab8c1ff72652c8f1ca39fcc6c511764..5d23523bda531d2a7b35331161d5209e4d309848 100644 --- a/src/main/java/org/springframework/samples/petclinic/model/Person.java +++ b/src/main/java/org/springframework/samples/petclinic/model/Person.java @@ -17,8 +17,7 @@ package org.springframework.samples.petclinic.model; import javax.persistence.Column; import javax.persistence.MappedSuperclass; - -import org.hibernate.validator.constraints.NotEmpty; +import javax.validation.constraints.NotEmpty; /** * Simple JavaBean domain object representing an person. diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java index f6fcae7aced256c4fcc067dd08ac231ba987700e..89aad2c2cc2c74cee71caf32f9deb6fb822c7110 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -27,8 +27,8 @@ import javax.persistence.Entity; import javax.persistence.OneToMany; import javax.persistence.Table; import javax.validation.constraints.Digits; +import javax.validation.constraints.NotEmpty; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.beans.support.MutableSortDefinition; import org.springframework.beans.support.PropertyComparator; import org.springframework.core.style.ToStringCreator; @@ -61,7 +61,6 @@ public class Owner extends Person { @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") private Set<Pet> pets; - public String getAddress() { return this.address; } @@ -99,7 +98,8 @@ public class Owner extends Person { public List<Pet> getPets() { List<Pet> sortedPets = new ArrayList<>(getPetsInternal()); - PropertyComparator.sort(sortedPets, new MutableSortDefinition("name", true, true)); + PropertyComparator.sort(sortedPets, + new MutableSortDefinition("name", true, true)); return Collections.unmodifiableList(sortedPets); } @@ -144,13 +144,9 @@ public class Owner extends Person { public String toString() { return new ToStringCreator(this) - .append("id", this.getId()) - .append("new", this.isNew()) - .append("lastName", this.getLastName()) - .append("firstName", this.getFirstName()) - .append("address", this.address) - .append("city", this.city) - .append("telephone", this.telephone) - .toString(); + .append("id", this.getId()).append("new", this.isNew()) + .append("lastName", this.getLastName()) + .append("firstName", this.getFirstName()).append("address", this.address) + .append("city", this.city).append("telephone", this.telephone).toString(); } } diff --git a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java index c18c04dd85b2b026f73f483c76f1a27a0b31cee0..2f5e7a3484592ac9a5eccc2b0d2942677851026d 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java @@ -17,8 +17,6 @@ package org.springframework.samples.petclinic.system; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestMethod; /** * Controller used to showcase what happens when an exception is thrown @@ -32,8 +30,8 @@ class CrashController { @GetMapping("/oups") public String triggerException() { - throw new RuntimeException( - "Expected: controller used to showcase what " + "happens when an exception is thrown"); + throw new RuntimeException("Expected: controller used to showcase what " + + "happens when an exception is thrown"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java index f83d1463cbbc24edfe8bf3ca3e5794b0dc83fa5a..ce10d7b127e8ac4b532fbc1054ed1589fac8c272 100755 --- a/src/main/java/org/springframework/samples/petclinic/visit/Visit.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/Visit.java @@ -22,8 +22,8 @@ import javax.persistence.Entity; import javax.persistence.Table; import javax.persistence.Temporal; import javax.persistence.TemporalType; +import javax.validation.constraints.NotEmpty; -import org.hibernate.validator.constraints.NotEmpty; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.samples.petclinic.model.BaseEntity; @@ -46,11 +46,9 @@ public class Visit extends BaseEntity { @Column(name = "description") private String description; - @Column(name = "pet_id") private Integer petId; - /** * Creates a new instance of Visit for the current date */ @@ -58,32 +56,26 @@ public class Visit extends BaseEntity { this.date = new Date(); } - public Date getDate() { return this.date; } - public void setDate(Date date) { this.date = date; } - public String getDescription() { return this.description; } - public void setDescription(String description) { this.description = description; } - public Integer getPetId() { return this.petId; } - public void setPetId(Integer petId) { this.petId = petId; } diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java index b836d0cc2bda6fad7a2dded46f69accf794b0ff2..7da0d3dea5ecdc47a02ebc5b7a764a4e9a0ed4ef 100644 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java @@ -1,7 +1,5 @@ package org.springframework.samples.petclinic.model; -import static org.assertj.core.api.Assertions.assertThat; - import java.util.Locale; import java.util.Set; @@ -9,13 +7,15 @@ import javax.validation.ConstraintViolation; import javax.validation.Validator; import org.junit.Test; + import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; +import static org.assertj.core.api.Assertions.assertThat; + /** - * @author Michael Isvy - * Simple test to make sure that Bean Validation is working - * (useful when upgrading to a new version of Hibernate Validator/ Bean Validation) + * @author Michael Isvy Simple test to make sure that Bean Validation is working (useful + * when upgrading to a new version of Hibernate Validator/ Bean Validation) */ public class ValidatorTests { @@ -34,12 +34,13 @@ public class ValidatorTests { person.setLastName("smith"); Validator validator = createValidator(); - Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person); + Set<ConstraintViolation<Person>> constraintViolations = validator + .validate(person); assertThat(constraintViolations.size()).isEqualTo(1); ConstraintViolation<Person> violation = constraintViolations.iterator().next(); assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); - assertThat(violation.getMessage()).isEqualTo("may not be empty"); + assertThat(violation.getMessage()).isEqualTo("must not be empty"); } } diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java index f332257bc2847dfe104db1f68a1519912b80e3ea..4e8e36c147c5e3bceb05c2dea95ff099b554d87e 100644 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java +++ b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java @@ -1,7 +1,5 @@ package org.springframework.samples.petclinic.owner; -import static org.junit.Assert.assertEquals; - import java.text.ParseException; import java.util.ArrayList; import java.util.Collection; @@ -13,10 +11,9 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; import org.mockito.Mockito; -import org.mockito.runners.MockitoJUnitRunner; -import org.springframework.samples.petclinic.owner.PetRepository; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.owner.PetTypeFormatter; +import org.mockito.junit.MockitoJUnitRunner; + +import static org.junit.Assert.assertEquals; /** * Test class for {@link PetTypeFormatter} @@ -64,12 +61,12 @@ public class PetTypeFormatterTests { */ private List<PetType> makePetTypes() { List<PetType> petTypes = new ArrayList<>(); - petTypes.add(new PetType(){ + petTypes.add(new PetType() { { setName("Dog"); } }); - petTypes.add(new PetType(){ + petTypes.add(new PetType() { { setName("Bird"); }