本文整理汇总了Java中org.easymock.EasyMock.createNiceMock方法的典型用法代码示例。如果您正苦于以下问题:Java EasyMock.createNiceMock方法的具体用法?Java EasyMock.createNiceMock怎么用?Java EasyMock.createNiceMock使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.easymock.EasyMock
的用法示例。
在下文中一共展示了EasyMock.createNiceMock方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: mockSearchResults
import org.easymock.EasyMock; //导入方法依赖的package包/类
private NamingEnumeration<SearchResult> mockSearchResults(String password)
throws NamingException {
@SuppressWarnings("unchecked")
NamingEnumeration<SearchResult> searchResults =
EasyMock.createNiceMock(NamingEnumeration.class);
EasyMock.expect(Boolean.valueOf(searchResults.hasMore()))
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE)
.andReturn(Boolean.TRUE)
.andReturn(Boolean.FALSE);
EasyMock.expect(searchResults.next())
.andReturn(new SearchResult("ANY RESULT", "",
new BasicAttributes(USER_PASSWORD_ATTR, password)))
.times(2);
EasyMock.replay(searchResults);
return searchResults;
}
示例2: testShutdown
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testShutdown() throws InterruptedException {
AnomalyNotifier mockAnomalyNotifier = EasyMock.createNiceMock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.createNiceMock(KafkaCruiseControl.class);
ScheduledExecutorService detectorScheduler =
Executors.newScheduledThreadPool(2, new KafkaCruiseControlThreadFactory("AnomalyDetector", false, null));
AnomalyDetector anomalyDetector = new AnomalyDetector(new LinkedBlockingDeque<>(), 3000L, mockKafkaCruiseControl,
mockAnomalyNotifier, mockGoalViolationDetector,
mockBrokerFailureDetector, detectorScheduler);
anomalyDetector.shutdown();
Thread t = new Thread(anomalyDetector::shutdown);
t.start();
t.join(30000L);
assertTrue(detectorScheduler.isTerminated());
}
示例3: testSynchronizeLocalArchive
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testSynchronizeLocalArchive ()
throws DataStoreLocalArchiveNotExistingException, InterruptedException
{
int expected = 5;
ProductService mock = EasyMock.createNiceMock (ProductService.class);
EasyMock.expect (mock.processArchiveSync ()).andReturn (expected);
EasyMock.replay (mock);
archiveService.setDefaultDataStore (mock);
int result = archiveService.synchronizeLocalArchive ();
Assert.assertEquals (result, expected);
expected = -1;
mock = EasyMock.createNiceMock (ProductService.class);
EasyMock.expect (mock.processArchiveSync ()).andThrow (
new InterruptedException ());
EasyMock.replay (mock);
archiveService.setDefaultDataStore (mock);
result = archiveService.synchronizeLocalArchive ();
Assert.assertEquals (result, expected);
}
示例4: writeStatsRequest
import org.easymock.EasyMock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public <REPLY extends OFStatsReply> ListenableFuture<List<REPLY>> writeStatsRequest(OFStatsRequest<REPLY> request) {
ListenableFuture<List<REPLY>> ofStatsFuture =
EasyMock.createNiceMock(ListenableFuture.class);
// We create a mock future and return info from the map
try {
OFStatsType statsType = request.getStatsType();
List<REPLY> replies = (List<REPLY>) statsMap.get(statsType);
EasyMock.expect(ofStatsFuture.get(EasyMock.anyLong(),
EasyMock.anyObject(TimeUnit.class))).andReturn(replies).anyTimes();
EasyMock.expect(ofStatsFuture.get()).andReturn(replies).anyTimes();
EasyMock.replay(ofStatsFuture);
} catch (Exception e) {
throw new RuntimeException(e);
}
return ofStatsFuture;
}
示例5: issueInsert
import org.easymock.EasyMock; //导入方法依赖的package包/类
/**
* Issues a fake dataStoreChange insert event that affects two tile layers: "theLayer" and
* "theGroup"
*/
private void issueInsert(Map<Object, Object> extendedProperties,
ReferencedEnvelope affectedBounds) {
TransactionType transaction = EasyMock.createNiceMock(TransactionType.class);
EasyMock.expect(transaction.getExtendedProperties()).andStubReturn(extendedProperties);
TransactionEvent event = EasyMock.createNiceMock(TransactionEvent.class);
EasyMock.expect(event.getRequest()).andStubReturn(transaction);
EasyMock.expect(event.getLayerName()).andStubReturn(featureTypeQName1);
InsertElementType insert = EasyMock.createNiceMock(InsertElementType.class);
EasyMock.expect(event.getSource()).andStubReturn(insert);
EasyMock.expect(event.getType()).andStubReturn(TransactionEventType.PRE_INSERT);
SimpleFeatureCollection affectedFeatures = EasyMock.createNiceMock(SimpleFeatureCollection.class);
EasyMock.expect(affectedFeatures.getBounds()).andStubReturn(affectedBounds);
EasyMock.expect(event.getAffectedFeatures()).andStubReturn(affectedFeatures);
EasyMock.replay(transaction, event, insert, affectedFeatures);
listener.dataStoreChange(event);
}
示例6: exceptionExecutingPolicy
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void exceptionExecutingPolicy() throws InterruptedException, IOException, IllegalAccessException {
Map<String, String> props = new HashMap<>(taskConfig);
task.start(props);
Policy policy = EasyMock.createNiceMock(Policy.class);
EasyMock.expect(policy.hasEnded()).andReturn(Boolean.FALSE);
EasyMock.expect(policy.execute()).andThrow(new ConnectException("Exception from mock"));
EasyMock.expect(policy.getURIs()).andReturn(null);
EasyMock.checkOrder(policy, false);
EasyMock.replay(policy);
MemberModifier.field(FsSourceTask.class, "policy").set(task, policy);
assertEquals(0, task.poll().size());
}
示例7: setUp
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
// Build our test packet
IDebugCounterService debugCounter = new DebugCounterServiceImpl();
switchManager = createMock(IOFSwitchManager.class);
SwitchManagerCounters counters = new SwitchManagerCounters(debugCounter);
expect(switchManager.getCounters()).andReturn(counters).anyTimes();
replay(switchManager);
factory = OFFactories.getFactory(OFVersion.OF_13);
testMessage = factory.buildRoleReply()
.setXid(1)
.setRole(OFControllerRole.ROLE_MASTER)
.build();
IOFConnectionBackend conn = EasyMock.createNiceMock(IOFConnectionBackend.class);
capturedMessage = new Capture<OFMessage>();
conn.write(EasyMock.capture(capturedMessage));
expectLastCall().anyTimes();
expect(conn.getOFFactory()).andReturn(factory).anyTimes();
expect(conn.getAuxId()).andReturn(OFAuxId.MAIN).anyTimes();
EasyMock.replay(conn);
IOFConnectionBackend auxConn = EasyMock.createNiceMock(IOFConnectionBackend.class);
expect(auxConn.getOFFactory()).andReturn(factory).anyTimes();
expect(auxConn.getAuxId()).andReturn(OFAuxId.of(1)).anyTimes();
EasyMock.replay(auxConn);
sw = new OFSwitchTest(conn, switchManager);
sw.registerConnection(auxConn);
sw.setControllerRole(OFControllerRole.ROLE_MASTER); /* must supply role now, otherwise write() will be blocked if not master/equal/other */
switches = new ConcurrentHashMap<DatapathId, IOFSwitchBackend>();
switches.put(sw.getId(), sw);
reset(switchManager);
//expect(switchManager.getSwitch(sw.getId())).andReturn(sw).anyTimes();
}
示例8: mockDirContext
import org.easymock.EasyMock; //导入方法依赖的package包/类
private DirContext mockDirContext(NamingEnumeration<SearchResult> namingEnumeration)
throws NamingException {
DirContext dirContext = EasyMock.createNiceMock(InitialDirContext.class);
EasyMock.expect(dirContext.search(EasyMock.anyString(), EasyMock.anyString(),
EasyMock.anyObject(SearchControls.class)))
.andReturn(namingEnumeration)
.times(2);
EasyMock.expect(dirContext.getNameParser(""))
.andReturn(new NameParserImpl()).times(2);
EasyMock.expect(dirContext.getNameInNamespace())
.andReturn("ANY NAME")
.times(2);
EasyMock.replay(dirContext);
return dirContext;
}
示例9: testBad
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test public void testBad() throws Exception
{
OptionsParser parser = new OptionsParser();
OptionsHandler handler = EasyMock.createNiceMock(OptionsHandler.class);
try
{
parser.parse(new ByteArrayInputStream(NONAME.getBytes()), handler);
missing(InvalidFileFormatException.class);
}
catch (InvalidFileFormatException x)
{
//
}
}
示例10: testDataStoreChangeDoesNotPropagateExceptions
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testDataStoreChangeDoesNotPropagateExceptions() {
TransactionEvent event = EasyMock.createNiceMock(TransactionEvent.class);
EasyMock.expect(event.getSource()).andStubThrow(new RuntimeException("This exception should be eaten to prevent the transaction from failing"));
EasyMock.replay(catalog, featureType1, featureType2, event);
listener.dataStoreChange(event);
EasyMock.verify(catalog, featureType1, featureType2, event);
}
示例11: setUp
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
controller = EasyMock.createNiceMock(Controller.class);
isisProcess = EasyMock.createNiceMock(IsisProcess.class);
channelHandlerContext = EasyMock.createNiceMock(ChannelHandlerContext.class);
channelStateEvent = EasyMock.createNiceMock(ChannelStateEvent.class);
exceptionEvent = EasyMock.createNiceMock(ExceptionEvent.class);
messageEvent = EasyMock.createNiceMock(MessageEvent.class);
isisMessage = EasyMock.createNiceMock(L1L2HelloPdu.class);
isisMessage.setInterfaceIndex(2);
isisChannelHandler = new IsisChannelHandler(controller, isisProcessList);
}
示例12: setUp
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
defaultIsisController = new DefaultIsisController();
mapper = new ObjectMapper();
jsonNode = mapper.readTree(jsonString);
isisRouterListener = EasyMock.createNiceMock(IsisRouterListener.class);
}
示例13: testDelayedCheck
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testDelayedCheck() throws InterruptedException, KafkaCruiseControlException {
LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
EasyMock.expect(mockAnomalyNotifier.onBrokerFailure(EasyMock.isA(BrokerFailures.class)))
.andReturn(AnomalyNotificationResult.check(1000L));
// Starting periodic goal violation detection.
EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
EasyMock.anyLong(),
EasyMock.eq(3000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
// Starting anomaly handler
EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
.andDelegateTo(executorService);
// Schedule a delayed check
EasyMock.expect(mockDetectorScheduler.schedule(EasyMock.isA(Runnable.class),
EasyMock.eq(1000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
mockDetectorScheduler.shutdown();
EasyMock.expectLastCall().andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);
// The following state are used to test the delayed check when executor is busy.
EasyMock.expect(mockKafkaCruiseControl.state())
.andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
EasyMock.replay(mockAnomalyNotifier);
EasyMock.replay(mockBrokerFailureDetector);
EasyMock.replay(mockGoalViolationDetector);
EasyMock.replay(mockDetectorScheduler);
EasyMock.replay(mockKafkaCruiseControl);
AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
mockGoalViolationDetector, mockBrokerFailureDetector,
mockDetectorScheduler);
try {
anomalyDetector.startDetection();
anomalies.add(new BrokerFailures(Collections.singletonMap(0, 100L)));
while (!anomalies.isEmpty()) {
// just wait for the anomalies to be drained.
}
anomalyDetector.shutdown();
assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
} finally {
executorService.shutdown();
}
}
示例14: testFix
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Test
public void testFix() throws InterruptedException, KafkaCruiseControlException {
LinkedBlockingDeque<Anomaly> anomalies = new LinkedBlockingDeque<>();
AnomalyNotifier mockAnomalyNotifier = EasyMock.mock(AnomalyNotifier.class);
BrokerFailureDetector mockBrokerFailureDetector = EasyMock.createNiceMock(BrokerFailureDetector.class);
GoalViolationDetector mockGoalViolationDetector = EasyMock.createNiceMock(GoalViolationDetector.class);
ScheduledExecutorService mockDetectorScheduler = EasyMock.mock(ScheduledExecutorService.class);
ScheduledExecutorService executorService = Executors.newSingleThreadScheduledExecutor();
KafkaCruiseControl mockKafkaCruiseControl = EasyMock.mock(KafkaCruiseControl.class);
EasyMock.expect(mockAnomalyNotifier.onGoalViolation(EasyMock.isA(GoalViolations.class)))
.andReturn(AnomalyNotificationResult.fix());
// Starting periodic goal violation detection.
EasyMock.expect(mockDetectorScheduler.scheduleAtFixedRate(EasyMock.eq(mockGoalViolationDetector),
EasyMock.anyLong(),
EasyMock.eq(3000L),
EasyMock.eq(TimeUnit.MILLISECONDS)))
.andReturn(null);
// Starting anomaly handler
EasyMock.expect(mockDetectorScheduler.submit(EasyMock.isA(AnomalyDetector.AnomalyHandlerTask.class)))
.andDelegateTo(executorService);
mockDetectorScheduler.shutdown();
EasyMock.expectLastCall().andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.awaitTermination(3000L, TimeUnit.MILLISECONDS)).andDelegateTo(executorService);
EasyMock.expect(mockDetectorScheduler.isTerminated()).andDelegateTo(executorService);
// The following state are used to test the delayed check when executor is busy.
EasyMock.expect(mockKafkaCruiseControl.state())
.andReturn(new KafkaCruiseControlState(ExecutorState.noTaskInProgress(), null, null));
EasyMock.expect(mockKafkaCruiseControl.rebalance(Collections.emptyList(), false, null))
.andReturn(null);
EasyMock.replay(mockAnomalyNotifier);
EasyMock.replay(mockBrokerFailureDetector);
EasyMock.replay(mockGoalViolationDetector);
EasyMock.replay(mockDetectorScheduler);
EasyMock.replay(mockKafkaCruiseControl);
AnomalyDetector anomalyDetector = new AnomalyDetector(anomalies, 3000L, mockKafkaCruiseControl, mockAnomalyNotifier,
mockGoalViolationDetector, mockBrokerFailureDetector,
mockDetectorScheduler);
try {
anomalyDetector.startDetection();
anomalies.add(new GoalViolations());
while (!anomalies.isEmpty()) {
// Just wait for the anomalies to be drained.
}
anomalyDetector.shutdown();
assertTrue(executorService.awaitTermination(5000, TimeUnit.MILLISECONDS));
EasyMock.verify(mockAnomalyNotifier, mockDetectorScheduler, mockKafkaCruiseControl);
} finally {
executorService.shutdown();
}
}
示例15: setUp
import org.easymock.EasyMock; //导入方法依赖的package包/类
@Override
@Before
public void setUp() throws Exception {
super.setUp();
cntx = new FloodlightContext();
mockFloodlightProvider = getMockFloodlightProvider();
mockSwitchManager = getMockSwitchService();
debugEventService = new MockDebugEventService();
entityClassifier = new DefaultEntityClassifier();
tps = new MockThreadPoolService();
deviceManager = new MockDeviceManager();
topology = createMock(ITopologyService.class);
debugCounterService = new MockDebugCounterService();
storageService = new MemoryStorageSource();
restApi = new RestApiServer();
acl = new ACL();
// Mock switches
DatapathId dpid = DatapathId.of(TestSwitch1DPID);
sw = EasyMock.createNiceMock(IOFSwitch.class);
expect(sw.getId()).andReturn(dpid).anyTimes();
expect(sw.getOFFactory()).andReturn(
OFFactories.getFactory(OFVersion.OF_13)).anyTimes();
replay(sw);
// Load the switch map
Map<DatapathId, IOFSwitch> switches = new HashMap<DatapathId, IOFSwitch>();
switches.put(dpid, sw);
mockSwitchManager.setSwitches(switches);
FloodlightModuleContext fmc = new FloodlightModuleContext();
fmc.addService(IFloodlightProviderService.class, mockFloodlightProvider);
fmc.addService(IOFSwitchService.class, mockSwitchManager);
fmc.addService(IDebugCounterService.class, debugCounterService);
fmc.addService(IStorageSourceService.class, storageService);
fmc.addService(IDebugEventService.class, debugEventService);
fmc.addService(IEntityClassifierService.class, entityClassifier);
fmc.addService(IThreadPoolService.class, tps);
fmc.addService(IDeviceService.class, deviceManager);
fmc.addService(ITopologyService.class, topology);
fmc.addService(IRestApiService.class, restApi);
fmc.addService(IACLService.class, acl);
topology.addListener(deviceManager);
expectLastCall().times(1);
replay(topology);
debugCounterService.init(fmc);
entityClassifier.init(fmc);
tps.init(fmc);
deviceManager.init(fmc);
storageService.init(fmc);
restApi.init(fmc);
acl.init(fmc);
debugCounterService.startUp(fmc);
deviceManager.startUp(fmc);
entityClassifier.startUp(fmc);
tps.startUp(fmc);
storageService.startUp(fmc);
acl.startUp(fmc);
verify(topology);
storageService.createTable(StaticFlowEntryPusher.TABLE_NAME, null);
storageService.setTablePrimaryKeyName(StaticFlowEntryPusher.TABLE_NAME,
StaticFlowEntryPusher.COLUMN_NAME);
}