mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:55:49 +00:00
Requested changes of OwnerTest.java
This commit is contained in:
parent
7c36089f6f
commit
d20b9c7002
1 changed files with 19 additions and 17 deletions
|
@ -11,56 +11,58 @@ import org.springframework.core.style.ToStringCreator;
|
|||
|
||||
public class OwnerTest {
|
||||
|
||||
private Owner instance;
|
||||
private Owner ownerInstance;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
this.instance = new Owner();
|
||||
this.ownerInstance = new Owner();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void getSetTelephoneTest() {
|
||||
// Owner instance = new Owner();
|
||||
instance.setTelephone("514 371 9999");
|
||||
String result = instance.getTelephone();
|
||||
ownerInstance.setTelephone("514 371 9999");
|
||||
String result = ownerInstance.getTelephone();
|
||||
assertEquals("514 371 9999", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setGetCityTest() {
|
||||
// Owner instance = new Owner();
|
||||
instance.setCity("Montreal");
|
||||
String result = instance.getCity();
|
||||
ownerInstance.setCity("Montreal");
|
||||
String result = ownerInstance.getCity();
|
||||
assertEquals("Montreal", result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void toStringTest() {
|
||||
ToStringCreator creator = new ToStringCreator(instance);
|
||||
ToStringCreator creator = new ToStringCreator(ownerInstance);
|
||||
String expected =
|
||||
creator
|
||||
.append("id", instance.getId())
|
||||
.append("new", instance.isNew())
|
||||
.append("lastName", instance.getLastName())
|
||||
.append("firstName", instance.getFirstName())
|
||||
.append("address", instance.getAddress())
|
||||
.append("city", instance.getCity())
|
||||
.append("telephone", instance.getTelephone())
|
||||
.append("id", ownerInstance.getId())
|
||||
.append("new", ownerInstance.isNew())
|
||||
.append("lastName", ownerInstance.getLastName())
|
||||
.append("firstName", ownerInstance.getFirstName())
|
||||
.append("address", ownerInstance.getAddress())
|
||||
.append("city", ownerInstance.getCity())
|
||||
.append("telephone", ownerInstance.getTelephone())
|
||||
.toString();
|
||||
String result = instance.toString();
|
||||
String result = ownerInstance.toString();
|
||||
assertEquals(expected, result);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void setPetgetPetsTest() {
|
||||
Pet pet = new Pet();
|
||||
instance.addPet(pet);
|
||||
List<Pet> result = instance.getPets();
|
||||
pet.setName("Pogo");
|
||||
ownerInstance.addPet(pet);
|
||||
List<Pet> result = ownerInstance.getPets();
|
||||
Pet onlyPet = result.iterator().next();
|
||||
|
||||
assertEquals(1, result.size()); // Make sure there's only one element in the Collection returned
|
||||
assertEquals(pet, onlyPet);
|
||||
assertEquals(pet.getName(), onlyPet.getName());
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in a new issue