mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2026-01-14 13:51:12 +00:00
#96 Reformat code with EditorConfig
This commit is contained in:
parent
1aef94d6a8
commit
09ed33a5fc
56 changed files with 831 additions and 832 deletions
|
|
@ -13,24 +13,22 @@ import org.springframework.context.i18n.LocaleContextHolder;
|
|||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
/**
|
||||
*
|
||||
* @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)
|
||||
*
|
||||
* 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 {
|
||||
|
||||
private Validator createValidator() {
|
||||
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
|
||||
localValidatorFactoryBean.afterPropertiesSet();
|
||||
return localValidatorFactoryBean;
|
||||
}
|
||||
|
||||
@Test
|
||||
private Validator createValidator() {
|
||||
LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean();
|
||||
localValidatorFactoryBean.afterPropertiesSet();
|
||||
return localValidatorFactoryBean;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotValidateWhenFirstNameEmpty() {
|
||||
|
||||
LocaleContextHolder.setLocale(Locale.ENGLISH);
|
||||
LocaleContextHolder.setLocale(Locale.ENGLISH);
|
||||
Person person = new Person();
|
||||
person.setFirstName("");
|
||||
person.setLastName("smith");
|
||||
|
|
@ -39,9 +37,9 @@ public class ValidatorTests {
|
|||
Set<ConstraintViolation<Person>> constraintViolations = validator.validate(person);
|
||||
|
||||
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.getMessage()).isEqualTo("may not be empty");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -69,8 +69,8 @@ public abstract class AbstractClinicServiceTests {
|
|||
Owner owner = this.clinicService.findOwnerById(1);
|
||||
assertThat(owner.getLastName()).startsWith("Franklin");
|
||||
assertThat(owner.getPets().size()).isEqualTo(1);
|
||||
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
||||
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
||||
assertThat(owner.getPets().get(0).getType()).isNotNull();
|
||||
assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
@ -78,7 +78,7 @@ public abstract class AbstractClinicServiceTests {
|
|||
public void shouldInsertOwner() {
|
||||
Collection<Owner> owners = this.clinicService.findOwnerByLastName("Schultz");
|
||||
int found = owners.size();
|
||||
|
||||
|
||||
Owner owner = new Owner();
|
||||
owner.setFirstName("Sam");
|
||||
owner.setLastName("Schultz");
|
||||
|
|
@ -94,11 +94,11 @@ public abstract class AbstractClinicServiceTests {
|
|||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldUpdateOwner() {
|
||||
public void shouldUpdateOwner() {
|
||||
Owner owner = this.clinicService.findOwnerById(1);
|
||||
String oldLastName = owner.getLastName();
|
||||
String newLastName = oldLastName + "X";
|
||||
|
||||
|
||||
owner.setLastName(newLastName);
|
||||
this.clinicService.saveOwner(owner);
|
||||
|
||||
|
|
@ -107,87 +107,87 @@ public abstract class AbstractClinicServiceTests {
|
|||
assertThat(owner.getLastName()).isEqualTo(newLastName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindPetWithCorrectId() {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getName()).startsWith("Samantha");
|
||||
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
|
||||
|
||||
}
|
||||
@Test
|
||||
public void shouldFindPetWithCorrectId() {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getName()).startsWith("Samantha");
|
||||
assertThat(pet7.getOwner().getFirstName()).isEqualTo("Jean");
|
||||
|
||||
@Test
|
||||
public void shouldFindAllPetTypes() {
|
||||
Collection<PetType> petTypes = this.clinicService.findPetTypes();
|
||||
|
||||
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
||||
assertThat(petType1.getName()).isEqualTo("cat");
|
||||
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
|
||||
assertThat(petType4.getName()).isEqualTo("snake");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldInsertPetIntoDatabaseAndGenerateId() {
|
||||
Owner owner6 = this.clinicService.findOwnerById(6);
|
||||
int found = owner6.getPets().size();
|
||||
|
||||
Pet pet = new Pet();
|
||||
pet.setName("bowser");
|
||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
||||
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
||||
pet.setBirthDate(new DateTime());
|
||||
owner6.addPet(pet);
|
||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||
|
||||
this.clinicService.savePet(pet);
|
||||
this.clinicService.saveOwner(owner6);
|
||||
|
||||
owner6 = this.clinicService.findOwnerById(6);
|
||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||
// checks that id has been generated
|
||||
assertThat(pet.getId()).isNotNull();
|
||||
}
|
||||
@Test
|
||||
public void shouldFindAllPetTypes() {
|
||||
Collection<PetType> petTypes = this.clinicService.findPetTypes();
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldUpdatePetName() throws Exception {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
String oldName = pet7.getName();
|
||||
|
||||
String newName = oldName + "X";
|
||||
pet7.setName(newName);
|
||||
this.clinicService.savePet(pet7);
|
||||
PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1);
|
||||
assertThat(petType1.getName()).isEqualTo("cat");
|
||||
PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4);
|
||||
assertThat(petType4.getName()).isEqualTo("snake");
|
||||
}
|
||||
|
||||
pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getName()).isEqualTo(newName);
|
||||
}
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldInsertPetIntoDatabaseAndGenerateId() {
|
||||
Owner owner6 = this.clinicService.findOwnerById(6);
|
||||
int found = owner6.getPets().size();
|
||||
|
||||
@Test
|
||||
public void shouldFindVets() {
|
||||
Collection<Vet> vets = this.clinicService.findVets();
|
||||
|
||||
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
||||
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
||||
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
|
||||
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
|
||||
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
|
||||
}
|
||||
Pet pet = new Pet();
|
||||
pet.setName("bowser");
|
||||
Collection<PetType> types = this.clinicService.findPetTypes();
|
||||
pet.setType(EntityUtils.getById(types, PetType.class, 2));
|
||||
pet.setBirthDate(new DateTime());
|
||||
owner6.addPet(pet);
|
||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldAddNewVisitForPet() {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
int found = pet7.getVisits().size();
|
||||
Visit visit = new Visit();
|
||||
pet7.addVisit(visit);
|
||||
visit.setDescription("test");
|
||||
this.clinicService.saveVisit(visit);
|
||||
this.clinicService.savePet(pet7);
|
||||
this.clinicService.savePet(pet);
|
||||
this.clinicService.saveOwner(owner6);
|
||||
|
||||
pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
|
||||
assertThat(visit.getId()).isNotNull();
|
||||
}
|
||||
owner6 = this.clinicService.findOwnerById(6);
|
||||
assertThat(owner6.getPets().size()).isEqualTo(found + 1);
|
||||
// checks that id has been generated
|
||||
assertThat(pet.getId()).isNotNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldUpdatePetName() throws Exception {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
String oldName = pet7.getName();
|
||||
|
||||
String newName = oldName + "X";
|
||||
pet7.setName(newName);
|
||||
this.clinicService.savePet(pet7);
|
||||
|
||||
pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getName()).isEqualTo(newName);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFindVets() {
|
||||
Collection<Vet> vets = this.clinicService.findVets();
|
||||
|
||||
Vet vet = EntityUtils.getById(vets, Vet.class, 3);
|
||||
assertThat(vet.getLastName()).isEqualTo("Douglas");
|
||||
assertThat(vet.getNrOfSpecialties()).isEqualTo(2);
|
||||
assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry");
|
||||
assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery");
|
||||
}
|
||||
|
||||
@Test
|
||||
@Transactional
|
||||
public void shouldAddNewVisitForPet() {
|
||||
Pet pet7 = this.clinicService.findPetById(7);
|
||||
int found = pet7.getVisits().size();
|
||||
Visit visit = new Visit();
|
||||
pet7.addVisit(visit);
|
||||
visit.setDescription("test");
|
||||
this.clinicService.saveVisit(visit);
|
||||
this.clinicService.savePet(pet7);
|
||||
|
||||
pet7 = this.clinicService.findPetById(7);
|
||||
assertThat(pet7.getVisits().size()).isEqualTo(found + 1);
|
||||
assertThat(visit.getId()).isNotNull();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,11 +21,11 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* <p> Integration test using the jdbc profile.
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
* <p> Integration test using the jdbc profile.
|
||||
*
|
||||
* @author Thomas Risberg
|
||||
* @author Michael Isvy
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -7,12 +6,12 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* <p> Integration test using the jpa profile.
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
* <p> Integration test using the jpa profile.
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Sam Brannen
|
||||
* @author Michael Isvy
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
|
|
@ -20,4 +19,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
@ActiveProfiles("jpa")
|
||||
public class ClinicServiceJpaTests extends AbstractClinicServiceTests {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
package org.springframework.samples.petclinic.service;
|
||||
|
||||
import org.junit.runner.RunWith;
|
||||
|
|
@ -7,9 +6,10 @@ import org.springframework.test.context.ContextConfiguration;
|
|||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* <p> Integration test using the 'Spring Data' profile.
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
* <p> Integration test using the 'Spring Data' profile.
|
||||
*
|
||||
* @author Michael Isvy
|
||||
* @see AbstractClinicServiceTests AbstractClinicServiceTests for more details. </p>
|
||||
*/
|
||||
|
||||
@ContextConfiguration(locations = {"classpath:spring/business-config.xml"})
|
||||
|
|
@ -17,4 +17,4 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
|||
@ActiveProfiles("spring-data-jpa")
|
||||
public class ClinicServiceSpringDataJpaTests extends AbstractClinicServiceTests {
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -40,9 +40,9 @@ public class VetControllerTests {
|
|||
|
||||
@Test
|
||||
public void testGetExistingUser() throws Exception {
|
||||
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
actions.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
ResultActions actions = mockMvc.perform(get("/vets.json").accept(MediaType.APPLICATION_JSON))
|
||||
.andExpect(status().isOk());
|
||||
actions.andExpect(content().contentType("application/json;charset=UTF-8"))
|
||||
.andExpect(jsonPath("$.vetList[0].id").value(1));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue