本文整理匯總了Java中org.easymock.EasyMock.createMock方法的典型用法代碼示例。如果您正苦於以下問題:Java EasyMock.createMock方法的具體用法?Java EasyMock.createMock怎麽用?Java EasyMock.createMock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.easymock.EasyMock
的用法示例。
在下文中一共展示了EasyMock.createMock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: test
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void test() {
KafkaCruiseControl mockKCC = EasyMock.createMock(KafkaCruiseControl.class);
KafkaCruiseControlState kccState = getState(_numReadyGoals, _totalGoals, _numValidWindows);
EasyMock.expect(mockKCC.state()).andReturn(kccState).anyTimes();
EasyMock.replay(mockKCC);
KafkaCruiseControlServlet servlet = new KafkaCruiseControlServlet(mockKCC);
KafkaCruiseControlServlet.GoalsAndRequirements goalsAndRequirements =
servlet.getGoalsAndRequirements(Collections.emptyList(),
_dataFrom,
false);
assertEquals(new HashSet<>(goalsAndRequirements.goals()), new HashSet<>(_expectedGoalsToUse));
if (_expectedRequirements != null) {
assertEquals(_expectedRequirements.minRequiredNumSnapshotWindows(),
goalsAndRequirements.requirements().minRequiredNumSnapshotWindows());
assertEquals(_expectedRequirements.minMonitoredPartitionsPercentage(),
goalsAndRequirements.requirements().minMonitoredPartitionsPercentage(), 0.0);
assertEquals(_expectedRequirements.includeAllTopics(),
goalsAndRequirements.requirements().includeAllTopics());
} else {
assertNull("The requirement should be null", goalsAndRequirements.requirements());
}
}
示例2: testInvokerGeneric
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testInvokerGeneric() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
Result filterResult = compatibleFilter.invoke(invoker, invocation);
assertEquals(filterResult, result);
}
示例3: testRpcException
import org.easymock.EasyMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testRpcException() {
Logger logger = EasyMock.createMock(Logger.class);
RpcContext.getContext().setRemoteAddress("127.0.0.1", 1234);
RpcException exception = new RpcException("TestRpcException");
logger.error(EasyMock.eq("Got unchecked and undeclared exception which called by 127.0.0.1. service: " + DemoService.class.getName() + ", method: sayHello, exception: " + RpcException.class.getName() + ": TestRpcException"), EasyMock.eq(exception));
ExceptionFilter exceptionFilter = new ExceptionFilter(logger);
RpcInvocation invocation = new RpcInvocation("sayHello", new Class<?>[]{String.class}, new Object[]{"world"});
Invoker<DemoService> invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class);
EasyMock.expect(invoker.invoke(EasyMock.eq(invocation))).andThrow(exception);
EasyMock.replay(logger, invoker);
try {
exceptionFilter.invoke(invoker, invocation);
} catch (RpcException e) {
assertEquals("TestRpcException", e.getMessage());
}
EasyMock.verify(logger, invoker);
RpcContext.removeContext();
}
示例4: testSetContext
import org.easymock.EasyMock; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
@Test
public void testSetContext() {
invocation = EasyMock.createMock(Invocation.class);
EasyMock.expect(invocation.getMethodName()).andReturn("$enumlength").anyTimes();
EasyMock.expect(invocation.getParameterTypes()).andReturn(new Class<?>[] { Enum.class }).anyTimes();
EasyMock.expect(invocation.getArguments()).andReturn(new Object[] { "hello" }).anyTimes();
EasyMock.expect(invocation.getAttachments()).andReturn(null).anyTimes();
EasyMock.replay(invocation);
invoker = EasyMock.createMock(Invoker.class);
EasyMock.expect(invoker.isAvailable()).andReturn(true).anyTimes();
EasyMock.expect(invoker.getInterface()).andReturn(DemoService.class).anyTimes();
RpcResult result = new RpcResult();
result.setValue("High");
EasyMock.expect(invoker.invoke(invocation)).andReturn(result).anyTimes();
URL url = URL.valueOf("test://test:11/test?group=dubbo&version=1.1");
EasyMock.expect(invoker.getUrl()).andReturn(url).anyTimes();
EasyMock.replay(invoker);
contextFilter.invoke(invoker, invocation);
assertNull(RpcContext.getContext().getInvoker());
}
示例5: testNoInvoke
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test()
public void testNoInvoke() {
dic = EasyMock.createMock(Directory.class);
EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
EasyMock.expect(dic.getInterface()).andReturn(DemoService.class).anyTimes();
invocation.setMethodName("method1");
EasyMock.replay(dic);
resetInvokerToNoException();
FailsafeClusterInvoker<DemoService> invoker = new FailsafeClusterInvoker<DemoService>(dic);
LogUtil.start();
invoker.invoke(invocation);
assertTrue(LogUtil.findMessage("No provider") > 0);
LogUtil.stop();
}
示例6: setupMock
import org.easymock.EasyMock; //導入方法依賴的package包/類
private ClientFactory setupMock() throws Exception {
ArrayList<CMODataTransport> transports = new ArrayList<>();
transports.add(new CMODataTransport("L21K900026", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K900028", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K900029", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K90002A", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K90002B", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K90002C", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K90002D", false, "Description", "Owner"));
transports.add(new CMODataTransport("L21K90002E", true, "Description", "Owner"));
CMODataClient clientMock = createMock(CMODataClient.class);
expect(clientMock.getChangeTransports(capture(changeId))).andReturn(transports);
ClientFactory factoryMock = EasyMock.createMock(ClientFactory.class);
expect(factoryMock
.newClient(capture(host),
capture(user),
capture(password))).andReturn(clientMock);
clientMock.close(); expectLastCall();
replay(clientMock, factoryMock);
return factoryMock;
}
示例7: testNoInvoke
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test()
public void testNoInvoke() {
dic = EasyMock.createMock(Directory.class);
EasyMock.expect(dic.getUrl()).andReturn(url).anyTimes();
EasyMock.expect(dic.list(invocation)).andReturn(null).anyTimes();
EasyMock.expect(dic.getInterface()).andReturn(FailoverClusterInvokerTest.class).anyTimes();
invocation.setMethodName("method1");
EasyMock.replay(dic);
invokers.add(invoker1);
FailoverClusterInvoker<FailoverClusterInvokerTest> invoker = new FailoverClusterInvoker<FailoverClusterInvokerTest>(dic);
try {
invoker.invoke(invocation);
fail();
} catch (RpcException expected) {
assertFalse(expected.getCause() instanceof RpcException);
}
}
示例8: testCloseAvailablecheck
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testCloseAvailablecheck() {
LoadBalance lb = EasyMock.createMock(LoadBalance.class);
EasyMock.expect(lb.select(invokers, url, invocation)).andReturn(invoker1);
EasyMock.replay(lb);
initlistsize5();
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
Assert.assertEquals(false, sinvoker.isAvailable());
Assert.assertEquals(invoker1, sinvoker);
}
示例9: testChangeLogLevel
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testChangeLogLevel() throws RemotingException {
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.replay(mockChannel);
String result = log.telnet(mockChannel, "error");
assertTrue(result.contains("\r\nCURRENT LOG LEVEL:ERROR"));
String result2 = log.telnet(mockChannel, "warn");
assertTrue(result2.contains("\r\nCURRENT LOG LEVEL:WARN"));
EasyMock.reset(mockChannel);
}
示例10: testMessageError
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testMessageError() throws RemotingException {
mockChannel = EasyMock.createMock(Channel.class);
EasyMock.expect(mockChannel.getAttribute("telnet.service")).andReturn(null).anyTimes();
EasyMock.replay(mockChannel);
String result = count.telnet(mockChannel, "test");
assertEquals("Unsupported parameter test for pwd.", result);
}
示例11: setUp
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
isisHeader = new IsisHeader();
isisHeader.setIsisPduType(IsisPduType.L1PSNP.value());
psnp = new Psnp(isisHeader);
tlvHeader = new TlvHeader();
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
isisTlv = new AdjacencyStateTlv(tlvHeader);
}
示例12: testCloseAvailablecheck
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Test
public void testCloseAvailablecheck(){
LoadBalance lb = EasyMock.createMock(LoadBalance.class);
EasyMock.expect(lb.select(invokers, url, invocation)).andReturn(invoker1);
EasyMock.replay(lb);
initlistsize5();
Invoker sinvoker = cluster_nocheck.select(lb, invocation, invokers, selectedInvokers);
Assert.assertEquals(false,sinvoker.isAvailable());
Assert.assertEquals(invoker1,sinvoker);
}
示例13: testChannelConnected
import org.easymock.EasyMock; //導入方法依賴的package包/類
/**
* Tests channelConnected() method.
*/
@Test(expected = Exception.class)
public void testChannelConnected() throws Exception {
channelHandlerContext = EasyMock.createMock(ChannelHandlerContext.class);
channelStateEvent = EasyMock.createMock(ChannelStateEvent.class);
ospfInterfaceChannelHandler.channelConnected(channelHandlerContext, channelStateEvent);
}
示例14: setUp
import org.easymock.EasyMock; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
tlvHeader = new TlvHeader();
tlvHeader.setTlvLength(tlv.length);
hostNameTlv = new HostNameTlv(tlvHeader);
channelBuffer = EasyMock.createMock(ChannelBuffer.class);
}
示例15: testTruncateIfSizeIsDifferentToTargetSize
import org.easymock.EasyMock; //導入方法依賴的package包/類
/**
* see #testTruncateNotCalledIfSizeIsSameAsTargetSize
*/
@Test
public void testTruncateIfSizeIsDifferentToTargetSize() throws IOException {
FileChannel channelMock = EasyMock.createMock(FileChannel.class);
EasyMock.expect(channelMock.size()).andReturn(42L).atLeastOnce();
EasyMock.expect(channelMock.position(42L)).andReturn(null).once();
EasyMock.expect(channelMock.truncate(23L)).andReturn(null).once();
EasyMock.replay(channelMock);
FileRecords fileRecords = new FileRecords(tempFile(), channelMock, 0, Integer.MAX_VALUE, false);
fileRecords.truncateTo(23);
EasyMock.verify(channelMock);
}