mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-20 14:55:50 +00:00
Add unit test for showOwner method in OwnerController
This commit is contained in:
parent
b97e693834
commit
54aef7ab64
1 changed files with 15 additions and 0 deletions
|
@ -4,6 +4,7 @@ import java.util.Map;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
import org.junit.jupiter.api.DisplayName;
|
import org.junit.jupiter.api.DisplayName;
|
||||||
import org.springframework.ui.Model;
|
import org.springframework.ui.Model;
|
||||||
|
import org.springframework.web.servlet.ModelAndView;
|
||||||
import org.springframework.ui.ConcurrentModel;
|
import org.springframework.ui.ConcurrentModel;
|
||||||
import org.springframework.samples.petclinic.owner.Owner;
|
import org.springframework.samples.petclinic.owner.Owner;
|
||||||
import org.mockito.junit.jupiter.MockitoExtension;
|
import org.mockito.junit.jupiter.MockitoExtension;
|
||||||
|
@ -213,4 +214,18 @@ class OwnerControllerTest {
|
||||||
verify(ownerRepository).findById(ownerId);
|
verify(ownerRepository).findById(ownerId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
@DisplayName("Test showOwner")
|
||||||
|
void testShowOwner() {
|
||||||
|
int ownerId = 1;
|
||||||
|
Owner owner = new Owner();
|
||||||
|
doReturn(owner).when(ownerRepository).findById(ownerId);
|
||||||
|
|
||||||
|
ModelAndView mav = ownerController.showOwner(ownerId);
|
||||||
|
|
||||||
|
assertThat(mav.getViewName()).isEqualTo("owners/ownerDetails");
|
||||||
|
assertThat(mav.getModel().get("owner")).isEqualTo(owner);
|
||||||
|
verify(ownerRepository).findById(ownerId);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue