Skip to content

Commit

Permalink
fix: remove wrong verify logic (#1433)
Browse files Browse the repository at this point in the history
Co-authored-by: Lo1nt <[email protected]>
  • Loading branch information
Lo1nt and Lo1nt committed Aug 2, 2024
1 parent ff2471e commit 2d8190f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
Expand All @@ -37,20 +35,16 @@
*/
public class NettyBatchWriteQueueTest {

@Mock
private Channel mockChannel;
private Channel mockChannel = Mockito.mock(Channel.class);

@Mock
private EventLoop mockEventLoop;
private EventLoop mockEventLoop = Mockito.mock(EventLoop.class);

@Mock
private ChannelPromise mockChannelPromise;
private ChannelPromise mockChannelPromise = Mockito.mock(ChannelPromise.class);

private NettyBatchWriteQueue nettyBatchWriteQueue;
private NettyBatchWriteQueue nettyBatchWriteQueue = Mockito.mock(NettyBatchWriteQueue.class);

@Before
public void setUp() {
MockitoAnnotations.initMocks(this);
when(mockChannel.eventLoop()).thenReturn(mockEventLoop);
when(mockChannel.newPromise()).thenReturn(mockChannelPromise);
nettyBatchWriteQueue = NettyBatchWriteQueue.createWriteQueue(mockChannel);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
*/
package com.alipay.sofa.rpc.transport.netty;

import com.alipay.sofa.rpc.common.utils.NetUtils;
import io.netty.buffer.PooledByteBufAllocator;
import io.netty.channel.Channel;
import io.netty.channel.ChannelFuture;
Expand All @@ -27,13 +26,9 @@
import org.junit.Before;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mock;
import org.mockito.Mockito;

import java.net.InetSocketAddress;

import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.when;

/**
Expand All @@ -42,16 +37,12 @@
*/
public class NettyChannelTest {

@Mock
private Channel mockChannel = Mockito.mock(Channel.class);

@Mock
private ChannelHandlerContext mockContext = Mockito.mock(ChannelHandlerContext.class);

@Mock
private NettyBatchWriteQueue mockWriteQueue = Mockito.mock(NettyBatchWriteQueue.class);

@Mock
private ChannelFuture mockFuture = Mockito.mock(ChannelFuture.class);

private NettyChannel nettyChannel;
Expand All @@ -62,6 +53,7 @@ public void setUp() {
Mockito.when(mockChannel.alloc()).thenReturn(PooledByteBufAllocator.DEFAULT);
when(mockContext.channel()).thenReturn(mockChannel);
when(mockWriteQueue.enqueue(any())).thenReturn(mockFuture);

nettyChannel = new NettyChannel(mockChannel);
nettyChannel.setWriteQueue(mockWriteQueue);
}
Expand All @@ -80,8 +72,8 @@ public void testRunSuccess() throws Exception {
listener.operationComplete((Future) mockFuture);

// 验证没有错误日志被记录(因为操作是成功的)
Mockito.verify(Mockito.mock(NetUtils.class), times(10));
NetUtils.channelToString(any(InetSocketAddress.class), any(InetSocketAddress.class));
// Mockito.verify(Mockito.mock(NetUtils.class), times(10));
// NetUtils.channelToString(any(InetSocketAddress.class), any(InetSocketAddress.class));
}

}

0 comments on commit 2d8190f

Please sign in to comment.