Skip to content

Commit 441da15

Browse files
committed
Migrate junit4 to junit5
1 parent 0caf92b commit 441da15

File tree

10 files changed

+27
-56
lines changed

10 files changed

+27
-56
lines changed

SpringBootJpa/src/test/java/com/example/java/CustomerRepositoryTests.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,23 @@
22

33
import com.example.java.simple.domain.Customer;
44
import com.example.java.simple.repository.CustomerRepository;
5-
import org.junit.Test;
6-
import org.junit.runner.RunWith;
5+
import org.junit.jupiter.api.Test;
76
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
9-
import org.springframework.test.context.junit4.SpringRunner;
108

11-
import static org.junit.Assert.assertNotEquals;
9+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1210

13-
@RunWith(SpringRunner.class)
1411
@DataJpaTest
15-
public class CustomerRepositoryTests {
12+
class CustomerRepositoryTests {
1613

1714
@Autowired
1815
private CustomerRepository repository;
1916

2017
@Test
21-
public void test_update() {
18+
void test_update() {
2219
Customer customer = repository.save(new Customer("heo won chul", "010-xxxx-xxxx", "developer")); // 비영속성 데이터
2320
customer.changeBigo("Developer");
2421

25-
assertNotEquals(repository.save(customer).getBigo(), "developer");
22+
assertNotEquals("developer", repository.save(customer).getBigo());
2623
}
2724
}
Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
11
package com.example.java;
22

33
import com.example.java.simple.domain.Customer;
4-
import org.junit.Test;
5-
import org.junit.runner.RunWith;
4+
import org.junit.jupiter.api.Test;
65
import org.springframework.beans.factory.annotation.Autowired;
76
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
87
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager;
9-
import org.springframework.test.context.junit4.SpringRunner;
108

11-
import static org.junit.Assert.assertNotEquals;
9+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
1210

13-
@RunWith(SpringRunner.class)
1411
@DataJpaTest
15-
public class EntityManagerTests {
12+
class EntityManagerTests {
1613

1714
@Autowired
1815
private TestEntityManager testEntityManager;
@@ -23,13 +20,13 @@ private Customer getPersistenceContextCustomer() {
2320
}
2421

2522
@Test
26-
public void test_insertClearAndFindAndUpdateClear() {
23+
void test_insertClearAndFindAndUpdateClear() {
2724
Customer customer = testEntityManager.persistFlushFind(getPersistenceContextCustomer());
2825
customer.changeBigo("Developer");
2926
testEntityManager.flush(); // Database 동기화
3027
// testEntityManager.clear(); // Persistence Context 초기화
3128

3229
Customer result = testEntityManager.find(Customer.class, customer.getIdx());
33-
assertNotEquals(result.getBigo(), "developer");
30+
assertNotEquals("developer", result.getBigo());
3431
}
3532
}

SpringBootJpa/src/test/java/com/example/java/OneToManyTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,17 @@
44
import com.example.java.onetomany.domain.Product;
55
import com.example.java.onetomany.repository.OrderRepository;
66
import com.example.java.onetomany.repository.ProductRepository;
7-
import org.junit.Test;
8-
import org.junit.runner.RunWith;
7+
import org.junit.jupiter.api.Test;
98
import org.springframework.beans.factory.annotation.Autowired;
109
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
11-
import org.springframework.test.context.junit4.SpringRunner;
1210

1311
import java.util.Arrays;
1412
import java.util.List;
1513

1614
import static org.assertj.core.api.Assertions.assertThat;
1715

18-
@RunWith(SpringRunner.class)
1916
@DataJpaTest
20-
public class OneToManyTests {
17+
class OneToManyTests {
2118

2219
@Autowired
2320
private OrderRepository orderRepository;
@@ -28,7 +25,7 @@ public class OneToManyTests {
2825
private static final String PRODUCT_NAME = "java";
2926

3027
@Test
31-
public void test_productFindByName() {
28+
void test_productFindByName() {
3229
// given
3330
insertBaseData();
3431

SpringBootJpa/src/test/java/com/example/java/OneToOneTests.java

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@
44
import com.example.java.onetoone.domain.Owner;
55
import com.example.java.onetoone.repository.MarketRepository;
66
import com.example.java.onetoone.repository.OwnerRepository;
7-
import org.junit.Before;
8-
import org.junit.Test;
9-
import org.junit.runner.RunWith;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
109
import org.springframework.beans.factory.annotation.Autowired;
1110
import org.springframework.boot.test.context.SpringBootTest;
12-
import org.springframework.test.context.junit4.SpringRunner;
1311
import org.springframework.transaction.annotation.Transactional;
1412

15-
@RunWith(SpringRunner.class)
1613
@SpringBootTest(classes = SpringBootJpaApplication.class)
1714
@Transactional
1815
public class OneToOneTests {
@@ -23,7 +20,7 @@ public class OneToOneTests {
2320
@Autowired
2421
OwnerRepository ownerRepository;
2522

26-
@Before
23+
@BeforeEach
2724
public void before_init() {
2825
Market wonchulMarket = marketRepository.save(new Market("원철 중화 반점", "서울 구로구"));
2926
Market naeunMarket = marketRepository.save(new Market("나은 중화 반점", "서울 구로구"));
@@ -46,7 +43,7 @@ public void before_init() {
4643
}
4744

4845
@Test
49-
public void test_findOne() {
46+
void test_findOne() {
5047
System.out.println(marketRepository.findById(1L).orElse(null));
5148
System.out.println(ownerRepository.findById(1L).orElse(null));
5249
}

SpringBootJpa/src/test/java/com/example/java/TimeTests.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,19 @@
22

33
import com.example.java.simple.domain.TimeData;
44
import com.example.java.simple.repository.TimeDataRepository;
5-
import org.junit.Test;
6-
import org.junit.runner.RunWith;
5+
import org.junit.jupiter.api.Test;
76
import org.springframework.beans.factory.annotation.Autowired;
87
import org.springframework.boot.test.context.SpringBootTest;
9-
import org.springframework.test.context.junit4.SpringRunner;
108

119
import java.time.LocalDateTime;
1210

13-
@RunWith(SpringRunner.class)
1411
@SpringBootTest
15-
public class TimeTests {
12+
class TimeTests {
1613

1714
@Autowired TimeDataRepository timeDataRepository;
1815

1916
@Test
20-
public void test_save() {
17+
void test_save() {
2118
timeDataRepository.save(new TimeData(LocalDateTime.now()));
2219
}
2320

SpringBootJpa/src/test/kotlin/com/example/kotlin/CustomerRepositoryTests.kt

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,10 @@ package com.example.kotlin
33
import com.example.kotlin.simple.domain.Customer
44
import com.example.kotlin.simple.repository.CustomerRepository
55
import org.junit.Assert.assertNotEquals
6-
import org.junit.Test
7-
import org.junit.runner.RunWith
6+
import org.junit.jupiter.api.Test
87
import org.springframework.beans.factory.annotation.Autowired
98
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
10-
import org.springframework.test.context.junit4.SpringRunner
119

12-
13-
@RunWith(SpringRunner::class)
1410
@DataJpaTest
1511
class CustomerRepositoryTests {
1612

SpringBootJpa/src/test/kotlin/com/example/kotlin/EntityManagerTests.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ package com.example.kotlin
22

33
import com.example.kotlin.simple.domain.Customer
44
import org.junit.Assert.assertNotEquals
5-
import org.junit.Test
6-
import org.junit.runner.RunWith
5+
import org.junit.jupiter.api.Test
76
import org.springframework.beans.factory.annotation.Autowired
87
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
98
import org.springframework.boot.test.autoconfigure.orm.jpa.TestEntityManager
10-
import org.springframework.test.context.junit4.SpringRunner
119

12-
@RunWith(SpringRunner::class)
1310
@DataJpaTest
1411
class EntityManagerTests {
1512

SpringBootJpa/src/test/kotlin/com/example/kotlin/OneToManyTests.kt

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import com.example.kotlin.onetomany.domain.Product
55
import com.example.kotlin.onetomany.repository.OrderRepository
66
import com.example.kotlin.onetomany.repository.ProductRepository
77
import org.assertj.core.api.Assertions.assertThat
8-
import org.junit.Test
9-
import org.junit.runner.RunWith
8+
import org.junit.jupiter.api.Test
109
import org.springframework.beans.factory.annotation.Autowired
1110
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest
12-
import org.springframework.test.context.junit4.SpringRunner
1311
import java.util.*
1412

15-
@RunWith(SpringRunner::class)
1613
@DataJpaTest
1714
class OneToManyTests {
1815

SpringBootJpa/src/test/kotlin/com/example/kotlin/OneToOneTests.kt

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,15 +4,12 @@ import com.example.kotlin.onetoone.domain.Market
44
import com.example.kotlin.onetoone.domain.Owner
55
import com.example.kotlin.onetoone.repository.MarketRepository
66
import com.example.kotlin.onetoone.repository.OwnerRepository
7-
import org.junit.Before
8-
import org.junit.Test
9-
import org.junit.runner.RunWith
7+
import org.junit.jupiter.api.BeforeEach
8+
import org.junit.jupiter.api.Test
109
import org.springframework.beans.factory.annotation.Autowired
1110
import org.springframework.boot.test.context.SpringBootTest
12-
import org.springframework.test.context.junit4.SpringRunner
1311
import org.springframework.transaction.annotation.Transactional
1412

15-
@RunWith(SpringRunner::class)
1613
@SpringBootTest
1714
@Transactional
1815
class OneToOneTests {
@@ -23,7 +20,7 @@ class OneToOneTests {
2320
@Autowired
2421
lateinit var ownerRepository: OwnerRepository
2522

26-
@Before
23+
@BeforeEach
2724
fun before_init() {
2825
val wonchulMarket = marketRepository.save(Market(name = "원철 중화 반점", location = "서울 구로구"))
2926
val naeunMarket = marketRepository.save(Market(name = "나은 중화 반점", location = "서울 구로구"))

SpringBootJpa/src/test/kotlin/com/example/kotlin/TimeTests.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package com.example.kotlin
22

33
import com.example.kotlin.simple.domain.TimeData
44
import com.example.kotlin.simple.repository.TimeDataRepository
5-
import org.junit.Test
5+
import org.junit.jupiter.api.Test
66
import org.junit.runner.RunWith
77
import org.springframework.beans.factory.annotation.Autowired
88
import org.springframework.boot.test.context.SpringBootTest
99
import org.springframework.test.context.junit4.SpringRunner
1010

1111
import java.time.LocalDateTime
1212

13-
@RunWith(SpringRunner::class)
1413
@SpringBootTest
1514
class TimeTests {
1615

0 commit comments

Comments
 (0)