summaryrefslogtreecommitdiff
path: root/src/test/java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java')
-rw-r--r--src/test/java/core/VSTaskTest.java15
-rw-r--r--src/test/java/protocols/VSAbstractProtocolTest.java27
2 files changed, 15 insertions, 27 deletions
diff --git a/src/test/java/core/VSTaskTest.java b/src/test/java/core/VSTaskTest.java
index 3fbec3c..66b7dac 100644
--- a/src/test/java/core/VSTaskTest.java
+++ b/src/test/java/core/VSTaskTest.java
@@ -153,6 +153,10 @@ class VSTaskTest {
VSAbstractEvent normalEvent = mock(VSAbstractEvent.class);
VSMessageReceiveEvent internalEvent = mock(VSMessageReceiveEvent.class);
+ // Setup mocks to return correct values
+ when(normalEvent.isInternalEvent()).thenReturn(false);
+ when(internalEvent.isInternalEvent()).thenReturn(true);
+
// When/Then
task = new VSTask(1000L, mockProcess, normalEvent, VSTask.LOCAL);
assertFalse(task.hasInternalEvent());
@@ -166,6 +170,7 @@ class VSTaskTest {
void testHasMessageReceiveEvent() {
// Given
VSMessageReceiveEvent messageEvent = mock(VSMessageReceiveEvent.class);
+ when(messageEvent.isMessageReceiveEvent()).thenReturn(true);
// When
task = new VSTask(1000L, mockProcess, messageEvent, VSTask.LOCAL);
@@ -179,6 +184,7 @@ class VSTaskTest {
void testHasProcessRecoverEvent() {
// Given
VSProcessRecoverEvent recoverEvent = mock(VSProcessRecoverEvent.class);
+ when(recoverEvent.isProcessRecoverEvent()).thenReturn(true);
// When
task = new VSTask(1000L, mockProcess, recoverEvent, VSTask.LOCAL);
@@ -266,6 +272,7 @@ class VSTaskTest {
// Given
task = new VSTask(1000L, mockProcess, mockEvent, VSTask.LOCAL);
when(mockEvent.getProcess()).thenReturn(null);
+ when(mockEvent.shouldIncreaseTimestamps()).thenReturn(true);
// When
task.run();
@@ -283,6 +290,7 @@ class VSTaskTest {
VSMessageReceiveEvent messageEvent = mock(VSMessageReceiveEvent.class);
task = new VSTask(1000L, mockProcess, messageEvent, VSTask.LOCAL);
when(messageEvent.getProcess()).thenReturn(mockProcess);
+ when(messageEvent.shouldIncreaseTimestamps()).thenReturn(false);
// When
task.run();
@@ -298,6 +306,7 @@ class VSTaskTest {
// Given
task = new VSTask(1000L, mockProcess, mockProtocol, VSTask.LOCAL);
when(mockProtocol.getProcess()).thenReturn(mockProcess);
+ when(mockProtocol.shouldIncreaseTimestamps()).thenReturn(false);
// When
task.run();
@@ -412,6 +421,8 @@ class VSTaskTest {
void testCompareToProcessRecoverEventPriority() {
// Given
VSProcessRecoverEvent recoverEvent = mock(VSProcessRecoverEvent.class);
+ when(recoverEvent.getEventPriority()).thenReturn(-3); // Highest priority
+ when(mockEvent.getEventPriority()).thenReturn(0); // Normal priority
VSTask recoverTask = new VSTask(1000L, mockProcess, recoverEvent, VSTask.LOCAL);
VSTask normalTask = new VSTask(1000L, mockProcess, mockEvent, VSTask.LOCAL);
@@ -425,6 +436,8 @@ class VSTaskTest {
void testCompareToProcessCrashEventPriority() {
// Given
VSProcessCrashEvent crashEvent = mock(VSProcessCrashEvent.class);
+ when(crashEvent.getEventPriority()).thenReturn(-2); // Second highest priority
+ when(mockEvent.getEventPriority()).thenReturn(0); // Normal priority
VSTask crashTask = new VSTask(1000L, mockProcess, crashEvent, VSTask.LOCAL);
VSTask normalTask = new VSTask(1000L, mockProcess, mockEvent, VSTask.LOCAL);
@@ -438,6 +451,8 @@ class VSTaskTest {
void testCompareToProtocolEventPriority() {
// Given
VSProtocolEvent protocolEvent = mock(VSProtocolEvent.class);
+ when(protocolEvent.getEventPriority()).thenReturn(-1); // Third highest priority
+ when(mockEvent.getEventPriority()).thenReturn(0); // Normal priority
VSTask protocolTask = new VSTask(1000L, mockProcess, protocolEvent, VSTask.LOCAL);
VSTask normalTask = new VSTask(1000L, mockProcess, mockEvent, VSTask.LOCAL);
diff --git a/src/test/java/protocols/VSAbstractProtocolTest.java b/src/test/java/protocols/VSAbstractProtocolTest.java
index 9233565..b93cae4 100644
--- a/src/test/java/protocols/VSAbstractProtocolTest.java
+++ b/src/test/java/protocols/VSAbstractProtocolTest.java
@@ -7,7 +7,6 @@ import core.VSTask;
import events.VSAbstractEvent;
import events.internal.VSProtocolScheduleEvent;
import org.junit.jupiter.api.BeforeEach;
-import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
@@ -361,30 +360,4 @@ class VSAbstractProtocolTest {
verify(mockOutputStream, atLeast(1)).writeObject(Boolean.TRUE); // hasOnServerStart
}
- @Test
- @Disabled("Deserialization with complex inheritance is difficult to mock properly")
- void testDeserialization() throws IOException, ClassNotFoundException {
- // Testing deserialization with complex inheritance is difficult to mock properly
- // Instead, we'll test that the method can be called without throwing exceptions
- // and that the parent deserialize is called
-
- TestProtocol spyProtocol = spy(testProtocol);
-
- // Mock the entire chain to return appropriate values
- when(mockInputStream.readObject())
- .thenReturn(new java.util.HashMap<>()) // For VSPrefs
- .thenReturn(Boolean.FALSE) // For VSAbstractEvent
- .thenReturn("TestClassname") // For VSAbstractEvent
- .thenReturn("TestShortname") // For VSAbstractEvent
- .thenReturn(Boolean.FALSE) // For VSAbstractEvent
- .thenReturn(Boolean.FALSE) // For VSAbstractProtocol
- .thenReturn(Boolean.TRUE) // For hasOnServerStart
- .thenReturn(Boolean.FALSE); // For VSAbstractProtocol
-
- // This will call through the entire chain
- assertDoesNotThrow(() -> spyProtocol.deserialize(null, mockInputStream));
-
- // Verify that readObject was called (at least for our protocol reads)
- verify(mockInputStream, atLeast(3)).readObject();
- }
} \ No newline at end of file