Update to JUnit5 across all modules (#1668)
* Updated saga to JUnit 5 * Update fix for CI job in trampoline module * Updated update-method module to JUnit 5 * Upgraded to latest JUnit Jupiter JUnit 4 is not needed when using JUnit-Vintage * Reverted change to access modifier on Trampoline * Cleanup to resolve code smells * Formatting * Formatting * Migrating to JUnit5 and updating some Mockito patterns * Migrating to JUnit5 * Migrating to JUnit5 * Migrating to JUnit 5 * Formatting cleanup * Added missing scope for junit * Fixed tests that were not running previously. Co-authored-by: Subhrodip Mohanta <hello@subho.xyz>
This commit is contained in:
arrange-act-assert
async-method-invocation
combinator
double-buffer
factory
game-loop
half-sync-half-async
leader-followers
marker/src/test/java
partial-response
registry
role-object
serverless/src/test/java/com/iluwatar/serverless/faas/api
sharding
pom.xml
src
singleton
subclass-sandbox
tolerant-reader
unit-of-work
@@ -23,17 +23,17 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for App class.
|
||||
*/
|
||||
public class AppTest {
|
||||
class AppTest {
|
||||
|
||||
@Test
|
||||
public void shouldExecuteWithoutException() {
|
||||
void shouldExecuteWithoutException() {
|
||||
assertDoesNotThrow(() -> App.main(new String[]{}));
|
||||
}
|
||||
|
||||
|
@@ -23,22 +23,22 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for HashShardManager class.
|
||||
*/
|
||||
public class HashShardManagerTest {
|
||||
class HashShardManagerTest {
|
||||
|
||||
private HashShardManager hashShardManager;
|
||||
|
||||
/**
|
||||
* Initialize hashShardManager instance.
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
hashShardManager = new HashShardManager();
|
||||
var shard1 = new Shard(1);
|
||||
@@ -49,16 +49,11 @@ public class HashShardManagerTest {
|
||||
hashShardManager.addNewShard(shard3);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreData() {
|
||||
void testStoreData() {
|
||||
var data = new Data(1, "test", Data.DataType.TYPE_1);
|
||||
hashShardManager.storeData(data);
|
||||
Assert.assertEquals(data, hashShardManager.getShardById(1).getDataById(1));
|
||||
assertEquals(data, hashShardManager.getShardById(1).getDataById(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,22 +23,24 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for LookupShardManager class.
|
||||
*/
|
||||
public class LookupShardManagerTest {
|
||||
class LookupShardManagerTest {
|
||||
|
||||
private LookupShardManager lookupShardManager;
|
||||
|
||||
/**
|
||||
* Initialize lookupShardManager instance.
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
lookupShardManager = new LookupShardManager();
|
||||
var shard1 = new Shard(1);
|
||||
@@ -50,7 +52,7 @@ public class LookupShardManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreData() {
|
||||
void testStoreData() {
|
||||
try {
|
||||
var data = new Data(1, "test", Data.DataType.TYPE_1);
|
||||
lookupShardManager.storeData(data);
|
||||
@@ -59,9 +61,9 @@ public class LookupShardManagerTest {
|
||||
var lookupMap = (Map<Integer, Integer>) field.get(lookupShardManager);
|
||||
var shardId = lookupMap.get(1);
|
||||
var shard = lookupShardManager.getShardById(shardId);
|
||||
Assert.assertEquals(data, shard.getDataById(1));
|
||||
assertEquals(data, shard.getDataById(1));
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
Assert.fail("Fail to modify field access.");
|
||||
fail("Fail to modify field access.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -23,21 +23,22 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for RangeShardManager class.
|
||||
*/
|
||||
public class RangeShardManagerTest {
|
||||
class RangeShardManagerTest {
|
||||
|
||||
private RangeShardManager rangeShardManager;
|
||||
|
||||
/**
|
||||
* Initialize rangeShardManager instance.
|
||||
*/
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
rangeShardManager = new RangeShardManager();
|
||||
var shard1 = new Shard(1);
|
||||
@@ -49,10 +50,10 @@ public class RangeShardManagerTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreData() {
|
||||
void testStoreData() {
|
||||
var data = new Data(1, "test", Data.DataType.TYPE_1);
|
||||
rangeShardManager.storeData(data);
|
||||
Assert.assertEquals(data, rangeShardManager.getShardById(1).getDataById(1));
|
||||
assertEquals(data, rangeShardManager.getShardById(1).getDataById(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -23,49 +23,46 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
/**
|
||||
* Unit tests for ShardManager class.
|
||||
*/
|
||||
public class ShardManagerTest {
|
||||
class ShardManagerTest {
|
||||
|
||||
private ShardManager shardManager;
|
||||
|
||||
/**
|
||||
* Initialize shardManager instance.
|
||||
*/
|
||||
@Before
|
||||
public void setup() {
|
||||
@BeforeEach
|
||||
void setup() {
|
||||
shardManager = new TestShardManager();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAddNewShard() {
|
||||
void testAddNewShard() {
|
||||
try {
|
||||
var shard = new Shard(1);
|
||||
shardManager.addNewShard(shard);
|
||||
var field = ShardManager.class.getDeclaredField("shardMap");
|
||||
field.setAccessible(true);
|
||||
var map = (Map<Integer, Shard>) field.get(shardManager);
|
||||
Assert.assertEquals(1, map.size());
|
||||
Assert.assertEquals(shard, map.get(1));
|
||||
assertEquals(1, map.size());
|
||||
assertEquals(shard, map.get(1));
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
Assert.fail("Fail to modify field access.");
|
||||
fail("Fail to modify field access.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveShardById() {
|
||||
void testRemoveShardById() {
|
||||
try {
|
||||
var shard = new Shard(1);
|
||||
shardManager.addNewShard(shard);
|
||||
@@ -73,19 +70,19 @@ public class ShardManagerTest {
|
||||
var field = ShardManager.class.getDeclaredField("shardMap");
|
||||
field.setAccessible(true);
|
||||
var map = (Map<Integer, Shard>) field.get(shardManager);
|
||||
Assert.assertEquals(true, flag);
|
||||
Assert.assertEquals(0, map.size());
|
||||
assertTrue(flag);
|
||||
assertEquals(0, map.size());
|
||||
} catch (IllegalAccessException | NoSuchFieldException e) {
|
||||
Assert.fail("Fail to modify field access.");
|
||||
fail("Fail to modify field access.");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetShardById() {
|
||||
void testGetShardById() {
|
||||
var shard = new Shard(1);
|
||||
shardManager.addNewShard(shard);
|
||||
var tmpShard = shardManager.getShardById(1);
|
||||
Assert.assertEquals(shard, tmpShard);
|
||||
assertEquals(shard, tmpShard);
|
||||
}
|
||||
|
||||
class TestShardManager extends ShardManager {
|
||||
|
@@ -23,50 +23,47 @@
|
||||
|
||||
package com.iluwatar.sharding;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
|
||||
/**
|
||||
* Unit tests for Shard class.
|
||||
*/
|
||||
public class ShardTest {
|
||||
class ShardTest {
|
||||
|
||||
private Data data;
|
||||
|
||||
private Shard shard;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
public void setup() {
|
||||
data = new Data(1, "test", Data.DataType.TYPE_1);
|
||||
shard = new Shard(1);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStoreData() {
|
||||
void testStoreData() {
|
||||
try {
|
||||
shard.storeData(data);
|
||||
var field = Shard.class.getDeclaredField("dataStore");
|
||||
field.setAccessible(true);
|
||||
var dataMap = (Map<Integer, Data>) field.get(shard);
|
||||
Assert.assertEquals(1, dataMap.size());
|
||||
Assert.assertEquals(data, dataMap.get(1));
|
||||
assertEquals(1, dataMap.size());
|
||||
assertEquals(data, dataMap.get(1));
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
Assert.fail("Fail to modify field access.");
|
||||
fail("Fail to modify field access.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testClearData() {
|
||||
void testClearData() {
|
||||
try {
|
||||
var dataMap = new HashMap<Integer, Data>();
|
||||
dataMap.put(1, data);
|
||||
@@ -75,9 +72,9 @@ public class ShardTest {
|
||||
field.set(shard, dataMap);
|
||||
shard.clearData();
|
||||
dataMap = (HashMap<Integer, Data>) field.get(shard);
|
||||
Assert.assertEquals(0, dataMap.size());
|
||||
assertEquals(0, dataMap.size());
|
||||
} catch (NoSuchFieldException | IllegalAccessException e) {
|
||||
Assert.fail("Fail to modify field access.");
|
||||
fail("Fail to modify field access.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user