mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-23 16:25:49 +00:00
Added comments for clarity
This commit is contained in:
parent
23b1d2bb58
commit
8f516f8e3d
2 changed files with 20 additions and 14 deletions
|
@ -3,14 +3,13 @@ package org.springframework.samples.petclinic.visit;
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import static org.junit.Assert.*;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
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.context.annotation.ComponentScan;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
@ -38,14 +37,14 @@ public class VisitRepositoryTest {
|
||||||
@Test
|
@Test
|
||||||
public void shouldFindSavedVisitInVisitRepository() {
|
public void shouldFindSavedVisitInVisitRepository() {
|
||||||
visitRepository.save(visit);
|
visitRepository.save(visit);
|
||||||
|
//Get the list of visits associated to VISIT_ID
|
||||||
visitList = visitRepository.findByPetId(VISIT_ID);
|
visitList = visitRepository.findByPetId(VISIT_ID);
|
||||||
|
|
||||||
assertEquals(visitList.size(), 1);
|
assertThat(visitList.size()).isEqualTo(1);
|
||||||
Visit savedVisit = visitList.get(0);
|
Visit savedVisit = visitList.get(0);
|
||||||
assertEquals((int) savedVisit.getPetId(), VISIT_ID);
|
|
||||||
assertEquals(savedVisit.getDescription(), DESCRIPTION);
|
assertThat((int) savedVisit.getPetId()).isEqualTo(VISIT_ID);
|
||||||
assertEquals(savedVisit.getDate(), TODAY);
|
assertThat(savedVisit.getDescription()).isEqualTo(DESCRIPTION);
|
||||||
|
assertThat(savedVisit.getDate()).isEqualTo(TODAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,31 +1,38 @@
|
||||||
package org.springframework.samples.petclinic.visit;
|
package org.springframework.samples.petclinic.visit;
|
||||||
|
|
||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import static org.junit.Assert.*;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class VisitTest {
|
public class VisitTest {
|
||||||
private Visit visit;
|
private Visit visit;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setUp() {
|
||||||
|
visit = new Visit();
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDate() {
|
public void testGetDate() {
|
||||||
Date today = new Date();
|
Date today = new Date();
|
||||||
visit.setDate(today);
|
visit.setDate(today);
|
||||||
assertEquals(visit.getDate(), today);
|
assertThat(visit.getDate()).isEqualTo(today);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetDescription() {
|
public void testGetDescription() {
|
||||||
String description = "The greatest visit of all time";
|
String description = "The greatest visit of all time";
|
||||||
visit.setDescription(description);
|
visit.setDescription(description);
|
||||||
assertEquals(visit.getDescription(), description);
|
assertThat(visit.getDescription()).isEqualTo(description);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testGetPetId() {
|
public void testGetPetId() {
|
||||||
int petId = 1;
|
int petId = 1;
|
||||||
visit.setPetId(petId);
|
visit.setPetId(petId);
|
||||||
assertEquals((int) visit.getPetId(), petId);
|
assertThat((int) visit.getPetId()).isEqualTo(petId);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue