mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 00:05:50 +00:00
Addition to VisitController tests
This commit is contained in:
parent
8f516f8e3d
commit
506639c5d8
1 changed files with 9 additions and 1 deletions
|
@ -16,10 +16,15 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
import org.springframework.samples.petclinic.owner.Pet;
|
import org.springframework.samples.petclinic.owner.Pet;
|
||||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||||
import org.springframework.samples.petclinic.owner.VisitController;
|
import org.springframework.samples.petclinic.owner.VisitController;
|
||||||
|
import org.springframework.samples.petclinic.visit.Visit;
|
||||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
import org.springframework.test.web.servlet.MockMvc;
|
import org.springframework.test.web.servlet.MockMvc;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
import static org.mockito.Matchers.any;
|
||||||
|
import static org.mockito.Matchers.anyInt;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test class for {@link VisitController}
|
* Test class for {@link VisitController}
|
||||||
*
|
*
|
||||||
|
@ -50,6 +55,7 @@ public class VisitControllerTests {
|
||||||
mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID))
|
mockMvc.perform(get("/owners/*/pets/{petId}/visits/new", TEST_PET_ID))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
||||||
|
verify(pets).findById(anyInt()); //Ensure that a pet gets loaded per visit
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -60,6 +66,8 @@ public class VisitControllerTests {
|
||||||
)
|
)
|
||||||
.andExpect(status().is3xxRedirection())
|
.andExpect(status().is3xxRedirection())
|
||||||
.andExpect(view().name("redirect:/owners/{ownerId}"));
|
.andExpect(view().name("redirect:/owners/{ownerId}"));
|
||||||
|
verify(pets).findById(anyInt()); //Ensure that a pet gets loaded per visit
|
||||||
|
verify(visits).save(any(Visit.class)); //Ensure that upon success, the visit gets saved
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -70,6 +78,6 @@ public class VisitControllerTests {
|
||||||
.andExpect(model().attributeHasErrors("visit"))
|
.andExpect(model().attributeHasErrors("visit"))
|
||||||
.andExpect(status().isOk())
|
.andExpect(status().isOk())
|
||||||
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
.andExpect(view().name("pets/createOrUpdateVisitForm"));
|
||||||
|
verify(pets).findById(anyInt()); //Ensure that a pet gets loaded per visit
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue