mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 00:05:50 +00:00
Added test for Visit.java and VisitRepository.java
This commit is contained in:
parent
cd8cee435e
commit
23b1d2bb58
2 changed files with 82 additions and 0 deletions
|
@ -0,0 +1,51 @@
|
||||||
|
package org.springframework.samples.petclinic.visit;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||||
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||||
|
import org.springframework.context.annotation.ComponentScan;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
|
||||||
|
@RunWith(SpringRunner.class)
|
||||||
|
@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class))
|
||||||
|
public class VisitRepositoryTest {
|
||||||
|
private static final int VISIT_ID = 1;
|
||||||
|
private static final String DESCRIPTION = "Visiting a test case";
|
||||||
|
private static final Date TODAY = new Date();
|
||||||
|
private Visit visit;
|
||||||
|
private List<Visit> visitList;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private VisitRepository visitRepository;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp(){
|
||||||
|
visit = new Visit();
|
||||||
|
visit.setDescription(DESCRIPTION);
|
||||||
|
visit.setPetId(VISIT_ID);
|
||||||
|
visit.setDate(TODAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void shouldFindSavedVisitInVisitRepository() {
|
||||||
|
visitRepository.save(visit);
|
||||||
|
visitList = visitRepository.findByPetId(VISIT_ID);
|
||||||
|
|
||||||
|
assertEquals(visitList.size(), 1);
|
||||||
|
Visit savedVisit = visitList.get(0);
|
||||||
|
assertEquals((int) savedVisit.getPetId(), VISIT_ID);
|
||||||
|
assertEquals(savedVisit.getDescription(), DESCRIPTION);
|
||||||
|
assertEquals(savedVisit.getDate(), TODAY);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,31 @@
|
||||||
|
package org.springframework.samples.petclinic.visit;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class VisitTest {
|
||||||
|
private Visit visit;
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDate() {
|
||||||
|
Date today = new Date();
|
||||||
|
visit.setDate(today);
|
||||||
|
assertEquals(visit.getDate(), today);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetDescription() {
|
||||||
|
String description = "The greatest visit of all time";
|
||||||
|
visit.setDescription(description);
|
||||||
|
assertEquals(visit.getDescription(), description);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetPetId() {
|
||||||
|
int petId = 1;
|
||||||
|
visit.setPetId(petId);
|
||||||
|
assertEquals((int) visit.getPetId(), petId);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in a new issue