This is an automated email from the ASF dual-hosted git repository.
ppkarwasz pushed a commit to branch towards17
in repository https://gitbox.apache.org/repos/asf/logging-flume.git
The following commit(s) were added to refs/heads/towards17 by this push:
new a5c110c7c Fix: replace Mockito mock with `DummySession`
a5c110c7c is described below
commit a5c110c7c47e2d0d12faa265c880193ab3090bc9
Author: Piotr P. Karwasz <[email protected]>
AuthorDate: Fri May 29 20:31:02 2026 +0200
Fix: replace Mockito mock with `DummySession`
With the old Mockito `TestMultiportSyslogTCPSource` worked, because Mockito
was unable to mock final methods and the real methods were called.
Now Mockito inline is able to mock final methods and operations essential
for the test fail.
---
.../org/apache/flume/source/TestMultiportSyslogTCPSource.java | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git
a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
b/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
index 84adaf8b7..b6f63e13f 100644
---
a/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
+++
b/flume-ng-core/src/test/java/org/apache/flume/source/TestMultiportSyslogTCPSource.java
@@ -61,14 +61,13 @@ import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.apache.mina.core.buffer.IoBuffer;
import org.apache.mina.core.session.DefaultIoSessionDataStructureFactory;
-import org.apache.mina.transport.socket.nio.NioSession;
+import org.apache.mina.core.session.DummySession;
import org.junit.Assert;
import org.junit.Ignore;
import org.junit.Test;
import org.mockito.Mockito;
import org.apache.flume.util.Whitebox;
-import static java.time.ZoneOffset.UTC;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
@@ -460,17 +459,17 @@ public class TestMultiportSyslogTCPSource {
// one faker on port 10001
int port1 = 10001;
- NioSession session1 = mock(NioSession.class);
+ DummySession session1 = new DummySession();
session1.setAttributeMap(dsFactory.getAttributeMap(session1));
SocketAddress sockAddr1 = new InetSocketAddress(localAddr, port1);
- when(session1.getLocalAddress()).thenReturn(sockAddr1);
+ session1.setLocalAddress(sockAddr1);
// another faker on port 10002
int port2 = 10002;
- NioSession session2 = mock(NioSession.class);
+ DummySession session2 = new DummySession();
session2.setAttributeMap(dsFactory.getAttributeMap(session2));
SocketAddress sockAddr2 = new InetSocketAddress(localAddr, port2);
- when(session2.getLocalAddress()).thenReturn(sockAddr2);
+ session2.setLocalAddress(sockAddr2);
// set up expected charsets per port
ConcurrentMap<Integer, ThreadSafeDecoder> portCharsets =