Skip to content

Commit cdf3407

Browse files
committed
Upgrade junit lib to 5; Update tests; Reactoring heritage.
1 parent d4b0d8f commit cdf3407

File tree

6 files changed

+58
-47
lines changed

6 files changed

+58
-47
lines changed

pom.xml

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
<maven.compiler.target>11</maven.compiler.target>
1414
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
1515
<caffeine.version>3.1.8</caffeine.version>
16-
<junit.version>4.13.2</junit.version>
16+
<junit.version>5.10.3</junit.version>
1717
<mysql-connector.version>8.4.0</mysql-connector.version>
1818
<okhttp.version>4.12.0</okhttp.version>
1919
<protobuf.version>4.27.2</protobuf.version>
@@ -65,8 +65,8 @@
6565
</dependency>
6666

6767
<dependency>
68-
<groupId>junit</groupId>
69-
<artifactId>junit</artifactId>
68+
<groupId>org.junit.jupiter</groupId>
69+
<artifactId>junit-jupiter</artifactId>
7070
<version>${junit.version}</version>
7171
<scope>test</scope>
7272
</dependency>
@@ -165,6 +165,7 @@
165165
</goals>
166166
<configuration>
167167
<sources>
168+
<source>${project.build.directory}/generated-sources/protobuf</source>
168169
<source>${project.build.directory}/generated-test-sources/protobuf</source>
169170
</sources>
170171
</configuration>

src/main/java/io/eigr/spawn/api/actors/StatefulActor.java

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@
33
import java.lang.reflect.ParameterizedType;
44

55
public interface StatefulActor<S> extends BaseActor {
6-
default Class<S> getStateType() {
7-
return (Class<S>) ((ParameterizedType)
8-
getClass().getGenericSuperclass())
9-
.getActualTypeArguments()[0];
6+
default Class<S> getStateType(Class<S> entityClass) {
7+
return entityClass;
108
}
119
@Override
1210
default Boolean isStateful() {

src/main/java/io/eigr/spawn/internal/Entity.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public static Entity fromStatefulActorToEntity(BehaviorCtx ctx, Class<?> actor)
110110
try {
111111
Constructor<?> constructor = actor.getConstructor();
112112
StatefulActor stActor = (StatefulActor) constructor.newInstance();
113-
Class<?> stateType = stActor.getStateType();
113+
Class<?> stateType = stActor.getStateType(stActor.getClass().getGenericSuperclass().getClass());
114114
ActorBehavior behavior = stActor.configure(ctx);
115115

116116
if (behavior.getClass().isAssignableFrom(NamedActorBehavior.class)) {

src/test/java/io/eigr/spawn/AbstractContainerBaseTest.java

+15-3
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
import io.eigr.spawn.test.actors.JoeActor;
1212
import io.eigr.spawn.test.actors.StatelessNamedActor;
1313
import io.eigr.spawn.test.actors.UnNamedActor;
14+
import org.junit.After;
15+
import org.junit.AfterClass;
16+
import org.junit.Before;
17+
import org.junit.jupiter.api.AfterAll;
18+
import org.junit.jupiter.api.BeforeAll;
1419
import org.slf4j.Logger;
1520
import org.slf4j.LoggerFactory;
1621
import org.testcontainers.Testcontainers;
@@ -20,14 +25,15 @@
2025
abstract class AbstractContainerBaseTest {
2126

2227
private static final Logger log = LoggerFactory.getLogger(AbstractContainerBaseTest.class);
23-
private static final GenericContainer<?> SPAWN_CONTAINER;
28+
private static GenericContainer<?> SPAWN_CONTAINER;
2429
private static final String spawnProxyImage = "eigr/spawn-proxy:1.4.1-rc.1";
2530
private static final String userFunctionPort = "8091";
2631
private static final String spawnProxyPort = "9004";
27-
protected static final Spawn spawnSystem;
32+
protected static Spawn spawnSystem;
2833
protected static final String spawnSystemName = "spawn-system-test";
2934

30-
static {
35+
@BeforeAll
36+
public static void setup() {
3137
Testcontainers.exposeHostPorts(8091);
3238

3339
SPAWN_CONTAINER = new GenericContainer<>(DockerImageName.parse(spawnProxyImage))
@@ -73,5 +79,11 @@ abstract class AbstractContainerBaseTest {
7379
throw new RuntimeException(e);
7480
}
7581
}
82+
83+
@AfterAll
84+
public static void teardown() {
85+
SPAWN_CONTAINER.stop();
86+
87+
}
7688
}
7789

src/test/java/io/eigr/spawn/SpawnTest.java

+18-17
Original file line numberDiff line numberDiff line change
@@ -8,24 +8,25 @@
88
import io.eigr.spawn.test.actors.JoeActor;
99
import io.eigr.spawn.test.actors.StatelessNamedActor;
1010
import io.eigr.spawn.test.actors.UnNamedActor;
11-
import org.junit.Test;
11+
import org.junit.jupiter.api.Assertions;
12+
import org.junit.jupiter.api.Test;
1213

1314
import java.util.Optional;
1415

1516
import static org.junit.Assert.assertEquals;
1617
import static org.junit.Assert.assertNotNull;
1718

18-
public class SpawnTest extends AbstractContainerBaseTest {
19+
class SpawnTest extends AbstractContainerBaseTest {
1920

2021
@Test
21-
public void testNamedInvocation() throws ActorCreationException, ActorInvocationException {
22+
void testNamedInvocation() throws ActorCreationException, ActorInvocationException {
2223
ActorRef joeActor = spawnSystem.createActorRef(
2324
ActorIdentity.of(spawnSystemName, "JoeActor"));
2425

2526
Class type = joeActor.getType();
2627

27-
assertEquals(type, JoeActor.class);
28-
assertNotNull(joeActor);
28+
Assertions.assertEquals(type, JoeActor.class);
29+
Assertions.assertNotNull(joeActor);
2930

3031
Actor.Request msg = Actor.Request.newBuilder()
3132
.setLanguage("Erlang")
@@ -36,20 +37,20 @@ public void testNamedInvocation() throws ActorCreationException, ActorInvocation
3637

3738
if (maybeReply.isPresent()) {
3839
Actor.Reply reply = maybeReply.get();
39-
assertNotNull(reply);
40-
assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
40+
Assertions.assertNotNull(reply);
41+
Assertions.assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
4142
}
4243
}
4344

4445
@Test
45-
public void testUnNamedInvocation() throws ActorCreationException, ActorInvocationException {
46+
void testUnNamedInvocation() throws ActorCreationException, ActorInvocationException {
4647
ActorRef unNamedJoeActor = spawnSystem.createActorRef(
4748
ActorIdentity.of(spawnSystemName, "UnNamedJoeActor", "UnNamedActor"));
4849

4950
Class type = unNamedJoeActor.getType();
5051

51-
assertEquals(type, UnNamedActor.class);
52-
assertNotNull(unNamedJoeActor);
52+
Assertions.assertEquals(type, UnNamedActor.class);
53+
Assertions.assertNotNull(unNamedJoeActor);
5354

5455
Actor.Request msg = Actor.Request.newBuilder()
5556
.setLanguage("Erlang")
@@ -60,20 +61,20 @@ public void testUnNamedInvocation() throws ActorCreationException, ActorInvocati
6061

6162
if (maybeReply.isPresent()) {
6263
Actor.Reply reply = maybeReply.get();
63-
assertNotNull(reply);
64-
assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
64+
Assertions.assertNotNull(reply);
65+
Assertions.assertEquals("Hi Erlang. Hello From Java", reply.getResponse());
6566
}
6667
}
6768

6869
@Test
69-
public void testStatelessInvocation() throws ActorCreationException, ActorInvocationException {
70+
void testStatelessInvocation() throws ActorCreationException, ActorInvocationException {
7071
ActorRef statelessNamedActor = spawnSystem.createActorRef(
7172
ActorIdentity.of(spawnSystemName, "StatelessNamedActor"));
7273

7374
Class type = statelessNamedActor.getType();
7475

75-
assertEquals(type, StatelessNamedActor.class);
76-
assertNotNull(statelessNamedActor);
76+
Assertions.assertEquals(type, StatelessNamedActor.class);
77+
Assertions.assertNotNull(statelessNamedActor);
7778

7879
Actor.Request msg = Actor.Request.newBuilder()
7980
.setLanguage("Elixir")
@@ -84,8 +85,8 @@ public void testStatelessInvocation() throws ActorCreationException, ActorInvoca
8485

8586
if (maybeReply.isPresent()) {
8687
Actor.Reply reply = maybeReply.get();
87-
assertNotNull(reply);
88-
assertEquals("Hi Elixir. Hello From Java", reply.getResponse());
88+
Assertions.assertNotNull(reply);
89+
Assertions.assertEquals("Hi Elixir. Hello From Java", reply.getResponse());
8990
}
9091
}
9192
}

src/test/java/io/eigr/spawn/WorkflowTest.java

+18-19
Original file line numberDiff line numberDiff line change
@@ -9,52 +9,51 @@
99
import io.eigr.spawn.api.actors.workflows.SideEffect;
1010
import io.eigr.spawn.api.exceptions.SpawnException;
1111
import io.eigr.spawn.java.test.domain.Actor;
12-
import org.junit.Before;
13-
import org.junit.Test;
12+
import org.junit.jupiter.api.Assertions;
13+
import org.junit.jupiter.api.BeforeEach;
14+
import org.junit.jupiter.api.Test;
1415

15-
import static org.junit.Assert.*;
16-
17-
public class WorkflowTest extends AbstractContainerBaseTest {
16+
class WorkflowTest extends AbstractContainerBaseTest {
1817

1918
private ActorRef joeActorRef;
2019

21-
@Before
20+
@BeforeEach
2221
public void before() throws SpawnException {
2322
joeActorRef = spawnSystem.createActorRef(
2423
ActorIdentity.of(spawnSystemName, "JoeActor"));
2524
}
2625

2726
@Test
28-
public void testBroadcastBuilder() {
27+
void testBroadcastBuilder() {
2928
Broadcast broadcast = Broadcast.to("test.channel", "hi", Actor.Request.getDefaultInstance());
3029
final Protocol.Broadcast protocolBroadcast = broadcast.build();
31-
assertEquals("test.channel", protocolBroadcast.getChannelGroup());
32-
assertNotNull(protocolBroadcast.getValue());
30+
Assertions.assertEquals("test.channel", protocolBroadcast.getChannelGroup());
31+
Assertions.assertNotNull(protocolBroadcast.getValue());
3332
}
3433

3534
@Test
36-
public void testForwardBuilder() throws Exception {
35+
void testForwardBuilder() throws Exception {
3736
Forward forward = Forward.to(joeActorRef, "hi");
3837
final Protocol.Forward protocolForward = forward.build();
39-
assertEquals("hi", protocolForward.getActionName());
40-
assertEquals("JoeActor", protocolForward.getActor());
38+
Assertions.assertEquals("hi", protocolForward.getActionName());
39+
Assertions.assertEquals("JoeActor", protocolForward.getActor());
4140
}
4241

4342
@Test
44-
public void testPipeBuilder() throws Exception {
43+
void testPipeBuilder() throws Exception {
4544
Pipe pipe = Pipe.to(joeActorRef, "hi");
4645
final Protocol.Pipe protocolPipe = pipe.build();
47-
assertEquals("hi", protocolPipe.getActionName());
48-
assertEquals("JoeActor", protocolPipe.getActor());
46+
Assertions.assertEquals("hi", protocolPipe.getActionName());
47+
Assertions.assertEquals("JoeActor", protocolPipe.getActor());
4948
}
5049

5150
@Test
52-
public void testSideEffectBuilder() throws Exception {
51+
void testSideEffectBuilder() throws Exception {
5352
SideEffect effect = SideEffect.to(joeActorRef, "hi", Actor.Request.getDefaultInstance());
5453
final Protocol.SideEffect protocolSideEffect = effect.build();
5554
Protocol.InvocationRequest request = protocolSideEffect.getRequest();
56-
assertNotNull(request);
57-
assertEquals("hi", request.getActionName());
58-
assertEquals("JoeActor", request.getActor().getId().getName());
55+
Assertions.assertNotNull(request);
56+
Assertions.assertEquals("hi", request.getActionName());
57+
Assertions.assertEquals("JoeActor", request.getActor().getId().getName());
5958
}
6059
}

0 commit comments

Comments
 (0)