mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 00:05:50 +00:00
Merge pull request #2 from jadmalek/rogerDev
Adding more tests to the Owner class methods
This commit is contained in:
commit
f00cd1233a
1 changed files with 45 additions and 0 deletions
|
@ -2,6 +2,7 @@ package org.springframework.samples.petclinic.owner;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
@ -55,6 +56,7 @@ public class OwnerTest {
|
||||||
@Test
|
@Test
|
||||||
public void setPetgetPetsTest() {
|
public void setPetgetPetsTest() {
|
||||||
Pet pet = new Pet();
|
Pet pet = new Pet();
|
||||||
|
|
||||||
pet.setName("Pogo");
|
pet.setName("Pogo");
|
||||||
ownerInstance.addPet(pet);
|
ownerInstance.addPet(pet);
|
||||||
List<Pet> result = ownerInstance.getPets();
|
List<Pet> result = ownerInstance.getPets();
|
||||||
|
@ -65,4 +67,47 @@ public class OwnerTest {
|
||||||
assertEquals(pet.getName(), onlyPet.getName());
|
assertEquals(pet.getName(), onlyPet.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void getPetExistsTest() {
|
||||||
|
Pet pet = new Pet();
|
||||||
|
pet.setName("Pochi");
|
||||||
|
ownerInstance.addPet(pet);
|
||||||
|
|
||||||
|
//tests pet object exists
|
||||||
|
assertEquals(pet, ownerInstance.getPet("Pochi"));
|
||||||
|
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
|
||||||
|
public void getPetsTest() {
|
||||||
|
Pet pet = new Pet();
|
||||||
|
List<Pet> list = new ArrayList<>();
|
||||||
|
list.add(pet);
|
||||||
|
ownerInstance.addPet(pet);
|
||||||
|
|
||||||
|
assertEquals(list, ownerInstance.getPets());
|
||||||
|
assertEquals(1, list.size());
|
||||||
|
|
||||||
|
Pet pet2 = new Pet();
|
||||||
|
list.add(pet2);
|
||||||
|
ownerInstance.addPet(pet2);
|
||||||
|
|
||||||
|
assertEquals(list, ownerInstance.getPets());
|
||||||
|
assertEquals(2, list.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void setGetAddress() {
|
||||||
|
ownerInstance.setAddress("123 FakeStreet");
|
||||||
|
assertEquals("123 FakeStreet", ownerInstance.getAddress());
|
||||||
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue