mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-19 05:55:51 +00:00
Added VisitControllerTest and fixed pom.xml
This commit is contained in:
parent
6730a229a0
commit
bc81a84e48
3 changed files with 42 additions and 4 deletions
4
pom.xml
4
pom.xml
|
@ -5,7 +5,7 @@
|
|||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.springframework.samples</groupId>
|
||||
<artifactId>spring-petclinic</artifactId>
|
||||
<version>2.0.0</version>
|
||||
<version>2.0.0.BUILD-SNAPSHOT</version>
|
||||
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
|
@ -84,7 +84,7 @@
|
|||
<!-- webjars -->
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
<artifactId>webjars-locator</artifactId>
|
||||
<artifactId>webjars-locator-core</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.webjars</groupId>
|
||||
|
|
|
@ -34,8 +34,8 @@ import java.util.Map;
|
|||
* @author Dave Syer
|
||||
*/
|
||||
@Controller
|
||||
class VisitController {
|
||||
|
||||
public class VisitController // Set to public for testing -- can otherwise be accessed with annotations not covered in class
|
||||
{
|
||||
private final VisitRepository visits;
|
||||
private final PetRepository pets;
|
||||
|
||||
|
|
|
@ -0,0 +1,38 @@
|
|||
package org.springframework.samples.petclinic.teamkogan;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.mockito.Mockito.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.springframework.samples.petclinic.owner.Pet;
|
||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||
import org.springframework.samples.petclinic.owner.VisitController;
|
||||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||
|
||||
public class VisitControllerTest
|
||||
{
|
||||
@Test
|
||||
public void testPetVisitDate()
|
||||
{
|
||||
// Define random pet ID
|
||||
final Integer PET_ID = 7;
|
||||
Pet pet7 = new Pet();
|
||||
|
||||
// Mock dependencies
|
||||
VisitRepository mockVisitRepo = mock(VisitRepository.class);
|
||||
PetRepository mockPetRepo = mock(PetRepository.class);
|
||||
VisitController visitController = new VisitController(mockVisitRepo, mockPetRepo);
|
||||
|
||||
// Define mock behaviour
|
||||
when(mockPetRepo.findById(PET_ID)).thenReturn(pet7);
|
||||
|
||||
// Call method under inspection
|
||||
Visit visit = visitController.loadPetWithVisit(PET_ID, new HashMap<>());
|
||||
|
||||
// Confirm that the same visit date was assigned to the pet
|
||||
assertEquals(visit.getDate(), pet7.getVisits().get(0).getDate());
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue