Skip to content
Snippets Groups Projects
Commit cf352663 authored by Dave Syer's avatar Dave Syer
Browse files

Tidy up compiler warnings

parent 14ef611d
No related branches found
No related tags found
No related merge requests found
...@@ -17,8 +17,7 @@ package org.springframework.samples.petclinic.model; ...@@ -17,8 +17,7 @@ package org.springframework.samples.petclinic.model;
import javax.persistence.Column; import javax.persistence.Column;
import javax.persistence.MappedSuperclass; import javax.persistence.MappedSuperclass;
import javax.validation.constraints.NotEmpty;
import org.hibernate.validator.constraints.NotEmpty;
/** /**
* Simple JavaBean domain object representing an person. * Simple JavaBean domain object representing an person.
......
...@@ -27,8 +27,8 @@ import javax.persistence.Entity; ...@@ -27,8 +27,8 @@ import javax.persistence.Entity;
import javax.persistence.OneToMany; import javax.persistence.OneToMany;
import javax.persistence.Table; import javax.persistence.Table;
import javax.validation.constraints.Digits; 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.MutableSortDefinition;
import org.springframework.beans.support.PropertyComparator; import org.springframework.beans.support.PropertyComparator;
import org.springframework.core.style.ToStringCreator; import org.springframework.core.style.ToStringCreator;
...@@ -61,7 +61,6 @@ public class Owner extends Person { ...@@ -61,7 +61,6 @@ public class Owner extends Person {
@OneToMany(cascade = CascadeType.ALL, mappedBy = "owner") @OneToMany(cascade = CascadeType.ALL, mappedBy = "owner")
private Set<Pet> pets; private Set<Pet> pets;
public String getAddress() { public String getAddress() {
return this.address; return this.address;
} }
...@@ -99,7 +98,8 @@ public class Owner extends Person { ...@@ -99,7 +98,8 @@ public class Owner extends Person {
public List<Pet> getPets() { public List<Pet> getPets() {
List<Pet> sortedPets = new ArrayList<>(getPetsInternal()); 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); return Collections.unmodifiableList(sortedPets);
} }
...@@ -144,13 +144,9 @@ public class Owner extends Person { ...@@ -144,13 +144,9 @@ public class Owner extends Person {
public String toString() { public String toString() {
return new ToStringCreator(this) return new ToStringCreator(this)
.append("id", this.getId()) .append("id", this.getId()).append("new", this.isNew())
.append("new", this.isNew()) .append("lastName", this.getLastName())
.append("lastName", this.getLastName()) .append("firstName", this.getFirstName()).append("address", this.address)
.append("firstName", this.getFirstName()) .append("city", this.city).append("telephone", this.telephone).toString();
.append("address", this.address)
.append("city", this.city)
.append("telephone", this.telephone)
.toString();
} }
} }
...@@ -17,8 +17,6 @@ package org.springframework.samples.petclinic.system; ...@@ -17,8 +17,6 @@ package org.springframework.samples.petclinic.system;
import org.springframework.stereotype.Controller; import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping; 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 * Controller used to showcase what happens when an exception is thrown
...@@ -32,8 +30,8 @@ class CrashController { ...@@ -32,8 +30,8 @@ class CrashController {
@GetMapping("/oups") @GetMapping("/oups")
public String triggerException() { public String triggerException() {
throw new RuntimeException( throw new RuntimeException("Expected: controller used to showcase what "
"Expected: controller used to showcase what " + "happens when an exception is thrown"); + "happens when an exception is thrown");
} }
} }
...@@ -22,8 +22,8 @@ import javax.persistence.Entity; ...@@ -22,8 +22,8 @@ import javax.persistence.Entity;
import javax.persistence.Table; import javax.persistence.Table;
import javax.persistence.Temporal; import javax.persistence.Temporal;
import javax.persistence.TemporalType; import javax.persistence.TemporalType;
import javax.validation.constraints.NotEmpty;
import org.hibernate.validator.constraints.NotEmpty;
import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.samples.petclinic.model.BaseEntity; import org.springframework.samples.petclinic.model.BaseEntity;
...@@ -46,11 +46,9 @@ public class Visit extends BaseEntity { ...@@ -46,11 +46,9 @@ public class Visit extends BaseEntity {
@Column(name = "description") @Column(name = "description")
private String description; private String description;
@Column(name = "pet_id") @Column(name = "pet_id")
private Integer petId; private Integer petId;
/** /**
* Creates a new instance of Visit for the current date * Creates a new instance of Visit for the current date
*/ */
...@@ -58,32 +56,26 @@ public class Visit extends BaseEntity { ...@@ -58,32 +56,26 @@ public class Visit extends BaseEntity {
this.date = new Date(); this.date = new Date();
} }
public Date getDate() { public Date getDate() {
return this.date; return this.date;
} }
public void setDate(Date date) { public void setDate(Date date) {
this.date = date; this.date = date;
} }
public String getDescription() { public String getDescription() {
return this.description; return this.description;
} }
public void setDescription(String description) { public void setDescription(String description) {
this.description = description; this.description = description;
} }
public Integer getPetId() { public Integer getPetId() {
return this.petId; return this.petId;
} }
public void setPetId(Integer petId) { public void setPetId(Integer petId) {
this.petId = petId; this.petId = petId;
} }
......
package org.springframework.samples.petclinic.model; package org.springframework.samples.petclinic.model;
import static org.assertj.core.api.Assertions.assertThat;
import java.util.Locale; import java.util.Locale;
import java.util.Set; import java.util.Set;
...@@ -9,13 +7,15 @@ import javax.validation.ConstraintViolation; ...@@ -9,13 +7,15 @@ import javax.validation.ConstraintViolation;
import javax.validation.Validator; import javax.validation.Validator;
import org.junit.Test; import org.junit.Test;
import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.i18n.LocaleContextHolder;
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
import static org.assertj.core.api.Assertions.assertThat;
/** /**
* @author Michael Isvy * @author Michael Isvy Simple test to make sure that Bean Validation is working (useful
* Simple test to make sure that Bean Validation is working * when upgrading to a new version of Hibernate Validator/ Bean Validation)
* (useful when upgrading to a new version of Hibernate Validator/ Bean Validation)
*/ */
public class ValidatorTests { public class ValidatorTests {
...@@ -34,12 +34,13 @@ public class ValidatorTests { ...@@ -34,12 +34,13 @@ public class ValidatorTests {
person.setLastName("smith"); person.setLastName("smith");
Validator validator = createValidator(); Validator validator = createValidator();
Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person); Set<ConstraintViolation<Person>> constraintViolations = validator
.validate(person);
assertThat(constraintViolations.size()).isEqualTo(1); assertThat(constraintViolations.size()).isEqualTo(1);
ConstraintViolation<Person> violation = constraintViolations.iterator().next(); ConstraintViolation<Person> violation = constraintViolations.iterator().next();
assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName");
assertThat(violation.getMessage()).isEqualTo("may not be empty"); assertThat(violation.getMessage()).isEqualTo("must not be empty");
} }
} }
package org.springframework.samples.petclinic.owner; package org.springframework.samples.petclinic.owner;
import static org.junit.Assert.assertEquals;
import java.text.ParseException; import java.text.ParseException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collection; import java.util.Collection;
...@@ -13,10 +11,9 @@ import org.junit.Test; ...@@ -13,10 +11,9 @@ import org.junit.Test;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.junit.MockitoJUnitRunner;
import org.springframework.samples.petclinic.owner.PetRepository;
import org.springframework.samples.petclinic.owner.PetType; import static org.junit.Assert.assertEquals;
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
/** /**
* Test class for {@link PetTypeFormatter} * Test class for {@link PetTypeFormatter}
...@@ -64,12 +61,12 @@ public class PetTypeFormatterTests { ...@@ -64,12 +61,12 @@ public class PetTypeFormatterTests {
*/ */
private List<PetType> makePetTypes() { private List<PetType> makePetTypes() {
List<PetType> petTypes = new ArrayList<>(); List<PetType> petTypes = new ArrayList<>();
petTypes.add(new PetType(){ petTypes.add(new PetType() {
{ {
setName("Dog"); setName("Dog");
} }
}); });
petTypes.add(new PetType(){ petTypes.add(new PetType() {
{ {
setName("Bird"); setName("Bird");
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment