Skip to content

Commit ce39a53

Browse files
divya_jnu08mp911de
divya_jnu08
authored andcommitted
Migrate REST examples to JUnit 5.
Original pull request: #620. See #583.
1 parent e4f3438 commit ce39a53

File tree

11 files changed

+32
-61
lines changed

11 files changed

+32
-61
lines changed

rest/headers/src/test/java/example/springdata/rest/headers/ApplicationIntegrationTests.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -16,21 +16,19 @@
1616
package example.springdata.rest.headers;
1717

1818
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
19+
import static org.hamcrest.MatcherAssert.assertThat;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.test.context.SpringBootTest;
25-
import org.springframework.test.context.junit4.SpringRunner;
24+
2625

2726
/**
2827
* Integration tests to bootstrap the application.
2928
*
3029
* @author Oliver Gierke
3130
* @soundtrack The Intersphere - Out of phase (Live at Alte Feuerwache Mannheim)
3231
*/
33-
@RunWith(SpringRunner.class)
3432
@SpringBootTest
3533
public class ApplicationIntegrationTests {
3634

rest/headers/src/test/java/example/springdata/rest/headers/CrossOriginIntegrationTests.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,10 @@
2222

2323
import java.net.URI;
2424

25-
import org.junit.Before;
26-
import org.junit.Test;
27-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.BeforeEach;
26+
import org.junit.jupiter.api.Test;
2827
import org.springframework.beans.factory.annotation.Autowired;
2928
import org.springframework.boot.test.context.SpringBootTest;
30-
import org.springframework.test.context.junit4.SpringRunner;
3129
import org.springframework.test.web.servlet.MockMvc;
3230
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3331
import org.springframework.web.context.WebApplicationContext;
@@ -37,7 +35,6 @@
3735
*
3836
* @author Mark Paluch
3937
*/
40-
@RunWith(SpringRunner.class)
4138
@SpringBootTest
4239
public class CrossOriginIntegrationTests {
4340

@@ -46,7 +43,7 @@ public class CrossOriginIntegrationTests {
4643

4744
MockMvc mvc;
4845

49-
@Before
46+
@BeforeEach
5047
public void setUp() {
5148
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
5249
}

rest/headers/src/test/java/example/springdata/rest/headers/WebIntegrationTests.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,12 @@
2323

2424
import java.net.URI;
2525

26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2928
import org.springframework.beans.factory.annotation.Autowired;
3029
import org.springframework.boot.test.context.SpringBootTest;
3130
import org.springframework.mock.web.MockHttpServletResponse;
3231
import org.springframework.restdocs.config.RestDocumentationConfigurer;
33-
import org.springframework.test.context.junit4.SpringRunner;
3432
import org.springframework.test.web.servlet.MockMvc;
3533
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3634
import org.springframework.web.context.WebApplicationContext;
@@ -40,7 +38,6 @@
4038
* @author Oliver Gierke
4139
* @soundtrack The Intersphere - Out of phase (Live at Alte Feuerwache Mannheim)
4240
*/
43-
@RunWith(SpringRunner.class)
4441
@SpringBootTest
4542
public class WebIntegrationTests {
4643

@@ -49,7 +46,7 @@ public class WebIntegrationTests {
4946

5047
MockMvc mvc;
5148

52-
@Before
49+
@BeforeEach
5350
public void setUp() {
5451

5552
this.mvc = MockMvcBuilders.webAppContextSetup(context).//

rest/multi-store/src/test/java/example/springdata/multistore/ApplicationIntegrationTests.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,16 @@
2121
import example.springdata.multistore.treasure.TreasureRepository;
2222
import lombok.extern.slf4j.Slf4j;
2323

24-
import org.junit.Test;
25-
import org.junit.runner.RunWith;
24+
import org.junit.jupiter.api.Test;
2625
import org.springframework.beans.factory.annotation.Autowired;
2726
import org.springframework.boot.test.context.SpringBootTest;
28-
import org.springframework.test.context.junit4.SpringRunner;
2927

3028
/**
3129
* Integration test to show the usage of repositories backed by different stores.
3230
*
3331
* @author Oliver Gierke
3432
*/
3533
@Slf4j
36-
@RunWith(SpringRunner.class)
3734
@SpringBootTest
3835
public class ApplicationIntegrationTests {
3936

rest/projections/src/test/java/example/springdata/rest/projections/ApplicationIntegrationTests.java

+2-5
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,17 @@
1616
package example.springdata.rest.projections;
1717

1818
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
19+
import static org.hamcrest.MatcherAssert.assertThat;
2020

21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
21+
import org.junit.jupiter.api.Test;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.test.context.SpringBootTest;
25-
import org.springframework.test.context.junit4.SpringRunner;
2624

2725
/**
2826
* Integration tests to bootstrap the application.
2927
*
3028
* @author Oliver Gierke
3129
*/
32-
@RunWith(SpringRunner.class)
3330
@SpringBootTest
3431
public class ApplicationIntegrationTests {
3532

rest/projections/src/test/java/example/springdata/rest/projections/SimpleProjectionTests.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616
package example.springdata.rest.projections;
1717

1818
import static org.hamcrest.CoreMatchers.*;
19-
import static org.junit.Assert.*;
19+
import static org.hamcrest.MatcherAssert.assertThat;
2020

2121
import java.util.HashMap;
2222
import java.util.Map;
2323

24-
import org.junit.Test;
24+
import org.junit.jupiter.api.Test;
2525
import org.springframework.beans.factory.annotation.Value;
2626
import org.springframework.data.projection.ProjectionFactory;
2727
import org.springframework.data.projection.SpelAwareProxyProjectionFactory;

rest/security/src/test/java/example/springdata/rest/security/MethodLevelSecurityTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -15,31 +15,28 @@
1515
*/
1616
package example.springdata.rest.security;
1717

18-
import static org.junit.Assert.*;
18+
import static org.junit.jupiter.api.Assertions.fail;
1919

20-
import org.junit.Before;
21-
import org.junit.Test;
22-
import org.junit.runner.RunWith;
20+
import org.junit.jupiter.api.BeforeEach;
21+
import org.junit.jupiter.api.Test;
2322
import org.springframework.beans.factory.annotation.Autowired;
2423
import org.springframework.boot.test.context.SpringBootTest;
2524
import org.springframework.security.access.AccessDeniedException;
2625
import org.springframework.security.authentication.AuthenticationCredentialsNotFoundException;
2726
import org.springframework.security.core.context.SecurityContextHolder;
28-
import org.springframework.test.context.junit4.SpringRunner;
2927

3028
/**
3129
* Collection of test cases used to verify method-level security.
3230
*
3331
* @author Greg Turnquist
3432
* @author Oliver Gierke
3533
*/
36-
@RunWith(SpringRunner.class)
3734
@SpringBootTest
3835
public class MethodLevelSecurityTests {
3936

4037
@Autowired ItemRepository itemRepository;
4138

42-
@Before
39+
@BeforeEach
4340
public void setUp() {
4441
SecurityContextHolder.clearContext();
4542
}

rest/security/src/test/java/example/springdata/rest/security/UrlLevelSecurityTests.java

+4-7
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,22 @@
1616
package example.springdata.rest.security;
1717

1818
import static org.hamcrest.CoreMatchers.*;
19-
import static org.junit.Assert.*;
19+
import static org.hamcrest.MatcherAssert.assertThat;
2020
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
2121
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2222
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*;
2323

2424
import java.util.Base64;
2525

26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2928
import org.springframework.beans.factory.annotation.Autowired;
3029
import org.springframework.boot.test.context.SpringBootTest;
3130
import org.springframework.hateoas.MediaTypes;
3231
import org.springframework.http.HttpHeaders;
3332
import org.springframework.http.MediaType;
3433
import org.springframework.security.core.context.SecurityContextHolder;
3534
import org.springframework.security.web.FilterChainProxy;
36-
import org.springframework.test.context.junit4.SpringRunner;
3735
import org.springframework.test.web.servlet.MockMvc;
3836
import org.springframework.web.context.WebApplicationContext;
3937

@@ -45,7 +43,6 @@
4543
* @author Greg Turnquist
4644
* @author Oliver Gierke
4745
*/
48-
@RunWith(SpringRunner.class)
4946
@SpringBootTest
5047
public class UrlLevelSecurityTests {
5148

@@ -56,7 +53,7 @@ public class UrlLevelSecurityTests {
5653

5754
MockMvc mvc;
5855

59-
@Before
56+
@BeforeEach
6057
public void setUp() {
6158

6259
this.mvc = webAppContextSetup(context).addFilters(filterChain).build();

rest/starbucks/src/test/java/example/springdata/rest/stores/StarbucksClient.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@
2424
import java.util.Map;
2525
import java.util.stream.StreamSupport;
2626

27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
27+
import org.junit.jupiter.api.Test;
2928
import org.springframework.beans.factory.annotation.Autowired;
3029
import org.springframework.boot.autoconfigure.SpringBootApplication;
3130
import org.springframework.boot.test.context.SpringBootTest;
@@ -45,7 +44,6 @@
4544
import org.springframework.hateoas.server.core.TypeReferences.EntityModelType;
4645
import org.springframework.hateoas.server.core.TypeReferences.PagedModelType;
4746
import org.springframework.http.RequestEntity;
48-
import org.springframework.test.context.junit4.SpringRunner;
4947
import org.springframework.web.client.RestOperations;
5048
import org.springframework.web.client.RestTemplate;
5149

@@ -54,7 +52,6 @@
5452
*
5553
* @author Oliver Gierke
5654
*/
57-
@RunWith(SpringRunner.class)
5855
@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT)
5956
@Slf4j
6057
public class StarbucksClient {

rest/starbucks/src/test/java/example/springdata/rest/stores/StoreRepositoryIntegrationTests.java

+6-9
Original file line numberDiff line numberDiff line change
@@ -15,40 +15,37 @@
1515
*/
1616
package example.springdata.rest.stores;
1717

18+
import static org.hamcrest.MatcherAssert.assertThat;
1819
import static org.hamcrest.Matchers.*;
19-
import static org.junit.Assert.*;
2020

2121
import example.springdata.rest.stores.Store.Address;
2222

2323
import java.util.UUID;
2424

25-
import org.junit.After;
26-
import org.junit.Before;
27-
import org.junit.Test;
28-
import org.junit.runner.RunWith;
25+
import org.junit.jupiter.api.AfterEach;
26+
import org.junit.jupiter.api.BeforeEach;
27+
import org.junit.jupiter.api.Test;
2928
import org.springframework.beans.factory.annotation.Autowired;
3029
import org.springframework.boot.test.context.SpringBootTest;
3130
import org.springframework.data.domain.Page;
3231
import org.springframework.data.domain.PageRequest;
3332
import org.springframework.data.geo.Distance;
3433
import org.springframework.data.geo.Metrics;
3534
import org.springframework.data.geo.Point;
36-
import org.springframework.test.context.junit4.SpringRunner;
3735

3836
/**
3937
* Integration tests for {@link StoreRepository}.
4038
*
4139
* @author Oliver Gierke
4240
* @author Mark Paluch
4341
*/
44-
@RunWith(SpringRunner.class)
4542
@SpringBootTest(classes = Application.class)
4643
public class StoreRepositoryIntegrationTests {
4744

4845
@Autowired StoreRepository repository;
4946

50-
@Before
51-
@After
47+
@BeforeEach
48+
@AfterEach
5249
public void clearDb() {
5350
repository.deleteAll();
5451
}

rest/uri-customization/src/test/java/example/springdata/rest/uris/WebIntegrationTests.java

+3-6
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,10 @@
1919
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
2020
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
2121

22-
import org.junit.Before;
23-
import org.junit.Test;
24-
import org.junit.runner.RunWith;
22+
import org.junit.jupiter.api.BeforeEach;
23+
import org.junit.jupiter.api.Test;
2524
import org.springframework.beans.factory.annotation.Autowired;
2625
import org.springframework.boot.test.context.SpringBootTest;
27-
import org.springframework.test.context.junit4.SpringRunner;
2826
import org.springframework.test.web.servlet.MockMvc;
2927
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
3028
import org.springframework.web.context.WebApplicationContext;
@@ -35,15 +33,14 @@
3533
* @author Oliver Gierke
3634
* @soundtrack Clueso - Gewinner (Stadtrandlichter Live)
3735
*/
38-
@RunWith(SpringRunner.class)
3936
@SpringBootTest
4037
public class WebIntegrationTests {
4138

4239
@Autowired WebApplicationContext context;
4340

4441
MockMvc mvc;
4542

46-
@Before
43+
@BeforeEach
4744
public void setUp() {
4845
this.mvc = MockMvcBuilders.webAppContextSetup(context).build();
4946
}

0 commit comments

Comments
 (0)