mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 00:05:50 +00:00
Changed instance to ownerInstance, separated getPet tests, added assert for size in getPets
This commit is contained in:
parent
6cb72af443
commit
8b0ddd27a8
1 changed files with 39 additions and 28 deletions
|
@ -12,52 +12,52 @@ import org.springframework.core.style.ToStringCreator;
|
||||||
|
|
||||||
public class OwnerTest {
|
public class OwnerTest {
|
||||||
|
|
||||||
private Owner instance;
|
private Owner ownerInstance;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setUp() {
|
public void setUp() {
|
||||||
this.instance = new Owner();
|
this.ownerInstance = new Owner();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getSetTelephoneTest() {
|
public void getSetTelephoneTest() {
|
||||||
// Owner instance = new Owner();
|
// Owner instance = new Owner();
|
||||||
instance.setTelephone("514 371 9999");
|
ownerInstance.setTelephone("514 371 9999");
|
||||||
String result = instance.getTelephone();
|
String result = ownerInstance.getTelephone();
|
||||||
assertEquals("514 371 9999", result);
|
assertEquals("514 371 9999", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setGetCityTest() {
|
public void setGetCityTest() {
|
||||||
// Owner instance = new Owner();
|
// Owner instance = new Owner();
|
||||||
instance.setCity("Montreal");
|
ownerInstance.setCity("Montreal");
|
||||||
String result = instance.getCity();
|
String result = ownerInstance.getCity();
|
||||||
assertEquals("Montreal", result);
|
assertEquals("Montreal", result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void toStringTest() {
|
public void toStringTest() {
|
||||||
ToStringCreator creator = new ToStringCreator(instance);
|
ToStringCreator creator = new ToStringCreator(ownerInstance);
|
||||||
String expected =
|
String expected =
|
||||||
creator
|
creator
|
||||||
.append("id", instance.getId())
|
.append("id", ownerInstance.getId())
|
||||||
.append("new", instance.isNew())
|
.append("new", ownerInstance.isNew())
|
||||||
.append("lastName", instance.getLastName())
|
.append("lastName", ownerInstance.getLastName())
|
||||||
.append("firstName", instance.getFirstName())
|
.append("firstName", ownerInstance.getFirstName())
|
||||||
.append("address", instance.getAddress())
|
.append("address", ownerInstance.getAddress())
|
||||||
.append("city", instance.getCity())
|
.append("city", ownerInstance.getCity())
|
||||||
.append("telephone", instance.getTelephone())
|
.append("telephone", ownerInstance.getTelephone())
|
||||||
.toString();
|
.toString();
|
||||||
String result = instance.toString();
|
String result = ownerInstance.toString();
|
||||||
assertEquals(expected, result);
|
assertEquals(expected, result);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setPetgetPetsTest() {
|
public void setPetgetPetsTest() {
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
instance.addPet(pet);
|
ownerInstance.addPet(pet);
|
||||||
List<Pet> result = instance.getPets();
|
List<Pet> result = ownerInstance.getPets();
|
||||||
Pet onlyPet = result.iterator().next();
|
Pet onlyPet = result.iterator().next();
|
||||||
|
|
||||||
assertEquals(1, result.size()); // Make sure there's only one element in the Collection returned
|
assertEquals(1, result.size()); // Make sure there's only one element in the Collection returned
|
||||||
|
@ -65,14 +65,23 @@ public class OwnerTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getPetTest() {
|
public void getPetExistsTest() {
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
pet.setName("Pochi");
|
pet.setName("Pochi");
|
||||||
instance.addPet(pet);
|
ownerInstance.addPet(pet);
|
||||||
|
|
||||||
assertEquals(pet, instance.getPet("Pochi"));
|
//tests pet object exists
|
||||||
assertEquals(pet, instance.getPet("Pochi", false)); //tests pet object exists
|
assertEquals(pet, ownerInstance.getPet("Pochi"));
|
||||||
assertEquals(null, instance.getPet("Pochi", true)); //tests pet object doesn't exist
|
assertEquals(pet, ownerInstance.getPet("Pochi", false));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPetDoesntExistsTest() {
|
||||||
|
Pet pet = new Pet();
|
||||||
|
pet.setName("Pochi");
|
||||||
|
ownerInstance.addPet(pet);
|
||||||
|
//tests pet object doesn't exist
|
||||||
|
assertEquals(null, ownerInstance.getPet("Pochi", true));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -80,20 +89,22 @@ public class OwnerTest {
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
List<Pet> list = new ArrayList<>();
|
List<Pet> list = new ArrayList<>();
|
||||||
list.add(pet);
|
list.add(pet);
|
||||||
instance.addPet(pet);
|
ownerInstance.addPet(pet);
|
||||||
|
|
||||||
assertEquals(list, instance.getPets());
|
assertEquals(list, ownerInstance.getPets());
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
Pet pet2 = new Pet();
|
Pet pet2 = new Pet();
|
||||||
list.add(pet2);
|
list.add(pet2);
|
||||||
instance.addPet(pet2);
|
ownerInstance.addPet(pet2);
|
||||||
|
|
||||||
assertEquals(list, instance.getPets());
|
assertEquals(list, ownerInstance.getPets());
|
||||||
|
assertEquals(2, list.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void setGetAddress() {
|
public void setGetAddress() {
|
||||||
instance.setAddress("123 FakeStreet");
|
ownerInstance.setAddress("123 FakeStreet");
|
||||||
assertEquals("123 FakeStreet", instance.getAddress());
|
assertEquals("123 FakeStreet", ownerInstance.getAddress());
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue