Skip to content

Commit fcba2a2

Browse files
Migrate to JUnit 5 (#292)
Co-Authored-By: [email protected] <[email protected]>
1 parent 59f3e12 commit fcba2a2

File tree

12 files changed

+84
-100
lines changed

12 files changed

+84
-100
lines changed

doma-spring-boot-autoconfigure/pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,8 @@
4646
<scope>test</scope>
4747
</dependency>
4848
<dependency>
49-
<groupId>org.junit.vintage</groupId>
50-
<artifactId>junit-vintage-engine</artifactId>
51-
<scope>test</scope>
52-
</dependency>
53-
<dependency>
54-
<groupId>junit</groupId>
55-
<artifactId>junit</artifactId>
49+
<groupId>org.junit.jupiter</groupId>
50+
<artifactId>junit-jupiter</artifactId>
5651
<scope>test</scope>
5752
</dependency>
5853
<dependency>

doma-spring-boot-core/pom.xml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -34,21 +34,11 @@
3434
<groupId>org.springframework.data</groupId>
3535
<artifactId>spring-data-commons</artifactId>
3636
</dependency>
37-
<dependency>
38-
<groupId>junit</groupId>
39-
<artifactId>junit</artifactId>
40-
<scope>test</scope>
41-
</dependency>
4237
<dependency>
4338
<groupId>org.junit.jupiter</groupId>
4439
<artifactId>junit-jupiter</artifactId>
4540
<scope>test</scope>
4641
</dependency>
47-
<dependency>
48-
<groupId>org.junit.vintage</groupId>
49-
<artifactId>junit-vintage-engine</artifactId>
50-
<scope>test</scope>
51-
</dependency>
5242
<dependency>
5343
<groupId>org.assertj</groupId>
5444
<artifactId>assertj-core</artifactId>

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/DomaPersistenceExceptionTranslatorTest.java

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
package org.seasar.doma.boot;
22

3-
import static org.hamcrest.CoreMatchers.*;
4-
import static org.hamcrest.MatcherAssert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.junit.jupiter.api.Assertions.assertInstanceOf;
55

66
import java.sql.SQLException;
77
import java.util.Collections;
88

9-
import org.junit.Test;
9+
import org.junit.jupiter.api.Test;
1010
import org.seasar.doma.DomaException;
1111
import org.seasar.doma.jdbc.ConfigException;
1212
import org.seasar.doma.jdbc.NoResultException;
@@ -39,7 +39,7 @@ public class DomaPersistenceExceptionTranslatorTest {
3939
public void testOccurNotJdbcException() {
4040
DataAccessException dataAccessException = translator
4141
.translateExceptionIfPossible(new DomaException(Message.DOMA2008));
42-
assertThat(dataAccessException, nullValue());
42+
assertNull(dataAccessException);
4343
}
4444

4545
@Test
@@ -50,9 +50,9 @@ public void testOccurSqlExecutionException() {
5050
"select * from todo where todo_id = ?",
5151
"select * from todo where todo_id = '000000001'",
5252
"TodoDao/findOne.sql", new SQLException(), null));
53-
assertThat(dataAccessException, is(instanceOf(UncategorizedSQLException.class)));
54-
assertThat(UncategorizedSQLException.class.cast(dataAccessException).getSql(),
55-
is("select * from todo where todo_id = ?"));
53+
assertInstanceOf(UncategorizedSQLException.class, dataAccessException);
54+
assertEquals("select * from todo where todo_id = ?",
55+
((UncategorizedSQLException)dataAccessException).getSql());
5656
}
5757

5858
@Test
@@ -64,8 +64,7 @@ public void testThrowOptimisticLockingFailureException() {
6464
"update todo set title = ? where todo_id = ? and version = ?",
6565
"update todo set title = 'Modified Title' where todo_id = '000000001' and version = 1",
6666
"TodoDao/update.sql"));
67-
assertThat(dataAccessException,
68-
is(instanceOf(OptimisticLockingFailureException.class)));
67+
assertInstanceOf(OptimisticLockingFailureException.class, dataAccessException);
6968
}
7069

7170
@Test
@@ -77,7 +76,7 @@ public void testThrowDuplicateKeyException() {
7776
"insert into todo (todo_id, title) values (?, ?)",
7877
"insert into todo (todo_id, title) values ('000000001', 'Title')",
7978
"TodoDao/insert.sql", new SQLException()));
80-
assertThat(dataAccessException, is(instanceOf(DuplicateKeyException.class)));
79+
assertInstanceOf(DuplicateKeyException.class, dataAccessException);
8180
}
8281

8382
@Test
@@ -89,8 +88,7 @@ public void testThrowIncorrectResultSizeDataAccessException() {
8988
"select * from todo where created_at = ?",
9089
"select * from todo where created_at = '2016-03-06'",
9190
"TodoDao/findBy.sql"));
92-
assertThat(dataAccessException,
93-
is(instanceOf(IncorrectResultSizeDataAccessException.class)));
91+
assertInstanceOf(IncorrectResultSizeDataAccessException.class, dataAccessException);
9492
}
9593
{
9694
DataAccessException dataAccessException = translator
@@ -100,8 +98,7 @@ public void testThrowIncorrectResultSizeDataAccessException() {
10098
"select todo_id, title from todo where created_at = ?",
10199
"select todo_id, title from todo where created_at = '2016-03-06'",
102100
"TodoDao/findBy.sql"));
103-
assertThat(dataAccessException,
104-
is(instanceOf(IncorrectResultSizeDataAccessException.class)));
101+
assertInstanceOf(IncorrectResultSizeDataAccessException.class, dataAccessException);
105102
}
106103
}
107104

@@ -112,8 +109,7 @@ public void testThrowEmptyResultDataAccessException() {
112109
SqlKind.SELECT, "select * from todo where todo_id = ?",
113110
"select * from todo where todo_id = '000000001'",
114111
"TodoDao/findOne.sql"));
115-
assertThat(dataAccessException,
116-
is(instanceOf(EmptyResultDataAccessException.class)));
112+
assertInstanceOf(EmptyResultDataAccessException.class, dataAccessException);
117113
}
118114

119115
@Test
@@ -125,8 +121,7 @@ public void testThrowTypeMismatchDataAccessException() {
125121
SqlKind.SELECT, "select * from todo where created_at = ?",
126122
"select * from todo where created_at = '2016-03-06'",
127123
"TodoDao/findBy.sql"));
128-
assertThat(dataAccessException,
129-
is(instanceOf(TypeMismatchDataAccessException.class)));
124+
assertInstanceOf(TypeMismatchDataAccessException.class, dataAccessException);
130125
}
131126
{
132127
DataAccessException dataAccessException = translator
@@ -139,8 +134,7 @@ public void testThrowTypeMismatchDataAccessException() {
139134
"select todo_id, title from todo where created_at = ?",
140135
"select todo_id, title from todo where created_at = '2016-03-06'",
141136
"TodoDao/findBy.sql"));
142-
assertThat(dataAccessException,
143-
is(instanceOf(TypeMismatchDataAccessException.class)));
137+
assertInstanceOf(TypeMismatchDataAccessException.class, dataAccessException);
144138
}
145139
}
146140

@@ -149,8 +143,7 @@ public void testThrowUncategorizedDataAccessException() {
149143
DataAccessException dataAccessException = translator
150144
.translateExceptionIfPossible(new ConfigException("DomaConfig",
151145
"configure"));
152-
assertThat(dataAccessException,
153-
is(instanceOf(UncategorizedDataAccessException.class)));
146+
assertInstanceOf(UncategorizedDataAccessException.class, dataAccessException);
154147
}
155148

156149
}

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/PageablesTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package org.seasar.doma.boot;
22

3-
import static org.hamcrest.CoreMatchers.*;
4-
import static org.hamcrest.MatcherAssert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
54

6-
import org.junit.Test;
5+
import org.junit.jupiter.api.Test;
76
import org.seasar.doma.jdbc.SelectOptions;
87
import org.seasar.doma.jdbc.SelectOptionsAccessor;
98
import org.springframework.data.domain.PageRequest;
@@ -13,22 +12,22 @@ public class PageablesTest {
1312
@Test
1413
public void testToSelectOptions() throws Exception {
1514
SelectOptions options = Pageables.toSelectOptions(pageRequest(0, 10));
16-
assertThat(SelectOptionsAccessor.getOffset(options), is(0L));
17-
assertThat(SelectOptionsAccessor.getLimit(options), is(10L));
15+
assertEquals(0L, SelectOptionsAccessor.getOffset(options));
16+
assertEquals(10L, SelectOptionsAccessor.getLimit(options));
1817
}
1918

2019
@Test
2120
public void testToSelectOptions2() throws Exception {
2221
SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 10));
23-
assertThat(SelectOptionsAccessor.getOffset(options), is(20L));
24-
assertThat(SelectOptionsAccessor.getLimit(options), is(10L));
22+
assertEquals(20L, SelectOptionsAccessor.getOffset(options));
23+
assertEquals(10L, SelectOptionsAccessor.getLimit(options));
2524
}
2625

2726
@Test
2827
public void testToSelectOptions3() throws Exception {
2928
SelectOptions options = Pageables.toSelectOptions(pageRequest(2, 5));
30-
assertThat(SelectOptionsAccessor.getOffset(options), is(10L));
31-
assertThat(SelectOptionsAccessor.getLimit(options), is(5L));
29+
assertEquals(10L, SelectOptionsAccessor.getOffset(options));
30+
assertEquals(5L, SelectOptionsAccessor.getLimit(options));
3231
}
3332

3433
private static PageRequest pageRequest(int page, int size) throws Exception {

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/TryLookupEntityListenerProviderTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
package org.seasar.doma.boot;
22

3-
import static org.hamcrest.CoreMatchers.*;
4-
import static org.hamcrest.MatcherAssert.*;
3+
import static org.junit.jupiter.api.Assertions.*;
4+
import static org.junit.jupiter.api.Assertions.assertThrows;
55

6-
import org.junit.Test;
6+
import org.junit.jupiter.api.Test;
77
import org.seasar.doma.jdbc.entity.EntityListener;
88
import org.springframework.beans.factory.annotation.Autowired;
99
import org.springframework.context.ApplicationContext;
@@ -21,17 +21,19 @@ public void testManaged() throws Exception {
2121
TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider();
2222
provider.setApplicationContext(context);
2323
FooListener listener = provider.get(FooListener.class, FooListener::new);
24-
assertThat(listener.managed, is(true));
24+
assertTrue(listener.managed);
2525
}
2626
}
2727

28-
@Test(expected = IllegalStateException.class)
28+
@Test
2929
public void testManaged_notUnique() throws Exception {
3030
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
3131
FooConfig.class)) {
3232
TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider();
3333
provider.setApplicationContext(context);
34-
provider.get(FooListener.class, FooListener::new);
34+
assertThrows(IllegalStateException.class, () -> {
35+
provider.get(FooListener.class, FooListener::new);
36+
});
3537
}
3638
}
3739

@@ -42,7 +44,7 @@ public void testNotManaged() throws Exception {
4244
TryLookupEntityListenerProvider provider = new TryLookupEntityListenerProvider();
4345
provider.setApplicationContext(context);
4446
FooListener listener = provider.get(FooListener.class, FooListener::new);
45-
assertThat(listener.managed, is(false));
47+
assertFalse(listener.managed);
4648
}
4749
}
4850

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/UnifiedCriteriaPageableTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package org.seasar.doma.boot;
22

33
import static org.assertj.core.api.Assertions.assertThatThrownBy;
4-
import static org.hamcrest.CoreMatchers.is;
5-
import static org.hamcrest.CoreMatchers.nullValue;
6-
import static org.hamcrest.CoreMatchers.sameInstance;
7-
import static org.hamcrest.MatcherAssert.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertNull;
6+
import static org.junit.jupiter.api.Assertions.assertSame;
87
import static org.mockito.Mockito.inOrder;
98
import static org.mockito.Mockito.mock;
109
import static org.mockito.Mockito.times;
@@ -41,8 +40,8 @@ public void testOffsetAndLimit(
4140
Integer offset = p.offset();
4241
Integer limit = p.limit();
4342

44-
assertThat(offset, is(expectedOffset));
45-
assertThat(limit, is(expectedLimit));
43+
assertEquals(expectedOffset, offset);
44+
assertEquals(expectedLimit, limit);
4645
}
4746

4847
@Test
@@ -53,8 +52,8 @@ public void testOffsetAndLimitWhenUnpaged() {
5352
Integer offset = p.offset();
5453
Integer limit = p.limit();
5554

56-
assertThat(offset, nullValue());
57-
assertThat(limit, nullValue());
55+
assertNull(offset);
56+
assertNull(limit);
5857
}
5958

6059
@Test
@@ -123,7 +122,7 @@ public void testOrderByWhenNonSortAndSetDefault() {
123122

124123
Consumer<OrderByNameDeclaration> consumer = p.orderBy();
125124

126-
assertThat(consumer, sameInstance(defaultOrder));
125+
assertSame(defaultOrder, consumer);
127126
}
128127

129128
@Test
@@ -166,7 +165,7 @@ public void testOrderByWhenMissingAllProperties() {
166165

167166
Consumer<OrderByNameDeclaration> consumer = p.orderBy();
168167

169-
assertThat(consumer, sameInstance(defaultOrder));
168+
assertSame(defaultOrder, consumer);
170169
}
171170

172171
@Test
@@ -187,4 +186,4 @@ public void testOrderByWhenMissingPropertiesHandle() {
187186

188187
@Entity(metamodel = @Metamodel)
189188
record Person(@Id String id, String name, Integer age) {
190-
}
189+
}

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaApplicationListenerTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,8 @@
66

77
import java.lang.reflect.Method;
88

9-
import org.junit.Test;
10-
import org.junit.experimental.runners.Enclosed;
11-
import org.junit.runner.RunWith;
9+
import org.junit.jupiter.api.Nested;
10+
import org.junit.jupiter.api.Test;
1211
import org.seasar.doma.Entity;
1312
import org.seasar.doma.boot.event.annotation.HandlePostInsert;
1413
import org.seasar.doma.boot.event.annotation.HandlePreInsert;
@@ -21,9 +20,9 @@
2120
import org.springframework.core.Ordered;
2221
import org.springframework.stereotype.Component;
2322

24-
@RunWith(Enclosed.class)
2523
public class DomaApplicationListenerTest {
2624

25+
@Nested
2726
public static class ConstructorTest {
2827

2928
@SuppressWarnings("unused")
@@ -184,6 +183,7 @@ void handle(TestEntity1 entity, PreInsertContext<TestEntity1> context) {
184183
}
185184
}
186185

186+
@Nested
187187
public static class OnApplicationEventTest {
188188

189189
@Test
@@ -369,4 +369,4 @@ public ApplicationListener<?> createApplicationListener(String beanName,
369369
}
370370
}
371371
}
372-
}
372+
}

doma-spring-boot-core/src/test/java/org/seasar/doma/boot/event/DomaEventEntityListenerTest.java

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22

33
import static org.assertj.core.api.Assertions.*;
44
import static org.mockito.Mockito.*;
5+
import static org.junit.jupiter.api.Assertions.assertThrows;
56

6-
import org.junit.Test;
7+
import org.junit.jupiter.api.Test;
78
import org.seasar.doma.boot.event.annotation.HandlePostDelete;
89
import org.seasar.doma.boot.event.annotation.HandlePostInsert;
910
import org.seasar.doma.boot.event.annotation.HandlePostUpdate;
@@ -333,14 +334,16 @@ public void multiAnnotations() throws Exception {
333334
}
334335
}
335336

336-
@Test(expected = BeanInitializationException.class)
337+
@Test
337338
public void noArg() throws Exception {
338-
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
339-
context.register(DomaEventEntityListener.class);
340-
context.register(DomaEventListenerFactory.class);
341-
context.register(NoArgHandler.class);
342-
context.refresh();
343-
}
339+
assertThrows(BeanInitializationException.class, () -> {
340+
try (AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext()) {
341+
context.register(DomaEventEntityListener.class);
342+
context.register(DomaEventListenerFactory.class);
343+
context.register(NoArgHandler.class);
344+
context.refresh();
345+
}
346+
});
344347
}
345348

346349
@Test

doma-spring-boot-samples/doma-spring-boot-sample-entity-listener/pom.xml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,13 +47,8 @@
4747
<scope>test</scope>
4848
</dependency>
4949
<dependency>
50-
<groupId>org.junit.vintage</groupId>
51-
<artifactId>junit-vintage-engine</artifactId>
52-
<scope>test</scope>
53-
</dependency>
54-
<dependency>
55-
<groupId>junit</groupId>
56-
<artifactId>junit</artifactId>
50+
<groupId>org.junit.jupiter</groupId>
51+
<artifactId>junit-jupiter</artifactId>
5752
<scope>test</scope>
5853
</dependency>
5954
</dependencies>

0 commit comments

Comments
 (0)