本文整理了Java中org.easymock.EasyMock.createNiceMock()
方法的一些代码示例,展示了EasyMock.createNiceMock()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。EasyMock.createNiceMock()
方法的具体详情如下:
包路径:org.easymock.EasyMock
类名称:EasyMock
方法名:createNiceMock
[英]Creates a mock object that implements the given interface, order checking is disabled by default, and the mock object will return 0
, null
or false
for unexpected invocations.
[中]创建实现给定接口的模拟对象,默认情况下禁用顺序检查,对于意外调用,模拟对象将返回0
、null
或false
。
代码示例来源:origin: google/guava
@AndroidIncompatible // EasyMock Class Extension doesn't appear to work on Android.
public void testMockingEasyMock() throws Exception {
RateLimiter mock = EasyMock.createNiceMock(RateLimiter.class);
EasyMock.replay(mock);
doTestMocking(mock);
}
代码示例来源:origin: apache/incubator-druid
private static MemcachedNode dummyNode(String host, int port)
{
SocketAddress address = InetSocketAddress.createUnresolved(host, port);
MemcachedNode node = EasyMock.createNiceMock(MemcachedNode.class);
EasyMock.expect(node.getSocketAddress()).andReturn(address).anyTimes();
EasyMock.replay(node);
return node;
}
}
代码示例来源:origin: apache/shiro
@Test
public void testSimple() throws Exception {
FilterChainResolver resolver = setupResolver();
HttpServletResponse response = createNiceMock(HttpServletResponse.class);
FilterChain chain = createNiceMock(FilterChain.class);
HttpServletRequest request = createMockRequest("/index.html");
FilterChain resolved = resolver.getChain(request, response, chain);
assertNotNull(resolved);
verify(request);
}
代码示例来源:origin: apache/shiro
@Test
public void testExecute() {
Executor targetMockExecutor = createNiceMock(Executor.class);
//* ensure the target Executor receives a SubjectRunnable instance that retains the subject identity:
//(this is what verifies the test is valid):
targetMockExecutor.execute(isA(SubjectRunnable.class));
replay(targetMockExecutor);
final SubjectAwareExecutor executor = new SubjectAwareExecutor(targetMockExecutor);
Runnable work = new Runnable() {
public void run() {
System.out.println("Hello World");
}
};
executor.execute(work);
verify(targetMockExecutor);
}
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testMonitor() throws Exception
{
final MemcachedCache cache = MemcachedCache.create(memcachedCacheConfig);
final Emitter emitter = EasyMock.createNiceMock(Emitter.class);
final Collection<Event> events = new ArrayList<>();
final ServiceEmitter serviceEmitter = new ServiceEmitter("service", "host", emitter)
{
@Override
public void emit(Event event)
{
events.add(event);
}
};
while (events.isEmpty()) {
Thread.sleep(memcachedCacheConfig.getTimeout());
cache.doMonitor(serviceEmitter);
}
Assert.assertFalse(events.isEmpty());
ObjectMapper mapper = new DefaultObjectMapper();
for (Event event : events) {
log.debug("Found event `%s`", mapper.writeValueAsString(event.toMap()));
}
}
代码示例来源:origin: apache/shiro
private HttpServletRequest createMockRequest(String path) {
HttpServletRequest request = createNiceMock(HttpServletRequest.class);
expect(request.getAttribute(WebUtils.INCLUDE_CONTEXT_PATH_ATTRIBUTE)).andReturn(null).anyTimes();
expect(request.getContextPath()).andReturn("");
expect(request.getRequestURI()).andReturn(path);
replay(request);
return request;
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSerialization() throws IOException, ClassNotFoundException, PropertyVetoException {
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
listenerSupport.addListener(EasyMock.createNiceMock(VetoableChangeListener.class));
final PropertyChangeEvent evt = new PropertyChangeEvent(new Date(), "Day", 7, 9);
listener.vetoableChange(evt);
EasyMock.replay(listener);
deserializedListenerSupport.fire().vetoableChange(evt);
EasyMock.verify(listener);
代码示例来源:origin: org.apache.commons/commons-lang3
/**
* Tests whether reset() is automatically called after build().
*/
@Test
public void testBuilderResetAfterBuild() {
builder.wrappedFactory(EasyMock.createNiceMock(ThreadFactory.class))
.namingPattern(PATTERN).daemon(true).build();
checkFactoryDefaults(builder.build());
}
代码示例来源:origin: apache/shiro
@Test
public void testWithConfig() throws Exception {
FilterChainResolver resolver = setupResolver();
HttpServletResponse response = createNiceMock(HttpServletResponse.class);
FilterChain chain = createNiceMock(FilterChain.class);
HttpServletRequest request = createMockRequest("/index2.html");
FilterChain resolved = resolver.getChain(request, response, chain);
assertNotNull(resolved);
verify(request);
}
代码示例来源:origin: apache/incubator-druid
@BeforeClass
public static void setUpStatic()
{
LoggingEmitter loggingEmitter = EasyMock.createNiceMock(LoggingEmitter.class);
EasyMock.replay(loggingEmitter);
SERVICE_EMITTER = new ServiceEmitter("", "", loggingEmitter)
{
@Override
public void emit(Event event)
{
EVENT_EMITS.incrementAndGet();
super.emit(event);
}
};
EmittingLogger.registerEmitter(SERVICE_EMITTER);
}
代码示例来源:origin: apache/incubator-druid
@Before
public void setUp()
{
mapper.registerSubtypes(SomeBeanClass.class);
req = EasyMock.createNiceMock(HttpServletRequest.class);
EasyMock.expect(req.getContentType()).andReturn(MediaType.APPLICATION_JSON).anyTimes();
EasyMock.replay(req);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testSubclassInvocationHandling() throws PropertyVetoException {
final VetoableChangeListener listener = EasyMock.createNiceMock(VetoableChangeListener.class);
eventListenerSupport.addListener(listener);
final Object source = new Date();
final PropertyChangeEvent respond = new PropertyChangeEvent(source, "Day", 6, 7);
listener.vetoableChange(respond);
EasyMock.replay(listener);
eventListenerSupport.fire().vetoableChange(ignore);
eventListenerSupport.fire().vetoableChange(respond);
EasyMock.verify(listener);
代码示例来源:origin: apache/incubator-druid
@Test
public void failOnMalformedURLException() throws IOException
{
try (IndexTaskClient indexTaskClient = buildIndexTaskClient(
EasyMock.createNiceMock(HttpClient.class),
id -> TaskLocation.create(id, -2, -2)
)) {
expectedException.expect(MalformedURLException.class);
expectedException.expectMessage("Invalid port number :-2");
indexTaskClient.submitRequestWithEmptyContent(
"taskId",
HttpMethod.GET,
"test",
null,
true
);
}
}
代码示例来源:origin: apache/shiro
@Test
public void testSimple() {
//1. Create a mock Subject instance for the test to run
// (for example, as an authenticated Subject):
Subject subjectUnderTest = createNiceMock(Subject.class);
expect(subjectUnderTest.isAuthenticated()).andReturn(true);
//2. Bind the subject to the current thread:
setSubject(subjectUnderTest);
//perform test logic here. Any call to
//SecurityUtils.getSubject() directly (or nested in the
//call stack) will work properly.
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Test
public void set() throws SQLException {
LocalDate value = LocalDate.now();
Date date = new Date(value.atStartOfDay(ZoneOffset.UTC).toInstant().toEpochMilli());
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
stmt.setDate(1, date, UTC);
EasyMock.replay(stmt);
type.setValue(stmt, 1, value);
EasyMock.verify(stmt);
}
代码示例来源:origin: org.apache.commons/commons-lang3
@Test
public void testGetListeners() {
final EventListenerSupport<VetoableChangeListener> listenerSupport = EventListenerSupport.create(VetoableChangeListener.class);
final VetoableChangeListener[] listeners = listenerSupport.getListeners();
assertEquals(0, listeners.length);
assertEquals(VetoableChangeListener.class, listeners.getClass().getComponentType());
final VetoableChangeListener[] empty = listeners;
//for fun, show that the same empty instance is used
assertSame(empty, listenerSupport.getListeners());
final VetoableChangeListener listener1 = EasyMock.createNiceMock(VetoableChangeListener.class);
listenerSupport.addListener(listener1);
assertEquals(1, listenerSupport.getListeners().length);
final VetoableChangeListener listener2 = EasyMock.createNiceMock(VetoableChangeListener.class);
listenerSupport.addListener(listener2);
assertEquals(2, listenerSupport.getListeners().length);
listenerSupport.removeListener(listener1);
assertEquals(1, listenerSupport.getListeners().length);
listenerSupport.removeListener(listener2);
assertSame(empty, listenerSupport.getListeners());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testMissingAuthorizationCheckWithError() throws Exception
{
EmittingLogger.registerEmitter(EasyMock.createNiceMock(ServiceEmitter.class));
AuthenticationResult authenticationResult = new AuthenticationResult("so-very-valid", "so-very-valid", null, null);
HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
FilterChain filterChain = EasyMock.createNiceMock(FilterChain.class);
ServletOutputStream outputStream = EasyMock.createNiceMock(ServletOutputStream.class);
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(authenticationResult).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(null).once();
EasyMock.expect(resp.getStatus()).andReturn(404).once();
EasyMock.replay(req, resp, filterChain, outputStream);
PreResponseAuthorizationCheckFilter filter = new PreResponseAuthorizationCheckFilter(
authenticators,
new DefaultObjectMapper()
);
filter.doFilter(req, resp, filterChain);
EasyMock.verify(req, resp, filterChain, outputStream);
}
}
代码示例来源:origin: com.querydsl/querydsl-sql
@Test
public void set() throws SQLException {
Instant value = Instant.now();
Timestamp ts = new Timestamp(value.toEpochMilli());
PreparedStatement stmt = EasyMock.createNiceMock(PreparedStatement.class);
stmt.setTimestamp(1, ts, UTC);
EasyMock.replay(stmt);
type.setValue(stmt, 1, value);
EasyMock.verify(stmt);
}
代码示例来源:origin: apache/incubator-druid
@Test(timeout = 60_000L)
public void testStopByInterruption()
{
final SleepingFirehose firehose = new SleepingFirehose();
final RealtimeIOConfig ioConfig = new RealtimeIOConfig(
new FirehoseFactory()
{
@Override
public Firehose connect(InputRowParser parser, File temporaryDirectory)
{
return firehose;
}
},
(schema, config, metrics) -> plumber,
null
);
final FireDepartment department_0 = new FireDepartment(schema, ioConfig, tuningConfig_0);
final RealtimeManager realtimeManager = new RealtimeManager(
Collections.singletonList(department_0),
conglomerate,
EasyMock.createNiceMock(DataSegmentServerAnnouncer.class),
null
);
realtimeManager.start();
realtimeManager.stop();
Assert.assertTrue(firehose.isClosed());
Assert.assertFalse(plumber.isFinishedJob());
}
代码示例来源:origin: apache/incubator-druid
@Test
public void testValidRequest() throws Exception
{
AuthenticationResult authenticationResult = new AuthenticationResult("so-very-valid", "so-very-valid", null, null);
HttpServletRequest req = EasyMock.createStrictMock(HttpServletRequest.class);
HttpServletResponse resp = EasyMock.createStrictMock(HttpServletResponse.class);
FilterChain filterChain = EasyMock.createNiceMock(FilterChain.class);
ServletOutputStream outputStream = EasyMock.createNiceMock(ServletOutputStream.class);
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHENTICATION_RESULT)).andReturn(authenticationResult).once();
EasyMock.expect(req.getAttribute(AuthConfig.DRUID_AUTHORIZATION_CHECKED)).andReturn(true).once();
EasyMock.replay(req, resp, filterChain, outputStream);
PreResponseAuthorizationCheckFilter filter = new PreResponseAuthorizationCheckFilter(
authenticators,
new DefaultObjectMapper()
);
filter.doFilter(req, resp, filterChain);
EasyMock.verify(req, resp, filterChain, outputStream);
}
内容来源于网络,如有侵权,请联系作者删除!