Validate our own tests work with JUnit5 and the vintage engine

Closes gh-14737

Co-authored-by: Stephane Nicoll <snicoll@pivotal.io>
This commit is contained in:
Madhura Bhave
2018-12-05 13:56:29 -08:00
committed by Stephane Nicoll
parent d9f339a1b6
commit 1db1c8b03c
821 changed files with 2279 additions and 2787 deletions

View File

@@ -20,14 +20,12 @@ import java.lang.management.ManagementFactory;
import javax.management.ObjectName;
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.context.SpringBootTest;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.web.context.WebApplicationContext;
@@ -43,33 +41,32 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.
* @author Oliver Gierke
* @author Dave Syer
*/
@RunWith(SpringRunner.class)
// Enable JMX so we can test the MBeans (you can't do this in a properties file)
@SpringBootTest(
properties = { "spring.jmx.enabled:true", "spring.datasource.jmx-enabled:true" })
@ActiveProfiles("scratch")
// Separate profile for web tests to avoid clashing databases
public class SampleDataJpaApplicationTests {
class SampleDataJpaApplicationTests {
@Autowired
private WebApplicationContext context;
private MockMvc mvc;
@Before
@BeforeEach
public void setUp() {
this.mvc = MockMvcBuilders.webAppContextSetup(this.context).build();
}
@Test
public void testHome() throws Exception {
void testHome() throws Exception {
this.mvc.perform(get("/")).andExpect(status().isOk())
.andExpect(content().string("Bath"));
}
@Test
public void testJmx() throws Exception {
void testJmx() throws Exception {
assertThat(ManagementFactory.getPlatformMBeanServer()
.queryMBeans(new ObjectName("jpa.sample:type=HikariDataSource,*"), null))
.hasSize(1);

View File

@@ -15,15 +15,13 @@
*/
package sample.data.jpa.service;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import sample.data.jpa.domain.City;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -32,15 +30,14 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class CityRepositoryIntegrationTests {
class CityRepositoryIntegrationTests {
@Autowired
CityRepository repository;
@Test
public void findsFirstPageOfCities() {
void findsFirstPageOfCities() {
Page<City> cities = this.repository.findAll(PageRequest.of(0, 10));
assertThat(cities.getTotalElements()).isGreaterThan(20L);
}

View File

@@ -17,8 +17,7 @@ package sample.data.jpa.service;
import java.util.List;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import sample.data.jpa.domain.City;
import sample.data.jpa.domain.Hotel;
import sample.data.jpa.domain.HotelSummary;
@@ -30,7 +29,6 @@ import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.test.context.junit4.SpringRunner;
import static org.assertj.core.api.Assertions.assertThat;
@@ -39,9 +37,8 @@ import static org.assertj.core.api.Assertions.assertThat;
*
* @author Oliver Gierke
*/
@RunWith(SpringRunner.class)
@SpringBootTest
public class HotelRepositoryIntegrationTests {
class HotelRepositoryIntegrationTests {
@Autowired
CityRepository cityRepository;
@@ -50,7 +47,7 @@ public class HotelRepositoryIntegrationTests {
HotelRepository repository;
@Test
public void executesQueryMethodsCorrectly() {
void executesQueryMethodsCorrectly() {
City city = this.cityRepository
.findAll(PageRequest.of(0, 1, Direction.ASC, "name")).getContent().get(0);
assertThat(city.getName()).isEqualTo("Atlanta");