Skip to content

Commit 018eb3f

Browse files
authored
Merge pull request santanusinha#83 from r0goyal/junit5
JUnit 5 Integration
2 parents 7e0da80 + 83d16e8 commit 018eb3f

File tree

9 files changed

+36
-33
lines changed

9 files changed

+36
-33
lines changed

src/test/java/io/appform/dropwizard/sharding/ShardInfoProviderTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package io.appform.dropwizard.sharding;
22

33

4-
import org.junit.jupiter.api.Assertions;
54
import org.junit.jupiter.api.Test;
65

76
import static org.junit.jupiter.api.Assertions.assertEquals;
7+
import static org.junit.jupiter.api.Assertions.assertNull;
88

99
public class ShardInfoProviderTest {
1010

@@ -34,10 +34,10 @@ public void testGetNamespace() {
3434
assertEquals("default", namespace);
3535

3636
namespace = shardInfoProvider.namespace("connectionpool");
37-
Assertions.assertNull(namespace);
37+
assertNull(namespace);
3838

3939
namespace = shardInfoProvider.namespace("connectionpool-default");
40-
Assertions.assertNull(namespace);
40+
assertNull(namespace);
4141

4242
namespace = shardInfoProvider.namespace("connectionpool-test-1");
4343
assertEquals("test", namespace);

src/test/java/io/appform/dropwizard/sharding/dao/LookupDaoTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.hibernate.criterion.DetachedCriteria;
4242
import org.hibernate.criterion.Restrictions;
4343
import org.junit.jupiter.api.AfterEach;
44-
import org.junit.jupiter.api.Assertions;
4544
import org.junit.jupiter.api.BeforeEach;
4645
import org.junit.jupiter.api.Test;
4746

@@ -52,6 +51,7 @@
5251
import static org.junit.jupiter.api.Assertions.assertEquals;
5352
import static org.junit.jupiter.api.Assertions.assertFalse;
5453
import static org.junit.jupiter.api.Assertions.assertNotNull;
54+
import static org.junit.jupiter.api.Assertions.assertNull;
5555
import static org.junit.jupiter.api.Assertions.assertTrue;
5656

5757
public class LookupDaoTest {
@@ -360,8 +360,8 @@ public void deleteTest() throws Exception {
360360
assertNotNull(lookupDao.get("testId")
361361
.orElse(null));
362362
assertTrue(lookupDao.delete("testId"));
363-
Assertions.assertNull(lookupDao.get("testId")
364-
.orElse(null));
363+
assertNull(lookupDao.get("testId")
364+
.orElse(null));
365365
}
366366

367367
@Test

src/test/java/io/appform/dropwizard/sharding/dao/locktest/LockTest.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,6 @@
4141
import org.hibernate.criterion.Order;
4242
import org.hibernate.criterion.Restrictions;
4343
import org.hibernate.exception.ConstraintViolationException;
44-
import org.junit.jupiter.api.Assertions;
4544
import org.junit.jupiter.api.BeforeEach;
4645
import org.junit.jupiter.api.Test;
4746

@@ -53,9 +52,12 @@
5352

5453
import static org.junit.jupiter.api.Assertions.assertEquals;
5554
import static org.junit.jupiter.api.Assertions.assertFalse;
55+
import static org.junit.jupiter.api.Assertions.assertNotEquals;
5656
import static org.junit.jupiter.api.Assertions.assertNotNull;
5757
import static org.junit.jupiter.api.Assertions.assertNull;
58+
import static org.junit.jupiter.api.Assertions.assertThrows;
5859
import static org.junit.jupiter.api.Assertions.assertTrue;
60+
import static org.junit.jupiter.api.Assertions.fail;
5961

6062
/**
6163
* Test locking behavior
@@ -122,7 +124,7 @@ public void testLockingFail() throws Exception {
122124
.myId("0")
123125
.build();
124126
lookupDao.save(p1);
125-
Assertions.assertThrows(IllegalArgumentException.class,
127+
assertThrows(IllegalArgumentException.class,
126128
() -> lookupDao.lockAndGetExecutor("0")
127129
.filter(parent -> !Strings.isNullOrEmpty(parent.getName()))
128130
.save(relationDao, parent -> {
@@ -226,7 +228,7 @@ public void testPersist_alreadyExistingDifferent() throws Exception {
226228
.name("Changed")
227229
.build();
228230

229-
Assertions.assertThrows(ConstraintViolationException.class, () -> lookupDao.saveAndGetExecutor(p2)
231+
assertThrows(ConstraintViolationException.class, () -> lookupDao.saveAndGetExecutor(p2)
230232
.filter(parent -> !Strings.isNullOrEmpty(parent.getName()))
231233
.save(relationDao, parent -> SomeOtherObject.builder()
232234
.myId(parent.getMyId())
@@ -283,7 +285,7 @@ public void testCreateOrUpdate() throws Exception {
283285
childObj.setValue(childModifiedValue);
284286
return childObj;
285287
}, () -> {
286-
Assertions.fail("New Entity is getting created. It should have been updated.");
288+
fail("New Entity is getting created. It should have been updated.");
287289
return SomeOtherObject.builder()
288290
.myId(parentId)
289291
.value("test")
@@ -303,8 +305,8 @@ public void testCreateOrUpdate() throws Exception {
303305

304306
lookupDao.lockAndGetExecutor(parent.getMyId())
305307
.createOrUpdate(relationDao, creationCriteria, childObj -> {
306-
Assertions.assertNotEquals(null, childObj);
307-
Assertions.fail("New Entity is getting updated. It should have been created.");
308+
assertNotEquals(null, childObj);
309+
fail("New Entity is getting updated. It should have been created.");
308310

309311
childObj.setValue("abcd");
310312
return childObj;
@@ -321,7 +323,7 @@ public void testCreateOrUpdate() throws Exception {
321323
.findFirst()
322324
.get();
323325
assertEquals(newChildValue, savedChild.getValue());
324-
Assertions.assertNotEquals(child.getId(), savedChild.getId());
326+
assertNotEquals(child.getId(), savedChild.getId());
325327
assertEquals(newParentValue, lookupDao.get(parentId).get().getName());
326328
}
327329

src/test/java/io/appform/dropwizard/sharding/metrics/TransactionMetricManagerTest.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,37 +5,38 @@
55
import io.appform.dropwizard.sharding.config.MetricConfig;
66
import io.appform.dropwizard.sharding.execution.TransactionExecutionContext;
77
import lombok.val;
8-
import org.junit.jupiter.api.Assertions;
98
import org.junit.jupiter.api.Test;
109

1110
import static org.junit.jupiter.api.Assertions.assertEquals;
11+
import static org.junit.jupiter.api.Assertions.assertFalse;
12+
import static org.junit.jupiter.api.Assertions.assertTrue;
1213

1314
public class TransactionMetricManagerTest {
1415

1516
@Test
1617
public void testIsMetricApplicable() {
1718
TransactionMetricManager metricManager = new TransactionMetricManager(null, null);
18-
Assertions.assertFalse(metricManager.isMetricApplicable(this.getClass()));
19+
assertFalse(metricManager.isMetricApplicable(this.getClass()));
1920

2021
metricManager = new TransactionMetricManager(() -> null, null);
21-
Assertions.assertFalse(metricManager.isMetricApplicable(this.getClass()));
22+
assertFalse(metricManager.isMetricApplicable(this.getClass()));
2223

2324
metricManager = new TransactionMetricManager(() -> MetricConfig.builder().enabledForAll(true).build(), null);
24-
Assertions.assertTrue(metricManager.isMetricApplicable(this.getClass()));
25+
assertTrue(metricManager.isMetricApplicable(this.getClass()));
2526

2627
metricManager = new TransactionMetricManager(() -> MetricConfig.builder().enabledForAll(false)
2728
.enabledForEntities(ImmutableSet.of(this.getClass().getCanonicalName()))
2829
.build(), null);
29-
Assertions.assertTrue(metricManager.isMetricApplicable(this.getClass()));
30+
assertTrue(metricManager.isMetricApplicable(this.getClass()));
3031

3132
metricManager = new TransactionMetricManager(() -> MetricConfig.builder().enabledForAll(false)
3233
.enabledForEntities(ImmutableSet.of(this.getClass().getSimpleName()))
3334
.build(), null);
34-
Assertions.assertFalse(metricManager.isMetricApplicable(this.getClass()));
35+
assertFalse(metricManager.isMetricApplicable(this.getClass()));
3536

3637
metricManager = new TransactionMetricManager(() -> MetricConfig.builder().enabledForAll(false)
3738
.build(), null);
38-
Assertions.assertFalse(metricManager.isMetricApplicable(this.getClass()));
39+
assertFalse(metricManager.isMetricApplicable(this.getClass()));
3940
}
4041

4142
@Test

src/test/java/io/appform/dropwizard/sharding/metrics/TransactionMetricObserverTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import io.appform.dropwizard.sharding.dao.testdata.entities.RelationalEntity;
77
import io.appform.dropwizard.sharding.execution.TransactionExecutionContext;
88
import lombok.val;
9-
import org.junit.jupiter.api.Assertions;
109
import org.junit.jupiter.api.BeforeEach;
1110
import org.junit.jupiter.api.Test;
1211
import org.mockito.Mockito;
1312

1413
import static org.junit.jupiter.api.Assertions.assertEquals;
14+
import static org.junit.jupiter.api.Assertions.assertThrows;
1515

1616
public class TransactionMetricObserverTest {
1717

@@ -104,7 +104,7 @@ public void testExecuteWithException() {
104104

105105
Mockito.doReturn(true).when(metricManager).isMetricApplicable(context.getEntityClass());
106106

107-
Assertions.assertThrows(RuntimeException.class, () -> transactionMetricObserver.execute(context, this::terminateWithException));
107+
assertThrows(RuntimeException.class, () -> transactionMetricObserver.execute(context, this::terminateWithException));
108108
validateCache(entityMetricData, shardMetricData, daoMetricData, "test", context);
109109
validateMetrics(entityMetricData, shardMetricData, daoMetricData, 0, 1);
110110
}

src/test/java/io/appform/dropwizard/sharding/observers/ErrorListenerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,14 @@
1111
import lombok.val;
1212
import org.hibernate.criterion.DetachedCriteria;
1313
import org.hibernate.criterion.Property;
14-
import org.junit.jupiter.api.Assertions;
1514
import org.junit.jupiter.api.BeforeEach;
1615
import org.junit.jupiter.api.Test;
1716

1817
import java.util.concurrent.atomic.AtomicInteger;
1918

2019
import static org.junit.jupiter.api.Assertions.assertEquals;
2120
import static org.junit.jupiter.api.Assertions.assertNotNull;
21+
import static org.junit.jupiter.api.Assertions.assertThrows;
2222

2323

2424
/**
@@ -119,7 +119,7 @@ public void testFilterErrorCounter() {
119119
.setValue("CV1"))
120120
.execute();
121121
assertNotNull(parent);
122-
Assertions.assertThrows(Exception.class,
122+
assertThrows(Exception.class,
123123
() -> parentDao.lockAndGetExecutor(parent.getName())
124124
.update(childDao,
125125
DetachedCriteria.forClass(SimpleChild.class)

src/test/java/io/appform/dropwizard/sharding/sharding/BalancedShardManagerTest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,26 +18,26 @@
1818
package io.appform.dropwizard.sharding.sharding;
1919

2020

21-
import org.junit.jupiter.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2525

2626
public class BalancedShardManagerTest {
2727

2828
@Test
2929
public void testShardForBucket() throws Exception {
30-
Assertions.assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(5));
30+
assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(5));
3131
}
3232

3333
@Test
3434
public void testShardForOddBucket() throws Exception {
35-
Assertions.assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(9));
35+
assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(9));
3636
}
3737

3838
@Test
3939
public void testShardForEvenNon2PowerBucket() throws Exception {
40-
Assertions.assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(40));
40+
assertThrows(IllegalArgumentException.class, () -> new BalancedShardManager(40));
4141
}
4242

4343
@Test

src/test/java/io/appform/dropwizard/sharding/sharding/LegacyShardManagerTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,22 +18,22 @@
1818
package io.appform.dropwizard.sharding.sharding;
1919

2020

21-
import org.junit.jupiter.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.assertThrows;
2525

2626
public class LegacyShardManagerTest {
2727

2828
@Test
2929
public void testShardForOddBucket() {
30-
Assertions.assertThrows(IllegalArgumentException.class,
30+
assertThrows(IllegalArgumentException.class,
3131
() -> new LegacyShardManager(9));
3232
}
3333

3434
@Test
3535
public void testShardForEvenNon2PowerBucket() throws Exception {
36-
Assertions.assertThrows(IllegalArgumentException.class,
36+
assertThrows(IllegalArgumentException.class,
3737
() -> new LegacyShardManager(40));
3838
}
3939

src/test/java/io/appform/dropwizard/sharding/sharding/ShardManagerTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
package io.appform.dropwizard.sharding.sharding;
1919

2020
import io.appform.dropwizard.sharding.exceptions.ShardBlacklistedException;
21-
import org.junit.jupiter.api.Assertions;
2221
import org.junit.jupiter.api.Test;
2322

2423
import static org.junit.jupiter.api.Assertions.assertEquals;
24+
import static org.junit.jupiter.api.Assertions.fail;
2525

2626
public class ShardManagerTest {
2727

@@ -39,7 +39,7 @@ public void testBlacklisting() throws Exception {
3939
Thread.sleep(5000); //Sleeping for 5 seconds
4040
try {
4141
shardManager.shardForBucket(100);
42-
Assertions.fail("Should have errored out");
42+
fail("Should have errored out");
4343
} catch (ShardBlacklistedException e) {
4444

4545
}

0 commit comments

Comments
 (0)