mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-04-24 19:32:48 +00:00
Migrate tests to JUnit 5
See gh-360
This commit is contained in:
parent
ce7c3f93de
commit
ac69dbba23
11 changed files with 50 additions and 63 deletions
19
pom.xml
19
pom.xml
|
@ -57,6 +57,13 @@
|
|||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
<scope>test</scope>
|
||||
<exclusions>
|
||||
<!-- Exclude JUnit 4 from starter-test in favour of JUnit 5 -->
|
||||
<exclusion>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
|
||||
<!-- Databases - Uses HSQL by default -->
|
||||
|
@ -103,6 +110,18 @@
|
|||
</dependency>
|
||||
<!-- end of webjars -->
|
||||
|
||||
<!-- Testing -->
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-devtools</artifactId>
|
||||
|
|
|
@ -16,15 +16,11 @@
|
|||
|
||||
package org.springframework.samples.petclinic;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.samples.petclinic.vet.VetRepository;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@SpringBootTest
|
||||
public class PetclinicIntegrationTests {
|
||||
|
||||
|
|
|
@ -22,8 +22,7 @@ import java.util.Set;
|
|||
import javax.validation.ConstraintViolation;
|
||||
import javax.validation.Validator;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.context.i18n.LocaleContextHolder;
|
||||
import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean;
|
||||
|
||||
|
|
|
@ -23,16 +23,13 @@ import java.util.List;
|
|||
import org.assertj.core.util.Lists;
|
||||
import org.hamcrest.BaseMatcher;
|
||||
import org.hamcrest.Description;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
|
@ -51,7 +48,6 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(OwnerController.class)
|
||||
public class OwnerControllerTests {
|
||||
|
||||
|
@ -68,7 +64,7 @@ public class OwnerControllerTests {
|
|||
|
||||
private Owner george;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
george = new Owner();
|
||||
george.setId(TEST_OWNER_ID);
|
||||
|
|
|
@ -24,22 +24,13 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
import org.springframework.context.annotation.FilterType;
|
||||
import org.springframework.samples.petclinic.owner.Owner;
|
||||
import org.springframework.samples.petclinic.owner.OwnerRepository;
|
||||
import org.springframework.samples.petclinic.owner.Pet;
|
||||
import org.springframework.samples.petclinic.owner.PetController;
|
||||
import org.springframework.samples.petclinic.owner.PetRepository;
|
||||
import org.springframework.samples.petclinic.owner.PetType;
|
||||
import org.springframework.samples.petclinic.owner.PetTypeFormatter;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
/**
|
||||
|
@ -47,7 +38,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(value = PetController.class,
|
||||
includeFilters = @ComponentScan.Filter(
|
||||
value = PetTypeFormatter.class,
|
||||
|
@ -67,7 +57,7 @@ public class PetControllerTests {
|
|||
@MockBean
|
||||
private OwnerRepository owners;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
PetType cat = new PetType();
|
||||
cat.setId(3);
|
||||
|
|
|
@ -22,11 +22,12 @@ import java.util.Collection;
|
|||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
@ -36,7 +37,7 @@ import static org.mockito.BDDMockito.given;
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class PetTypeFormatterTests {
|
||||
|
||||
@Mock
|
||||
|
@ -44,7 +45,7 @@ public class PetTypeFormatterTests {
|
|||
|
||||
private PetTypeFormatter petTypeFormatter;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
this.petTypeFormatter = new PetTypeFormatter(pets);
|
||||
}
|
||||
|
@ -64,10 +65,12 @@ public class PetTypeFormatterTests {
|
|||
assertThat(petType.getName()).isEqualTo("Bird");
|
||||
}
|
||||
|
||||
@Test(expected = ParseException.class)
|
||||
@Test
|
||||
public void shouldThrowParseException() throws ParseException {
|
||||
given(this.pets.findPetTypes()).willReturn(makePetTypes());
|
||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
||||
Assertions.assertThrows(ParseException.class, () -> {
|
||||
petTypeFormatter.parse("Fish", Locale.ENGLISH);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -23,17 +23,12 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
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.VisitRepository;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
/**
|
||||
|
@ -41,7 +36,6 @@ import org.springframework.test.web.servlet.MockMvc;
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(VisitController.class)
|
||||
public class VisitControllerTests {
|
||||
|
||||
|
@ -56,7 +50,7 @@ public class VisitControllerTests {
|
|||
@MockBean
|
||||
private PetRepository pets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void init() {
|
||||
given(this.pets.findById(TEST_PET_ID)).willReturn(new Pet());
|
||||
}
|
||||
|
|
|
@ -21,8 +21,8 @@ import static org.assertj.core.api.Assertions.assertThat;
|
|||
import java.time.LocalDate;
|
||||
import java.util.Collection;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
@ -36,7 +36,6 @@ import org.springframework.samples.petclinic.vet.VetRepository;
|
|||
import org.springframework.samples.petclinic.visit.Visit;
|
||||
import org.springframework.samples.petclinic.visit.VisitRepository;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
|
@ -60,7 +59,6 @@ import org.springframework.transaction.annotation.Transactional;
|
|||
* @author Dave Syer
|
||||
*/
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class))
|
||||
public class ClinicServiceTests {
|
||||
|
||||
|
|
|
@ -16,13 +16,10 @@
|
|||
|
||||
package org.springframework.samples.petclinic.system;
|
||||
|
||||
import org.junit.Ignore;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
|
@ -36,9 +33,8 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
*
|
||||
* @author Colin But
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
// Waiting https://github.com/spring-projects/spring-boot/issues/5574
|
||||
@Ignore
|
||||
@Disabled
|
||||
@WebMvcTest(controllers = CrashController.class)
|
||||
public class CrashControllerTests {
|
||||
|
||||
|
|
|
@ -25,21 +25,18 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
|
|||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view;
|
||||
|
||||
import org.assertj.core.util.Lists;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
import org.springframework.test.web.servlet.ResultActions;
|
||||
|
||||
/**
|
||||
* Test class for the {@link VetController}
|
||||
*/
|
||||
@RunWith(SpringRunner.class)
|
||||
@WebMvcTest(VetController.class)
|
||||
public class VetControllerTests {
|
||||
|
||||
|
@ -49,7 +46,7 @@ public class VetControllerTests {
|
|||
@MockBean
|
||||
private VetRepository vets;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
Vet james = new Vet();
|
||||
james.setFirstName("James");
|
||||
|
|
|
@ -15,8 +15,7 @@
|
|||
*/
|
||||
package org.springframework.samples.petclinic.vet;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.util.SerializationUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
|
Loading…
Reference in a new issue