本文整理了Java中org.mockito.Mockito.anyObject()
方法的一些代码示例,展示了Mockito.anyObject()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.anyObject()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:anyObject
暂无
代码示例来源:origin: apache/storm
@Test
public void testLogResetResetsDoesNothingForEmptyLogConfig() {
TreeMap<String, LogLevel> config = new TreeMap<>();
AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
LogConfigManager underTest = spy(new LogConfigManagerUnderTest(atomConf));
underTest.resetLogLevels();
assertEquals(new TreeMap<>(), atomConf.get());
verify(underTest, never()).setLoggerLevel(anyObject(), anyObject(), anyObject());
}
代码示例来源:origin: google/guava
public void testStandardKeySet() throws InvocationTargetException {
@SuppressWarnings("unchecked")
final Map<String, Boolean> map = mock(Map.class);
Map<String, Boolean> forward =
new ForwardingMap<String, Boolean>() {
@Override
protected Map<String, Boolean> delegate() {
return map;
}
@Override
public Set<String> keySet() {
return new StandardKeySet();
}
};
callAllPublicMethods(new TypeToken<Set<String>>() {}, forward.keySet());
// These are the methods specified by StandardKeySet
verify(map, atLeast(0)).clear();
verify(map, atLeast(0)).containsKey(anyObject());
verify(map, atLeast(0)).isEmpty();
verify(map, atLeast(0)).remove(anyObject());
verify(map, atLeast(0)).size();
verify(map, atLeast(0)).entrySet();
verifyNoMoreInteractions(map);
}
代码示例来源:origin: google/guava
public void testStandardEntrySet() throws InvocationTargetException {
@SuppressWarnings("unchecked")
final Map<String, Boolean> map = mock(Map.class);
Map<String, Boolean> forward =
new ForwardingMap<String, Boolean>() {
@Override
protected Map<String, Boolean> delegate() {
return map;
}
@Override
public Set<Entry<String, Boolean>> entrySet() {
return new StandardEntrySet() {
@Override
public Iterator<Entry<String, Boolean>> iterator() {
return Iterators.emptyIterator();
}
};
}
};
callAllPublicMethods(new TypeToken<Set<Entry<String, Boolean>>>() {}, forward.entrySet());
// These are the methods specified by StandardEntrySet
verify(map, atLeast(0)).clear();
verify(map, atLeast(0)).containsKey(anyObject());
verify(map, atLeast(0)).get(anyObject());
verify(map, atLeast(0)).isEmpty();
verify(map, atLeast(0)).remove(anyObject());
verify(map, atLeast(0)).size();
verifyNoMoreInteractions(map);
}
代码示例来源:origin: google/guava
public void testStandardValues() throws InvocationTargetException {
@SuppressWarnings("unchecked")
final Map<String, Boolean> map = mock(Map.class);
Map<String, Boolean> forward =
new ForwardingMap<String, Boolean>() {
@Override
protected Map<String, Boolean> delegate() {
return map;
}
@Override
public Collection<Boolean> values() {
return new StandardValues();
}
};
callAllPublicMethods(new TypeToken<Collection<Boolean>>() {}, forward.values());
// These are the methods specified by StandardValues
verify(map, atLeast(0)).clear();
verify(map, atLeast(0)).containsValue(anyObject());
verify(map, atLeast(0)).isEmpty();
verify(map, atLeast(0)).size();
verify(map, atLeast(0)).entrySet();
verifyNoMoreInteractions(map);
}
代码示例来源:origin: AsyncHttpClient/async-http-client
@Test
public void testCancel() {
AsyncHandler<?> asyncHandler = mock(AsyncHandler.class);
NettyResponseFuture<?> nettyResponseFuture = new NettyResponseFuture<>(null, asyncHandler, null, 3, null, null, null);
boolean result = nettyResponseFuture.cancel(false);
verify(asyncHandler).onThrowable(anyObject());
assertTrue(result, "Cancel should return true if the Future was cancelled successfully");
assertTrue(nettyResponseFuture.isCancelled(), "isCancelled should return true for a cancelled Future");
}
代码示例来源:origin: apache/storm
@Test
public void testLogResetsNamedLoggersWithPastTimeout() {
try (SimulatedTime t = new SimulatedTime()) {
long past = Time.currentTimeMillis() - 1000;
TreeMap<String, LogLevel> config = new TreeMap<>();
config.put("my_debug_logger", ll("DEBUG", "INFO", past));
config.put("my_info_logger", ll("INFO", "WARN", past));
config.put("my_error_logger", ll("ERROR", "INFO", past));
AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
LogConfigManager underTest = spy(new LogConfigManagerUnderTest(atomConf));
underTest.resetLogLevels();
assertEquals(new TreeMap<>(), atomConf.get());
verify(underTest).setLoggerLevel(anyObject(), eq("my_debug_logger"), eq("INFO"));
verify(underTest).setLoggerLevel(anyObject(), eq("my_info_logger"), eq("WARN"));
verify(underTest).setLoggerLevel(anyObject(), eq("my_error_logger"), eq("INFO"));
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void unzipPostProcessingTest() throws Exception {
JobEntryUnZip jobEntryUnZip = new JobEntryUnZip();
Method unzipPostprocessingMethod = jobEntryUnZip.getClass().getDeclaredMethod( "doUnzipPostProcessing", FileObject.class, FileObject.class, String.class );
unzipPostprocessingMethod.setAccessible( true );
FileObject sourceFileObject = Mockito.mock( FileObject.class );
Mockito.doReturn( Mockito.mock( FileName.class ) ).when( sourceFileObject ).getName();
//delete
jobEntryUnZip.afterunzip = 1;
unzipPostprocessingMethod.invoke( jobEntryUnZip, sourceFileObject, Mockito.mock( FileObject.class ), "" );
Mockito.verify( sourceFileObject, Mockito.times( 1 ) ).delete();
//move
jobEntryUnZip.afterunzip = 2;
unzipPostprocessingMethod.invoke( jobEntryUnZip, sourceFileObject, Mockito.mock( FileObject.class ), "" );
Mockito.verify( sourceFileObject, Mockito.times( 1 ) ).moveTo( Mockito.anyObject() );
}
代码示例来源:origin: apache/hive
@Test(expected = AuthenticationException.class)
public void testApplyNegative() throws AuthenticationException, NamingException, IOException {
doThrow(AuthenticationException.class).when(filter3).apply((DirSearch) anyObject(), anyString());
when(factory1.getInstance(any(HiveConf.class))).thenReturn(filter1);
when(factory3.getInstance(any(HiveConf.class))).thenReturn(filter3);
Filter filter = factory.getInstance(conf);
filter.apply(search, "User");
}
}
代码示例来源:origin: apache/storm
@Test
public void testLogResetResetsRootLoggerIfSet() {
try (SimulatedTime t = new SimulatedTime()) {
long past = Time.currentTimeMillis() - 1000;
TreeMap<String, LogLevel> config = new TreeMap<>();
config.put(LogManager.ROOT_LOGGER_NAME, ll("DEBUG", "WARN", past));
AtomicReference<TreeMap<String, LogLevel>> atomConf = new AtomicReference<>(config);
LogConfigManager underTest = spy(new LogConfigManagerUnderTest(atomConf));
underTest.resetLogLevels();
assertEquals(new TreeMap<>(), atomConf.get());
verify(underTest).setLoggerLevel(anyObject(), eq(LogManager.ROOT_LOGGER_NAME), eq("WARN"));
}
}
代码示例来源:origin: pentaho/pentaho-kettle
@Before
public void setUp() throws Exception {
stepMockHelper =
new StepMockHelper<TextFileOutputMeta, TextFileOutputData>( "TEXT FILE OUTPUT TEST", TextFileOutputMeta.class,
TextFileOutputData.class );
Mockito.when( stepMockHelper.logChannelInterfaceFactory.create( Mockito.any(), Mockito.any( LoggingObjectInterface.class ) ) ).thenReturn(
stepMockHelper.logChannelInterface );
Mockito.verify( stepMockHelper.logChannelInterface, Mockito.never() ).logError( Mockito.anyString() );
Mockito.verify( stepMockHelper.logChannelInterface, Mockito.never() ).logError( Mockito.anyString(), Mockito.any( Object[].class ) );
Mockito.verify( stepMockHelper.logChannelInterface, Mockito.never() ).logError( Mockito.anyString(), (Throwable) Mockito.anyObject() );
Mockito.when( stepMockHelper.trans.isRunning() ).thenReturn( true );
Mockito.verify( stepMockHelper.trans, Mockito.never() ).stopAll();
Mockito.when( stepMockHelper.processRowsStepMetaInterface.getSeparator() ).thenReturn( " " );
Mockito.when( stepMockHelper.processRowsStepMetaInterface.getEnclosure() ).thenReturn( "\"" );
Mockito.when( stepMockHelper.processRowsStepMetaInterface.getNewline() ).thenReturn( "\n" );
Mockito.when( stepMockHelper.transMeta.listVariables() ).thenReturn( new String[0] );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void filesWithPath_AreProcessed_ArgsOfCurrentJob() throws Exception {
String[] args = new String[] { PATH_TO_FILE };
jobEntry.setArguments( args );
jobEntry.setFilemasks( new String[] { null, null } );
jobEntry.setArgFromPrevious( false );
jobEntry.execute( new Result(), 0 );
verify( jobEntry, times( args.length ) ).processFile( anyString(), anyString(), any( Job.class ) );
verify( mockNamedClusterEmbedManager ).passEmbeddedMetastoreKey( anyObject(), anyString() );
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void fileCopied() throws Exception {
String srcPath = "path/to/file";
String destPath = "path/to/dir";
entry.source_filefolder = new String[] { srcPath };
entry.destination_filefolder = new String[] { destPath };
entry.wildcard = new String[] { EMPTY };
Result result = entry.execute( new Result(), 0 );
verify( entry ).processFileFolder( anyString(), anyString(),
anyString(), any( Job.class ), any( Result.class ) );
verify( entry, atLeast( 1 ) ).preprocessfilefilder( any( String[].class ) );
assertFalse( result.getResult() );
assertEquals( 1, result.getNrErrors() );
verify( mockNamedClusterEmbedManager ).passEmbeddedMetastoreKey( anyObject(), anyString() );
}
代码示例来源:origin: apache/hbase
@Test
public void testFilter() throws Exception {
FilterConfig config = mockConfig("myuser");
StaticUserFilter suf = new StaticUserFilter();
suf.init(config);
ArgumentCaptor<HttpServletRequestWrapper> wrapperArg =
ArgumentCaptor.forClass(HttpServletRequestWrapper.class);
FilterChain chain = mock(FilterChain.class);
suf.doFilter(mock(HttpServletRequest.class), mock(ServletResponse.class),
chain);
Mockito.verify(chain).doFilter(wrapperArg.capture(), Mockito.<ServletResponse>anyObject());
HttpServletRequestWrapper wrapper = wrapperArg.getValue();
assertEquals("myuser", wrapper.getUserPrincipal().getName());
assertEquals("myuser", wrapper.getRemoteUser());
suf.destroy();
}
代码示例来源:origin: apache/hive
/**
* Tests the number of times Hive.createPartitions calls are executed with total number of
* partitions to is less than batch size
*
* @throws Exception
*/
@Test
public void testSmallNumberOfPartitions() throws Exception {
// create 10 dummy partitions
Set<PartitionResult> partsNotInMs = createPartsNotInMs(10);
IMetaStoreClient spyDb = Mockito.spy(db);
// batch size of 20 and decaying factor of 2
msck.createPartitionsInBatches(spyDb, repairOutput, partsNotInMs, table, 20, 2, 0);
// there should be 1 call to create partitions with batch sizes of 10
Mockito.verify(spyDb, Mockito.times(1)).add_partitions(Mockito.anyObject(), Mockito.anyBoolean(),
Mockito.anyBoolean());
ArgumentCaptor<Boolean> ifNotExistsArg = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<Boolean> needResultsArg = ArgumentCaptor.forClass(Boolean.class);
ArgumentCaptor<List<Partition>> argParts = ArgumentCaptor.forClass((Class) List.class);
// there should be 1 call to create partitions with batch sizes of 10
Mockito.verify(spyDb, Mockito.times(1)).add_partitions(argParts.capture(), ifNotExistsArg.capture(),
needResultsArg.capture());
Assert.assertEquals("Unexpected number of batch size", 10,
argParts.getValue().size());
assertTrue(ifNotExistsArg.getValue());
assertFalse(needResultsArg.getValue());
}
代码示例来源:origin: apache/hive
@Test
public void testQueryCloseOnError() throws Exception {
ObjectStore spy = Mockito.spy(objectStore);
spy.getAllDatabases(DEFAULT_CATALOG_NAME);
spy.getAllFunctions(DEFAULT_CATALOG_NAME);
spy.getAllTables(DEFAULT_CATALOG_NAME, DB1);
spy.getPartitionCount();
Mockito.verify(spy, Mockito.times(3))
.rollbackAndCleanup(Mockito.anyBoolean(), Mockito.<Query>anyObject());
}
代码示例来源:origin: apache/flink
verify(mock).process((ProcessAllWindowFunctionMock.Context) anyObject(), eq(i), eq(c));
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testGetRowSafeModeEnabled() throws KettleException {
Trans transMock = mock( Trans.class );
when( transMock.isSafeModeEnabled() ).thenReturn( true );
BaseStep baseStepSpy =
spy( new BaseStep( mockHelper.stepMeta, mockHelper.stepDataInterface,
0, mockHelper.transMeta, transMock ) );
doNothing().when( baseStepSpy ).waitUntilTransformationIsStarted();
doNothing().when( baseStepSpy ).openRemoteInputStepSocketsOnce();
BlockingRowSet rowSet = new BlockingRowSet( 1 );
List<ValueMetaInterface> valueMetaList = Arrays.asList( new ValueMetaInteger( "x" ), new ValueMetaString( "a" ) );
RowMeta rowMeta = new RowMeta();
rowMeta.setValueMetaList( valueMetaList );
final Object[] row = new Object[] {};
rowSet.putRow( rowMeta, row );
baseStepSpy.setInputRowSets( Arrays.asList( rowSet ) );
doReturn( rowSet ).when( baseStepSpy ).currentInputStream();
baseStepSpy.getRow();
verify( mockHelper.transMeta, times( 1 ) ).checkRowMixingStatically( any( StepMeta.class ), anyObject() );
}
}
代码示例来源:origin: apache/flink
return null;
}).when(mock).process(eq(42L), (ProcessWindowFunctionMock.Context) anyObject(), eq(i), eq(c));
代码示例来源:origin: apache/flink
@SuppressWarnings("unchecked")
@Test
public void testInternalSingleValueProcessAllWindowFunction() throws Exception {
ProcessAllWindowFunctionMock mock = mock(ProcessAllWindowFunctionMock.class);
InternalSingleValueProcessAllWindowFunction<Long, String, TimeWindow> windowFunction =
new InternalSingleValueProcessAllWindowFunction<>(mock);
// check setOutputType
TypeInformation<String> stringType = BasicTypeInfo.STRING_TYPE_INFO;
ExecutionConfig execConf = new ExecutionConfig();
execConf.setParallelism(42);
StreamingFunctionUtils.setOutputType(windowFunction, stringType, execConf);
verify(mock).setOutputType(stringType, execConf);
// check open
Configuration config = new Configuration();
windowFunction.open(config);
verify(mock).open(config);
// check setRuntimeContext
RuntimeContext rCtx = mock(RuntimeContext.class);
windowFunction.setRuntimeContext(rCtx);
verify(mock).setRuntimeContext(rCtx);
// check apply
TimeWindow w = mock(TimeWindow.class);
Collector<String> c = (Collector<String>) mock(Collector.class);
InternalWindowFunction.InternalWindowContext ctx = mock(InternalWindowFunction.InternalWindowContext.class);
windowFunction.process(((byte) 0), w, ctx, 23L, c);
verify(mock).process((ProcessAllWindowFunctionMock.Context) anyObject(), (Iterable<Long>) argThat(IsIterableContainingInOrder.contains(23L)), eq(c));
// check close
windowFunction.close();
verify(mock).close();
}
代码示例来源:origin: apache/flink
return null;
}).when(mock).process(eq(42L), (ProcessWindowFunctionMock.Context) anyObject(),
(Iterable<Long>) argThat(IsIterableContainingInOrder.contains(23L)), eq(c));
内容来源于网络,如有侵权,请联系作者删除!