Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
Apache RocketMQ
Rocketmq
提交
bbcb69ec
R
Rocketmq
项目概览
Apache RocketMQ
/
Rocketmq
上一次同步 大约 3 年
通知
267
Star
16139
Fork
68
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rocketmq
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
提交
bbcb69ec
编写于
1月 17, 2017
作者:
Y
yukon
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[ROCKETMQ-52] Use MockitoJUnitRunner with Mock
上级
032bb2b3
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
30 addition
and
34 deletion
+30
-34
client/src/test/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStoreTest.java
...ketmq/client/consumer/store/LocalFileOffsetStoreTest.java
+10
-9
client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java
...mq/client/consumer/store/RemoteBrokerOffsetStoreTest.java
+11
-12
client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
.../org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
+9
-10
client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java
...he/rocketmq/client/impl/factory/MQClientInstanceTest.java
+0
-3
未找到文件。
client/src/test/java/org/apache/rocketmq/client/consumer/store/LocalFileOffsetStoreTest.java
浏览文件 @
bbcb69ec
...
@@ -21,25 +21,26 @@ import java.util.HashSet;
...
@@ -21,25 +21,26 @@ import java.util.HashSet;
import
org.apache.rocketmq.client.ClientConfig
;
import
org.apache.rocketmq.client.ClientConfig
;
import
org.apache.rocketmq.client.impl.factory.MQClientInstance
;
import
org.apache.rocketmq.client.impl.factory.MQClientInstance
;
import
org.apache.rocketmq.common.message.MessageQueue
;
import
org.apache.rocketmq.common.message.MessageQueue
;
import
org.junit.Before
Class
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.
Mockito
;
import
org.mockito.
junit.MockitoJUnitRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
LocalFileOffsetStoreTest
{
public
class
LocalFileOffsetStoreTest
{
@Mock
@Mock
private
static
MQClientInstance
mQClientFactory
;
private
MQClientInstance
mQClientFactory
;
private
static
String
group
=
"FooBarGroup"
;
private
String
group
=
"FooBarGroup"
;
private
static
String
topic
=
"FooBar"
;
private
String
topic
=
"FooBar"
;
private
static
String
brokerName
=
"DefaultBrokerName"
;
private
String
brokerName
=
"DefaultBrokerName"
;
@Before
Class
@Before
public
static
void
init
()
{
public
void
init
()
{
System
.
setProperty
(
"rocketmq.client.localOffsetStoreDir"
,
System
.
getProperty
(
"java.io.tmpdir"
)
+
".rocketmq_offsets"
);
System
.
setProperty
(
"rocketmq.client.localOffsetStoreDir"
,
System
.
getProperty
(
"java.io.tmpdir"
)
+
".rocketmq_offsets"
);
mQClientFactory
=
Mockito
.
mock
(
MQClientInstance
.
class
);
String
clientId
=
new
ClientConfig
().
buildMQClientId
()
+
"#TestNamespace"
+
System
.
currentTimeMillis
();
String
clientId
=
new
ClientConfig
().
buildMQClientId
()
+
"#TestNamespace"
+
System
.
currentTimeMillis
();
when
(
mQClientFactory
.
getClientId
()).
thenReturn
(
clientId
);
when
(
mQClientFactory
.
getClientId
()).
thenReturn
(
clientId
);
}
}
...
...
client/src/test/java/org/apache/rocketmq/client/consumer/store/RemoteBrokerOffsetStoreTest.java
浏览文件 @
bbcb69ec
...
@@ -27,10 +27,12 @@ import org.apache.rocketmq.common.message.MessageQueue;
...
@@ -27,10 +27,12 @@ import org.apache.rocketmq.common.message.MessageQueue;
import
org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader
;
import
org.apache.rocketmq.common.protocol.header.QueryConsumerOffsetRequestHeader
;
import
org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader
;
import
org.apache.rocketmq.common.protocol.header.UpdateConsumerOffsetRequestHeader
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.junit.Before
Class
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.stubbing.Answer
;
import
org.mockito.stubbing.Answer
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -39,27 +41,24 @@ import static org.mockito.ArgumentMatchers.anyLong;
...
@@ -39,27 +41,24 @@ import static org.mockito.ArgumentMatchers.anyLong;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
ArgumentMatchers
.
anyString
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
import
static
org
.
mockito
.
Mockito
.
when
;
import
static
org
.
mockito
.
Mockito
.
when
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
RemoteBrokerOffsetStoreTest
{
public
class
RemoteBrokerOffsetStoreTest
{
@Mock
@Mock
private
static
MQClientInstance
mQClientFactory
;
private
MQClientInstance
mQClientFactory
;
@Mock
@Mock
private
static
MQClientAPIImpl
mqClientAPI
;
private
MQClientAPIImpl
mqClientAPI
;
private
static
String
group
=
"FooBarGroup"
;
private
String
group
=
"FooBarGroup"
;
private
static
String
topic
=
"FooBar"
;
private
String
topic
=
"FooBar"
;
private
static
String
brokerName
=
"DefaultBrokerName"
;
private
String
brokerName
=
"DefaultBrokerName"
;
@Before
Class
@Before
public
static
void
init
()
{
public
void
init
()
{
System
.
setProperty
(
"rocketmq.client.localOffsetStoreDir"
,
System
.
getProperty
(
"java.io.tmpdir"
)
+
".rocketmq_offsets"
);
System
.
setProperty
(
"rocketmq.client.localOffsetStoreDir"
,
System
.
getProperty
(
"java.io.tmpdir"
)
+
".rocketmq_offsets"
);
mQClientFactory
=
mock
(
MQClientInstance
.
class
);
String
clientId
=
new
ClientConfig
().
buildMQClientId
()
+
"#TestNamespace"
+
System
.
currentTimeMillis
();
String
clientId
=
new
ClientConfig
().
buildMQClientId
()
+
"#TestNamespace"
+
System
.
currentTimeMillis
();
when
(
mQClientFactory
.
getClientId
()).
thenReturn
(
clientId
);
when
(
mQClientFactory
.
getClientId
()).
thenReturn
(
clientId
);
when
(
mQClientFactory
.
findBrokerAddressInAdmin
(
brokerName
)).
thenReturn
(
new
FindBrokerResult
(
"127.0.0.1"
,
false
));
when
(
mQClientFactory
.
findBrokerAddressInAdmin
(
brokerName
)).
thenReturn
(
new
FindBrokerResult
(
"127.0.0.1"
,
false
));
mqClientAPI
=
mock
(
MQClientAPIImpl
.
class
);
when
(
mQClientFactory
.
getMQClientAPIImpl
()).
thenReturn
(
mqClientAPI
);
when
(
mQClientFactory
.
getMQClientAPIImpl
()).
thenReturn
(
mqClientAPI
);
}
}
...
...
client/src/test/java/org/apache/rocketmq/client/impl/MQClientAPIImplTest.java
浏览文件 @
bbcb69ec
...
@@ -35,13 +35,14 @@ import org.apache.rocketmq.remoting.RemotingClient;
...
@@ -35,13 +35,14 @@ import org.apache.rocketmq.remoting.RemotingClient;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.exception.RemotingTimeoutException
;
import
org.apache.rocketmq.remoting.exception.RemotingTimeoutException
;
import
org.apache.rocketmq.remoting.netty.NettyClientConfig
;
import
org.apache.rocketmq.remoting.netty.NettyClientConfig
;
import
org.apache.rocketmq.remoting.netty.NettyRemotingClient
;
import
org.apache.rocketmq.remoting.netty.ResponseFuture
;
import
org.apache.rocketmq.remoting.netty.ResponseFuture
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.apache.rocketmq.remoting.protocol.RemotingCommand
;
import
org.junit.Before
Class
;
import
org.junit.Before
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.mockito.Mock
;
import
org.mockito.Mock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.invocation.InvocationOnMock
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.stubbing.Answer
;
import
org.mockito.stubbing.Answer
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -52,14 +53,14 @@ import static org.mockito.ArgumentMatchers.anyString;
...
@@ -52,14 +53,14 @@ import static org.mockito.ArgumentMatchers.anyString;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
doAnswer
;
import
static
org
.
mockito
.
Mockito
.
doNothing
;
import
static
org
.
mockito
.
Mockito
.
doNothing
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
doThrow
;
import
static
org
.
mockito
.
Mockito
.
mock
;
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MQClientAPIImplTest
{
public
class
MQClientAPIImplTest
{
private
static
MQClientAPIImpl
mqClientAPI
=
new
MQClientAPIImpl
(
new
NettyClientConfig
(),
null
,
null
,
new
ClientConfig
());
private
MQClientAPIImpl
mqClientAPI
=
new
MQClientAPIImpl
(
new
NettyClientConfig
(),
null
,
null
,
new
ClientConfig
());
@Mock
@Mock
private
static
RemotingClient
remotingClient
;
private
RemotingClient
remotingClient
;
@Mock
@Mock
private
static
DefaultMQProducerImpl
defaultMQProducerImpl
;
private
DefaultMQProducerImpl
defaultMQProducerImpl
;
private
String
brokerAddr
=
"127.0.0.1"
;
private
String
brokerAddr
=
"127.0.0.1"
;
private
String
brokerName
=
"DefaultBroker"
;
private
String
brokerName
=
"DefaultBroker"
;
...
@@ -67,10 +68,8 @@ public class MQClientAPIImplTest {
...
@@ -67,10 +68,8 @@ public class MQClientAPIImplTest {
private
static
String
topic
=
"FooBar"
;
private
static
String
topic
=
"FooBar"
;
private
Message
msg
=
new
Message
(
"FooBar"
,
new
byte
[]
{});
private
Message
msg
=
new
Message
(
"FooBar"
,
new
byte
[]
{});
@BeforeClass
@Before
public
static
void
init
()
throws
Exception
{
public
void
init
()
throws
Exception
{
remotingClient
=
mock
(
NettyRemotingClient
.
class
);
defaultMQProducerImpl
=
mock
(
DefaultMQProducerImpl
.
class
);
Field
field
=
MQClientAPIImpl
.
class
.
getDeclaredField
(
"remotingClient"
);
Field
field
=
MQClientAPIImpl
.
class
.
getDeclaredField
(
"remotingClient"
);
field
.
setAccessible
(
true
);
field
.
setAccessible
(
true
);
field
.
set
(
mqClientAPI
,
remotingClient
);
field
.
set
(
mqClientAPI
,
remotingClient
);
...
...
client/src/test/java/org/apache/rocketmq/client/impl/factory/MQClientInstanceTest.java
浏览文件 @
bbcb69ec
...
@@ -32,7 +32,6 @@ import org.apache.rocketmq.common.protocol.route.TopicRouteData;
...
@@ -32,7 +32,6 @@ import org.apache.rocketmq.common.protocol.route.TopicRouteData;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.apache.rocketmq.remoting.exception.RemotingException
;
import
org.junit.Test
;
import
org.junit.Test
;
import
org.junit.runner.RunWith
;
import
org.junit.runner.RunWith
;
import
org.mockito.InjectMocks
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
org.mockito.junit.MockitoJUnitRunner
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
import
static
org
.
assertj
.
core
.
api
.
Assertions
.
assertThat
;
...
@@ -40,9 +39,7 @@ import static org.mockito.Mockito.mock;
...
@@ -40,9 +39,7 @@ import static org.mockito.Mockito.mock;
@RunWith
(
MockitoJUnitRunner
.
class
)
@RunWith
(
MockitoJUnitRunner
.
class
)
public
class
MQClientInstanceTest
{
public
class
MQClientInstanceTest
{
@InjectMocks
private
MQClientInstance
mqClientInstance
=
MQClientManager
.
getInstance
().
getAndCreateMQClientInstance
(
new
ClientConfig
());;
private
MQClientInstance
mqClientInstance
=
MQClientManager
.
getInstance
().
getAndCreateMQClientInstance
(
new
ClientConfig
());;
private
String
topic
=
"FooBar"
;
private
String
topic
=
"FooBar"
;
private
String
group
=
"FooBarGroup"
;
private
String
group
=
"FooBarGroup"
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录