本文整理匯總了Java中org.easymock.IMocksControl.createMock方法的典型用法代碼示例。如果您正苦於以下問題:Java IMocksControl.createMock方法的具體用法?Java IMocksControl.createMock怎麽用?Java IMocksControl.createMock使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.easymock.IMocksControl
的用法示例。
在下文中一共展示了IMocksControl.createMock方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: setUp
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void setUp() throws Exception
{
super.setUp();
migrationRunnerStrategy = new OrderedMigrationRunnerStrategy();
allMigrationTasks = new ArrayList<MigrationTask>();
IMocksControl mockControl = createControl();
currentPatchInfoStore = mockControl.createMock(PatchInfoStore.class);
allMigrationTasks.add(new TestRollbackableTask1());
allMigrationTasks.add(new TestRollbackableTask2());
allMigrationTasks.add(new TestRollbackableTask3());
allMigrationTasks.add(new TestRollbackableTask4());
allMigrationTasks.add(new TestRollbackableTask5());
expect(currentPatchInfoStore.getPatchLevel()).andReturn(12);
mockControl.replay();
}
示例2: testDefaults
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testDefaults() throws ConfigurationException {
IMocksControl c = EasyMock.createControl();
BundleContext bctx = c.createMock(BundleContext.class);
ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("localhost", host);
Assert.assertEquals("2181", port);
Assert.assertEquals(3000, timeout);
return null;
}
};
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
zkd.updated(configuration);
}
示例3: testExportExisting
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testExportExisting() throws Exception {
IMocksControl c = EasyMock.createControl();
RemoteServiceAdmin rsa = c.createMock(RemoteServiceAdmin.class);
final EndpointListenerNotifier mockEpListenerNotifier = c.createMock(EndpointListenerNotifier.class);
final ServiceReference sref = createUserService(c);
expectServiceExported(c, rsa, mockEpListenerNotifier, sref, createEndpoint());
c.replay();
EndpointRepository endpointRepo = new EndpointRepository();
endpointRepo.setNotifier(mockEpListenerNotifier);
ExportPolicy policy = new DefaultExportPolicy();
TopologyManagerExport exportManager = new TopologyManagerExport(endpointRepo, syncExecutor(), policy);
exportManager.serviceChanged(new ServiceEvent(ServiceEvent.REGISTERED, sref));
exportManager.add(rsa);
c.verify();
}
示例4: testGetService
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@SuppressWarnings({
"rawtypes"
})
public void testGetService() throws ClassNotFoundException {
final Object myTestProxyObject = new Object();
IMocksControl control = EasyMock.createControl();
EndpointDescription endpoint = createTestEndpointDesc();
ImportRegistrationImpl iri = new ImportRegistrationImpl(endpoint, null);
BundleContext consumerContext = control.createMock(BundleContext.class);
Bundle consumerBundle = control.createMock(Bundle.class);
BundleWiring bundleWiring = control.createMock(BundleWiring.class);
EasyMock.expect(bundleWiring.getClassLoader()).andReturn(this.getClass().getClassLoader());
EasyMock.expect(consumerBundle.adapt(BundleWiring.class)).andReturn(bundleWiring);
EasyMock.expect(consumerBundle.getBundleContext()).andReturn(consumerContext);
ServiceRegistration sreg = control.createMock(ServiceRegistration.class);
DistributionProvider handler = mockDistributionProvider(myTestProxyObject);
control.replay();
ClientServiceFactory csf = new ClientServiceFactory(endpoint, handler, iri);
assertSame(myTestProxyObject, csf.getService(consumerBundle, sreg));
}
示例5: testUpdateConfig
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void testUpdateConfig() throws Exception {
final File tempDir = new File("target");
IMocksControl control = EasyMock.createControl();
BundleContext bc = control.createMock(BundleContext.class);
expect(bc.getDataFile("")).andReturn(tempDir);
final MyZooKeeperServerMain mockServer = control.createMock(MyZooKeeperServerMain.class);
control.replay();
ZookeeperStarter starter = new ZookeeperStarter(bc) {
@Override
protected void startFromConfig(QuorumPeerConfig config) {
assertEquals(1234, config.getClientPortAddress().getPort());
assertTrue(config.getDataDir().contains(tempDir + File.separator + "zkdata"));
assertEquals(2000, config.getTickTime());
assertEquals(10, config.getInitLimit());
assertEquals(5, config.getSyncLimit());
this.main = mockServer;
}
};
Dictionary<String, Object> props = new Hashtable<String, Object>();
props.put("clientPort", "1234");
starter.updated(props);
assertNotNull(starter.main);
control.verify();
}
示例6: testEndpointRemovalAdding
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void testEndpointRemovalAdding() throws KeeperException, InterruptedException {
IMocksControl c = EasyMock.createNiceControl();
BundleContext ctx = c.createMock(BundleContext.class);
ZooKeeper zk = c.createMock(ZooKeeper.class);
String path = ENDPOINT_PATH;
expectCreated(zk, path);
expectDeleted(zk, path);
c.replay();
PublishingEndpointListener eli = new PublishingEndpointListener(zk, ctx);
EndpointDescription endpoint = createEndpoint();
eli.endpointAdded(endpoint, null);
eli.endpointAdded(endpoint, null); // should do nothing
eli.endpointRemoved(endpoint, null);
eli.endpointRemoved(endpoint, null); // should do nothing
c.verify();
}
示例7: testConfig
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testConfig() throws ConfigurationException {
IMocksControl c = EasyMock.createControl();
BundleContext bctx = c.createMock(BundleContext.class);
ZooKeeperDiscovery zkd = new ZooKeeperDiscovery(bctx) {
@Override
protected ZooKeeper createZooKeeper(String host, String port, int timeout) {
Assert.assertEquals("myhost", host);
Assert.assertEquals("1", port);
Assert.assertEquals(1000, timeout);
return null;
}
};
Dictionary<String, Object> configuration = new Hashtable<String, Object>();
configuration.put("zookeeper.host", "myhost");
configuration.put("zookeeper.port", "1");
configuration.put("zookeeper.timeout", "1000");
zkd.updated(configuration);
}
示例8: testScope
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@SuppressWarnings("unchecked")
public void testScope() {
IMocksControl c = EasyMock.createNiceControl();
BundleContext ctx = c.createMock(BundleContext.class);
ZooKeeper zk = c.createMock(ZooKeeper.class);
@SuppressWarnings("rawtypes")
ServiceRegistration sreg = c.createMock(ServiceRegistration.class);
PublishingEndpointListenerFactory eplf = new PublishingEndpointListenerFactory(zk, ctx);
EasyMock.expect(ctx.registerService(EasyMock.eq(EndpointListener.class.getName()), EasyMock.eq(eplf),
(Dictionary<String, String>)EasyMock.anyObject())).andReturn(sreg).once();
EasyMock.expect(ctx.getProperty(EasyMock.eq("org.osgi.framework.uuid"))).andReturn("myUUID").anyTimes();
c.replay();
eplf.start();
c.verify();
}
示例9: testInterfaceMonitor
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void testInterfaceMonitor() throws KeeperException, InterruptedException {
IMocksControl c = EasyMock.createControl();
ZooKeeper zk = c.createMock(ZooKeeper.class);
expect(zk.getState()).andReturn(ZooKeeper.States.CONNECTED).anyTimes();
String scope = "(myProp=test)";
String interf = "es.schaaf.test";
String node = Utils.getZooKeeperPath(interf);
EndpointListener endpointListener = c.createMock(EndpointListener.class);
InterfaceMonitor im = new InterfaceMonitor(zk, interf, endpointListener, scope);
zk.exists(eq(node), eq(im), eq(im), EasyMock.anyObject());
EasyMock.expectLastCall().once();
expect(zk.exists(eq(node), eq(false))).andReturn(new Stat()).anyTimes();
expect(zk.getChildren(eq(node), eq(false))).andReturn(Collections.<String> emptyList()).once();
expect(zk.getChildren(eq(node), eq(im))).andReturn(Collections.<String> emptyList()).once();
c.replay();
im.start();
// simulate a zk callback
WatchedEvent we = new WatchedEvent(EventType.NodeCreated, KeeperState.SyncConnected, node);
im.process(we);
c.verify();
}
示例10: testNoSuchEditor
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void testNoSuchEditor() throws Exception {
try {
ProjectContext context = new NoopProjectContext();
IMocksControl control = EasyMock.createControl();
RepositoryExpression mockRepoEx = control.createMock(RepositoryExpression.class);
expect(mockRepoEx.createCodebase(context)).andReturn(null); // Codebase unneeded
Expression ex =
new EditExpression(
mockRepoEx, new Operation(Operator.EDIT, new Term("noSuchEditor", EMPTY_MAP)));
control.replay();
ex.createCodebase(context);
fail();
} catch (CodebaseCreationError expected) {
assertEquals("no editor noSuchEditor", expected.getMessage());
}
}
示例11: testSimple
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testSimple() throws Exception {
IMocksControl testControl = createControl();
TestFilterChain testFilterChain = new TestFilterChain();
HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
expect(req.getMethod()).andReturn("GET").anyTimes();
expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes();
expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
expect(req.getContextPath()).andReturn("").anyTimes();
testControl.replay();
daggerFilter.doFilter(req, res, testFilterChain);
assertFalse(testFilterChain.isTriggered());
assertFalse(fooServlet.isTriggered());
assertTrue(barServlet.isTriggered());
testControl.verify();
}
示例12: testGet
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testGet() throws Exception {
IMocksControl control = createControl();
Response resp = control.createMock(Response.class);
expect(resp.getStatus()).andReturn(200).times(3);
Capture<Class<CloudantToDo>> classCapture = new Capture<Class<CloudantToDo>>();
expect(resp.readEntity(capture(classCapture))).andReturn(ctd1);
replay(resp);
WebTarget wt = createMockWebTarget();
Invocation.Builder builder = createBuilder();
expect(builder.get()).andReturn(resp).times(3);
replay(builder);
expect(wt.path(eq("bluemix-todo"))).andReturn(wt).times(2);
expect(wt.path(eq("todos"))).andReturn(wt);
expect(wt.path(eq("_design"))).andReturn(wt).times(1);
expect(wt.path(eq("123"))).andReturn(wt);
expect(wt.request(eq("application/json"))).andReturn(builder).anyTimes();
replay(wt);
CloudantStore store = new CloudantStore(wt);
assertEquals(ctd1.getToDo(), store.get("123"));
assertEquals(CloudantToDo.class, classCapture.getValue());
verify(resp);
verify(wt);
verify(builder);
}
示例13: testSimple
import org.easymock.IMocksControl; //導入方法依賴的package包/類
public void testSimple() throws Exception {
IMocksControl testControl = createControl();
TestFilterChain testFilterChain = new TestFilterChain();
HttpServletRequest req = testControl.createMock(HttpServletRequest.class);
HttpServletResponse res = testControl.createMock(HttpServletResponse.class);
expect(req.getMethod()).andReturn("GET").anyTimes();
expect(req.getRequestURI()).andReturn("/bar/foo").anyTimes();
expect(req.getServletPath()).andReturn("/bar/foo").anyTimes();
expect(req.getContextPath()).andReturn("").anyTimes();
testControl.replay();
guiceFilter.doFilter(req, res, testFilterChain);
assertFalse(testFilterChain.isTriggered());
assertFalse(fooServlet.isTriggered());
assertTrue(barServlet.isTriggered());
testControl.verify();
}
示例14: testMockFinal
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testMockFinal() {
IMocksControl control = EasyMock.createStrictControl();
try {
control.createMock(TestClass.FinalClass.class);
Assert.fail("FinalClass wasn't actually final or EasyMock has changed to support this case");
} catch(IllegalArgumentException e) {
}
JUnitCore core = new JUnitCore();
Result result = core.run(Request.method(TestClass.class, "testMockingFinal"));
if (!result.wasSuccessful()) {
if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
} else {
Assert.fail(result.getFailures().toString());
}
}
}
示例15: testMockParentFinalMethod
import org.easymock.IMocksControl; //導入方法依賴的package包/類
@Test
public void testMockParentFinalMethod() {
IMocksControl control = EasyMock.createStrictControl();
try {
control.createMock(TestClass.FinalChild.class);
Assert.fail("FinalClass wasn't actually final or EasyMock has changed to support this case");
} catch(IllegalArgumentException e) {
}
JUnitCore core = new JUnitCore();
Result result = core.run(Request.method(TestClass.class, "testMockingParentFinal"));
if (!result.wasSuccessful()) {
if (result.getFailures().get(0).getException().getCause() instanceof MultipleFailureException) {
Assert.fail(((MultipleFailureException)result.getFailures().get(0).getException().getCause()).getFailures().toString());
} else {
Assert.fail(result.getFailures().toString());
}
}
}