mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-22 15:55:49 +00:00
[TEST] Added tests for all the methods in the Pet.java (they were all mainly getters and setters). Will attempt to add more tests for this class or others.
This commit is contained in:
parent
ce262966e9
commit
38121c4645
3 changed files with 85 additions and 1 deletions
|
@ -23,3 +23,6 @@ logging.level.org.springframework=INFO
|
|||
|
||||
# Active Spring profiles
|
||||
spring.profiles.active=production
|
||||
|
||||
# Adjusting local host to 8090 for application launch
|
||||
server.port = 8090
|
||||
|
|
|
@ -0,0 +1,81 @@
|
|||
package org.springframework.samples.petclinic.owner;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.time.*;
|
||||
import java.util.Date;
|
||||
|
||||
public class PetTests {
|
||||
|
||||
private Pet pet;
|
||||
private Date birthDate;
|
||||
|
||||
private void establishCurrentDateForTesting() {
|
||||
LocalDateTime timePoint = LocalDateTime.now();
|
||||
LocalDate localDate = timePoint.toLocalDate();
|
||||
birthDate = Date.from(localDate.atStartOfDay(ZoneId.systemDefault()).toInstant());
|
||||
}
|
||||
|
||||
@Before
|
||||
public void testSetUp() {
|
||||
this.pet = new Pet();
|
||||
PetType dog = new PetType();
|
||||
dog.setId(9);
|
||||
dog.setName("Duncan Jones");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetBirthDate() {
|
||||
//Converting the current time to a local date and ultimately a date to be input into setBirthDate
|
||||
this.establishCurrentDateForTesting();
|
||||
pet.setBirthDate(this.birthDate);
|
||||
Date resultOfGetDate = pet.getBirthDate();
|
||||
assertEquals(this.birthDate, resultOfGetDate);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetType() {
|
||||
//Creating a new pet type to test the setters and getters for pet's type
|
||||
PetType walrus = new PetType();
|
||||
walrus.setId(36);
|
||||
walrus.setName("Alex Garland");
|
||||
pet.setType(walrus);
|
||||
PetType resultOfGetType = pet.getType();
|
||||
assertEquals(walrus, resultOfGetType);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetOwner() {
|
||||
//Creating a new owner type to test the setters and getters for the pet's owner
|
||||
Owner amandeepBhandal = new Owner();
|
||||
pet.setOwner(amandeepBhandal);
|
||||
Owner resultOfGetOwner = pet.getOwner();
|
||||
assertEquals(amandeepBhandal, resultOfGetOwner);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetAndGetVisitsInternal() {
|
||||
//Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits
|
||||
Set<Visit> visitsForTesting = new LinkedHashSet<>();
|
||||
pet.setVisitsInternal(visitsForTesting);
|
||||
Set<Visit> resultOfGetVisitsInternal = pet.getVisitsInternal();
|
||||
assertEquals(visitsForTesting, resultOfGetVisitsInternal);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddVisitAndGetVisits() {
|
||||
//Creating a new set of visits, albeit an empty set, to test the setters and getters for the pet's visits
|
||||
Visit visitForTesting = new Visit();
|
||||
pet.addVisit(visitForTesting);
|
||||
List<Visit> resultOfGetVisits = pet.getVisits();
|
||||
Visit onlyVisitInCollection = resultOfGetVisits.iterator().next();
|
||||
assertEquals(1, resultOfGetVisits.size());
|
||||
assertEquals(visitForTesting, onlyVisitInCollection);
|
||||
}
|
||||
}
|
|
@ -14,7 +14,7 @@ public class ProductionConfigurationTests {
|
|||
|
||||
@Autowired
|
||||
private VetRepository vets;
|
||||
|
||||
//Test error introduced by addition of 10 commits since forking of our repo from original repo
|
||||
@Test
|
||||
public void testFindAll() throws Exception {
|
||||
vets.findAll();
|
||||
|
|
Loading…
Reference in a new issue