Skip to content

Commit 2891994

Browse files
authored
Migrate test to junit 5 (#181)
1 parent a83065c commit 2891994

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+352
-140
lines changed

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/BaseTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
import com.fasterxml.jackson.databind.ObjectMapper;
66
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
77

8-
public abstract class BaseTest extends junit.framework.TestCase
8+
import static org.junit.jupiter.api.Assertions.fail;
9+
10+
public abstract class BaseTest
911
{
1012
protected BaseTest() { }
1113

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/ForceLazyLoadingTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,17 @@
44
import com.fasterxml.jackson.datatype.hibernate4.data.Customer;
55
import com.fasterxml.jackson.datatype.hibernate4.data.Payment;
66
import org.hibernate.Hibernate;
7-
import org.junit.Test;
7+
8+
import org.junit.jupiter.api.Test;
89

910
import javax.persistence.EntityManager;
1011
import javax.persistence.EntityManagerFactory;
1112
import javax.persistence.Persistence;
1213
import java.util.Map;
1314
import java.util.Set;
1415

16+
import static org.junit.jupiter.api.Assertions.*;
17+
1518
public class ForceLazyLoadingTest extends BaseTest
1619
{
1720
// [Issue#15]

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/HibernateTest.java

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,24 @@
55
import javax.persistence.Persistence;
66
import javax.persistence.Query;
77

8-
import org.junit.Assert;
9-
import org.junit.Test;
8+
import org.junit.jupiter.api.*;
109

1110
import com.fasterxml.jackson.databind.ObjectMapper;
1211
import com.fasterxml.jackson.datatype.hibernate4.data.Customer;
1312
import com.fasterxml.jackson.datatype.hibernate4.data.Employee;
1413

14+
import static org.junit.jupiter.api.Assertions.*;
15+
1516
public class HibernateTest extends BaseTest
1617
{
1718
protected EntityManagerFactory emf;
1819

19-
@Override
20+
@BeforeEach
2021
public void setUp() {
2122
emf = Persistence.createEntityManagerFactory("persistenceUnit");
2223
}
23-
24-
@Override
24+
25+
@AfterEach
2526
public void tearDown() {
2627
if (emf!=null) {
2728
emf.close();
@@ -37,7 +38,7 @@ public void tearDown() {
3738
@Test
3839
public void testGetEntityManager() {
3940
EntityManager em = emf.createEntityManager();
40-
Assert.assertNotNull(em);
41+
assertNotNull(em);
4142
}
4243

4344
@Test
@@ -58,7 +59,7 @@ public void testGetCustomerJson() throws Exception {
5859
@Test
5960
public void testAllCustomersJson() throws Exception {
6061
EntityManager em = emf.createEntityManager();
61-
Assert.assertNotNull(em);
62+
assertNotNull(em);
6263

6364
Query query = em.createQuery("select c from Customer c");
6465
// false -> no forcing of lazy loading
@@ -85,8 +86,8 @@ public void testCyclesJson() throws Exception {
8586
EntityManager em = emf.createEntityManager();
8687

8788
Employee salesEmployee = em.find(Employee.class, 1370);
88-
Assert.assertNotNull(salesEmployee);
89-
Assert.assertTrue(salesEmployee.getCustomers().size()>0);
89+
assertNotNull(salesEmployee);
90+
assertTrue(salesEmployee.getCustomers().size()>0);
9091

9192
// false -> no forcing of lazy loading
9293
ObjectMapper mapper = mapperWithModule(false);

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/InclusionTest.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import java.util.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.JsonInclude.Include;
68
import com.fasterxml.jackson.databind.ObjectMapper;
79

10+
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
812
public class InclusionTest extends BaseTest
913
{
1014
static class Mock
@@ -14,6 +18,7 @@ static class Mock
1418
}
1519

1620
// [hibernate#65]
21+
@Test
1722
public void testInclusion() throws Exception
1823
{
1924
final ObjectMapper mapper = mapperWithModule(false);

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/InfiniteRecursion70Test.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,17 @@
55
import javax.persistence.Persistence;
66

77
import org.hibernate.Hibernate;
8+
import org.junit.jupiter.api.Test;
89

910
import com.fasterxml.jackson.databind.ObjectMapper;
1011
import com.fasterxml.jackson.datatype.hibernate4.data.Contrato;
1112

13+
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
1215
public class InfiniteRecursion70Test extends BaseTest
1316
{
1417
// [datatype-hibernate#70]
18+
@Test
1519
public void testInfinite() throws Exception
1620
{
1721
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/LazyLoadingTest.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
import com.fasterxml.jackson.datatype.hibernate4.data.Payment;
1414

1515
import org.hibernate.Hibernate;
16-
import org.junit.Test;
16+
import org.junit.jupiter.api.Test;
17+
18+
import static org.junit.jupiter.api.Assertions.*;
1719

1820
public class LazyLoadingTest extends BaseTest
1921
{

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/MissingEntitiesAsNullTest.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,17 @@
88

99
import org.hibernate.Hibernate;
1010

11+
import org.junit.jupiter.api.Test;
12+
1113
import com.fasterxml.jackson.databind.JsonMappingException;
1214
import com.fasterxml.jackson.databind.ObjectMapper;
1315
import com.fasterxml.jackson.datatype.hibernate4.data.Customer;
1416

17+
import static org.junit.jupiter.api.Assertions.*;
18+
1519
// [Issue#125]
1620
public class MissingEntitiesAsNullTest extends BaseTest {
21+
@Test
1722
public void testMissingProductWhenMissing() throws Exception {
1823
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
1924

@@ -39,6 +44,7 @@ public void testMissingProductWhenMissing() throws Exception {
3944
}
4045
}
4146

47+
@Test
4248
public void testProductWithValidForeignKey() throws Exception {
4349
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
4450

@@ -66,6 +72,7 @@ public void testProductWithValidForeignKey() throws Exception {
6672

6773
// caused by javax.persistence.EntityNotFoundException: Unable to find
6874
// com.fasterxml.jackson.datatype.hibernate4.data.Product with id X10_1678
75+
@Test
6976
public void testExceptionWithInvalidForeignKey() throws Exception {
7077
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
7178

@@ -90,6 +97,7 @@ public void testExceptionWithInvalidForeignKey() throws Exception {
9097
}
9198
}
9299

100+
@Test
93101
public void testWriteAsNullWithInvalidForeignKey() throws Exception {
94102
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnit");
95103

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/OneToManyTest.java

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,12 @@
44

55
import javax.persistence.OneToMany;
66

7+
import org.junit.jupiter.api.Test;
8+
79
import com.fasterxml.jackson.databind.ObjectMapper;
810

11+
import static org.junit.jupiter.api.Assertions.assertEquals;
12+
913
public class OneToManyTest extends BaseTest
1014
{
1115
static final String EXPECTED_JSON = "{\"m\":{\"A\":\"A\"}}";
@@ -18,15 +22,17 @@ static final class X {
1822
static final class Y {
1923
public final Map<String, String> m = new LinkedHashMap<String, String>();
2024
}
21-
25+
26+
@Test
2227
public void testMap() throws Exception {
2328
Y object = new Y();
2429
object.m.put("A", "A");
2530

2631
assertEquals(EXPECTED_JSON, mapWithoutHibernateModule(object));
2732
assertEquals(EXPECTED_JSON, mapWithHibernateModule(object));
2833
}
29-
34+
35+
@Test
3036
public void testMapWithOneToMany() throws Exception {
3137
X object = new X();
3238
object.m.put("A", "A");

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/Polymorphic81Test.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,13 @@
22

33
import java.util.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.annotation.*;
68
import com.fasterxml.jackson.databind.ObjectMapper;
79

10+
import static org.junit.jupiter.api.Assertions.assertNotNull;
11+
812
public class Polymorphic81Test extends BaseTest
913
{
1014
static class TestLayout {
@@ -59,6 +63,7 @@ public static Expression simpleFieldExpression(String field) {
5963
}
6064
}
6165

66+
@Test
6267
public void testPolymorphic81() throws Exception
6368
{
6469
final ObjectMapper mapper = mapperWithModule(true);

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/ReplacePersistentCollectionTest.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,30 @@
55
import com.fasterxml.jackson.datatype.hibernate4.data.Customer;
66
import com.fasterxml.jackson.datatype.hibernate4.data.Payment;
77
import org.hibernate.Hibernate;
8-
import org.junit.After;
9-
import org.junit.Assert;
10-
import org.junit.Before;
11-
import org.junit.Test;
8+
9+
import org.junit.jupiter.api.*;
1210

1311
import javax.persistence.EntityManager;
1412
import javax.persistence.EntityManagerFactory;
1513
import javax.persistence.Persistence;
1614
import java.util.Map;
1715
import java.util.Set;
1816

17+
import static org.junit.jupiter.api.Assertions.*;
18+
1919
public class ReplacePersistentCollectionTest {
2020

2121
private EntityManagerFactory emf;
2222

2323
private EntityManager em;
2424

25-
@Before
25+
@BeforeEach
2626
public void setUp() throws Exception {
2727
emf = Persistence.createEntityManagerFactory("persistenceUnit");
2828
em = emf.createEntityManager();
2929
}
3030

31-
@After
31+
@AfterEach
3232
public void tearDown() throws Exception {
3333
em.close();
3434
emf.close();
@@ -43,9 +43,9 @@ public void testNoReplacePersistentCollection() throws Exception {
4343
).enableDefaultTyping();
4444

4545
Customer customer = em.find(Customer.class, 103);
46-
Assert.assertFalse(Hibernate.isInitialized(customer.getPayments()));
46+
assertFalse(Hibernate.isInitialized(customer.getPayments()));
4747
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(customer);
48-
Assert.assertTrue(json.contains("org.hibernate.collection"));
48+
assertTrue(json.contains("org.hibernate.collection"));
4949
// should force loading...
5050
Set<Payment> payments = customer.getPayments();
5151
/*
@@ -54,17 +54,17 @@ public void testNoReplacePersistentCollection() throws Exception {
5454
System.out.println("--- /JSON ---");
5555
*/
5656

57-
Assert.assertTrue(Hibernate.isInitialized(payments));
57+
assertTrue(Hibernate.isInitialized(payments));
5858
// TODO: verify
59-
Assert.assertNotNull(json);
59+
assertNotNull(json);
6060

6161
boolean exceptionThrown = false;
6262
try {
6363
Map<?, ?> stuff = mapper.readValue(json, Map.class);
6464
} catch (JsonMappingException e) {
6565
exceptionThrown = true;
6666
}
67-
Assert.assertTrue(exceptionThrown);
67+
assertTrue(exceptionThrown);
6868
}
6969

7070
// [Issue#93], backwards compatible case
@@ -77,9 +77,9 @@ public void testReplacePersistentCollection() throws Exception {
7777
).enableDefaultTyping();
7878

7979
Customer customer = em.find(Customer.class, 103);
80-
Assert.assertFalse(Hibernate.isInitialized(customer.getPayments()));
80+
assertFalse(Hibernate.isInitialized(customer.getPayments()));
8181
String json = mapper.writerWithDefaultPrettyPrinter().writeValueAsString(customer);
82-
Assert.assertFalse(json.contains("org.hibernate.collection"));
82+
assertFalse(json.contains("org.hibernate.collection"));
8383
// should force loading...
8484
Set<Payment> payments = customer.getPayments();
8585
/*
@@ -88,9 +88,9 @@ public void testReplacePersistentCollection() throws Exception {
8888
System.out.println("--- /JSON ---");
8989
*/
9090

91-
Assert.assertTrue(Hibernate.isInitialized(payments));
91+
assertTrue(Hibernate.isInitialized(payments));
9292
// TODO: verify
93-
Assert.assertNotNull(json);
93+
assertNotNull(json);
9494

9595
/*
9696
* Currently this cannot be verified due to Issue#94 default typing fails on 2.7.0 - 2.8.2-SNAPSHOT,
@@ -104,12 +104,12 @@ public void testReplacePersistentCollection() throws Exception {
104104
issue94failed = true;
105105
}
106106

107-
Assert.assertTrue("If this fails, means #94 is fixed. Replace to the below commented lines", issue94failed);
107+
assertTrue(issue94failed, "If this fails, means #94 is fixed. Replace to the below commented lines");
108108

109109
// Map<?, ?> stuff = mapper.readValue(json, Map.class);
110110
//
111-
// Assert.assertTrue(stuff.containsKey("payments"));
112-
// Assert.assertTrue(stuff.containsKey("orders"));
113-
// Assert.assertNull(stuff.get("orderes"));
111+
// assertTrue(stuff.containsKey("payments"));
112+
// assertTrue(stuff.containsKey("orders"));
113+
// assertNull(stuff.get("orderes"));
114114
}
115115
}

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/TestMaps.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,15 @@
22

33
import java.util.*;
44

5+
import org.junit.jupiter.api.Test;
6+
57
import com.fasterxml.jackson.databind.ObjectMapper;
68

9+
import static org.junit.jupiter.api.Assertions.assertEquals;
10+
711
public class TestMaps extends BaseTest
812
{
13+
@Test
914
public void testSimpleMap() throws Exception
1015
{
1116
ObjectMapper mapper = mapperWithModule(false);

hibernate4/src/test/java/com/fasterxml/jackson/datatype/hibernate4/TestVersions.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
package com.fasterxml.jackson.datatype.hibernate4;
22

3+
import org.junit.jupiter.api.Test;
4+
35
import com.fasterxml.jackson.core.Version;
46
import com.fasterxml.jackson.core.Versioned;
57

6-
import com.fasterxml.jackson.datatype.hibernate4.Hibernate4Module;
8+
import static org.junit.jupiter.api.Assertions.assertFalse;
79

810
public class TestVersions extends BaseTest
911
{
12+
@Test
1013
public void testMapperVersions()
1114
{
1215
assertVersion(new Hibernate4Module());
@@ -15,7 +18,7 @@ public void testMapperVersions()
1518
private void assertVersion(Versioned vers)
1619
{
1720
Version v = vers.version();
18-
assertFalse("Should find version information (got "+v+")", v.isUnknownVersion());
21+
assertFalse(v.isUnknownVersion(), "Should find version information (got "+v+")");
1922
// Version exp = PackageVersion.VERSION;
2023
// assertEquals(exp.toFullString(), v.toFullString());
2124
// assertEquals(exp, v);

0 commit comments

Comments
 (0)