本文整理了Java中org.mockito.Matchers.argThat()
方法的一些代码示例,展示了Matchers.argThat()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Matchers.argThat()
方法的具体详情如下:
包路径:org.mockito.Matchers
类名称:Matchers
方法名:argThat
[英]Allows creating custom argument matchers.
In rare cases when the parameter is a primitive then you must use relevant intThat(), floatThat(), etc. method. This way you will avoid NullPointerException
during auto-unboxing.
See examples in javadoc for ArgumentMatcher class
[中]允许创建自定义参数匹配器。
在极少数情况下,当参数是基元时,您必须使用相关的intThat()、floatThat()等方法。这样,在自动取消装箱期间,您将避免NullPointerException
。
有关ArgumentMatcher类,请参见javadoc中的示例
代码示例来源:origin: facebook/facebook-android-sdk
public void implTestLogInCreatesPendingRequestWithCorrectValues(
LoginManager loginManager,
final Collection<String> expectedPermissions) {
ArgumentMatcher<Intent> m = new ArgumentMatcher<Intent>() {
@Override
public boolean matches(Object argument) {
Intent orig = (Intent)argument;
Bundle bundle = orig.getBundleExtra(LoginFragment.REQUEST_KEY);
LoginClient.Request request =
(LoginClient.Request)bundle.getParcelable(LoginFragment.EXTRA_REQUEST);
assertEquals(MOCK_APP_ID, request.getApplicationId());
assertEquals(LoginBehavior.NATIVE_ONLY, request.getLoginBehavior());
assertEquals(DefaultAudience.EVERYONE, request.getDefaultAudience());
Set<String> permissions = request.getPermissions();
for (String permission : expectedPermissions) {
assertTrue(permissions.contains(permission));
}
return true;
}
};
int loginRequestCode = CallbackManagerImpl.RequestCodeOffset.Login.toRequestCode();
verify(mockActivity, times(1)).startActivityForResult(argThat(m), eq(loginRequestCode));
}
代码示例来源:origin: apache/hive
@Test
public void testAllQueryLifeTimeWithParseHooks() throws Exception {
String query = "select 1";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
int ret = driver.run(query).getResponseCode();
assertEquals("Expected query to succeed", 0, ret);
verify(mockHook).beforeParse(argThat(argMatcher));
verify(mockHook).afterParse(argThat(argMatcher), eq(false));
verify(mockHook).beforeCompile(argThat(argMatcher));
verify(mockHook).afterCompile(argThat(argMatcher), eq(false));
verify(mockHook).beforeExecution(argThat(argMatcher));
verify(mockHook).afterExecution(argThat(argMatcher), eq(false));
}
代码示例来源:origin: Karumi/Dexter
private void thenPermissionIsGranted(String permission) {
verify(permissionListener).onPermissionGranted(
argThat(getPermissionGrantedResponseMatcher(permission)));
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void getStepTypeIDs_WhenNeedToUseNotAllValues() throws Exception {
final int amount = 1;
final String[] values = new String[] { "1", "2", "3" };
KettleDatabaseRepository rep = new KettleDatabaseRepository();
rep.connectionDelegate = mock( KettleDatabaseRepositoryConnectionDelegate.class );
when( rep.connectionDelegate.getDatabaseMeta() ).thenReturn( mock( DatabaseMeta.class ) );
KettleDatabaseRepositoryStepDelegate delegate = new KettleDatabaseRepositoryStepDelegate( rep );
delegate.getStepTypeIDs( values, amount );
verify( rep.connectionDelegate )
.getIDsWithValues( anyString(), anyString(), anyString(), argThat( new BaseMatcher<String[]>() {
@Override public boolean matches( Object item ) {
return ( ( (String[]) item ).length == amount ) && ( ( (String[]) item )[ 0 ].equals( values[ 0 ] ) );
}
@Override public void describeTo( Description description ) {
}
} ) );
}
代码示例来源:origin: apache/hive
@Test
public void testAllQueryLifeTimeHooks() throws Exception {
String query = "select 1";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHook mockHook = mock(QueryLifeTimeHook.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
int ret = driver.run(query).getResponseCode();
assertEquals("Expected query to succeed", 0, ret);
verify(mockHook).beforeCompile(argThat(argMatcher));
verify(mockHook).afterCompile(argThat(argMatcher), eq(false));
verify(mockHook).beforeExecution(argThat(argMatcher));
verify(mockHook).afterExecution(argThat(argMatcher), eq(false));
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testSafeStopStaysRunningUntilStopped() throws Exception {
TransMeta transMeta = new TransMeta( getClass().getResource( "grid-to-subtrans.ktr" ).getPath() );
.safeStop( true )
.build();
verify( daemonEndpoint ).sendMessage( argThat( matchesSafeStop() ) );
List<StepMetaDataCombi> steps = adapter.getSteps();
steps.stream().map( s -> s.step ).forEach( step -> assertEquals( "Halting", step.getStatus().getDescription() ) );
代码示例来源:origin: apache/incubator-gobblin
allJobs.add(new SimpleProducerJob(page1, date, date));
allJobs.add(new SimpleProducerJob(page2, date, date));
Mockito.when(client.getAllPages(eq(date), eq(date), eq(country), eq(GoogleWebmasterClient.API_ROW_LIMIT)))
.thenReturn(allJobs);
filters1.add(GoogleWebmasterFilter.pageFilter(GoogleWebmasterFilter.FilterOperator.EQUALS, page1));
Mockito.when(client.performSearchAnalyticsQuery(eq(date), eq(date), eq(GoogleWebmasterClient.API_ROW_LIMIT),
eq(requestedDimensions), eq(requestedMetrics), argThat(new CollectionEquals(filters1)))).thenReturn(results1);
Mockito.when(client
.performSearchAnalyticsQuery(eq(date), eq(date), eq(5000), eq(requestedDimensions), eq(requestedMetrics),
argThat(new CollectionEquals(filters2)))).thenReturn(results2);
Assert.assertTrue(response.contains(a2));
Mockito.verify(client, Mockito.times(1)).getAllPages(eq(date), eq(date), eq(country), eq(5000));
Mockito.verify(client, Mockito.times(1))
.performSearchAnalyticsQuery(eq(date), eq(date), eq(5000), eq(requestedDimensions), eq(requestedMetrics),
argThat(new CollectionEquals(filters1)));
Mockito.verify(client, Mockito.times(1))
.performSearchAnalyticsQuery(eq(date), eq(date), eq(5000), eq(requestedDimensions), eq(requestedMetrics),
argThat(new CollectionEquals(filters2)));
代码示例来源:origin: Karumi/Dexter
private void thenPermissionIsPermanentlyDenied(String permission) {
verify(permissionListener).onPermissionDenied(
argThat(getPermissionDeniedResponseMatcher(permission, true)));
}
代码示例来源:origin: apache/hive
@Test
public void testQueryLifeTimeWithParseHooksWithCompileError() throws Exception {
String query = "select * from foo";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
int ret = driver.run(query).getResponseCode();
assertNotEquals("Expected compilation to fail", 0, ret);
verify(mockHook).beforeParse(argThat(argMatcher));
verify(mockHook).afterParse(argThat(argMatcher), eq(false));
verify(mockHook).beforeCompile(argThat(argMatcher));
verify(mockHook).afterCompile(argThat(argMatcher), eq(true));
verify(mockHook, never()).beforeExecution(any());
verify(mockHook, never()).afterExecution(any(), anyBoolean());
}
代码示例来源:origin: apache/hbase
@Test
public void testToViolation() throws Exception {
final TableName tn = TableName.valueOf("inviolation");
final SpaceQuotaSnapshot snapshot = new SpaceQuotaSnapshot(
new SpaceQuotaStatus(SpaceViolationPolicy.NO_INSERTS), 1024L, 512L);
final Table quotaTable = mock(Table.class);
when(conn.getTable(QuotaTableUtil.QUOTA_TABLE_NAME)).thenReturn(quotaTable);
final Put expectedPut = new Put(Bytes.toBytes("t." + tn.getNameAsString()));
final QuotaProtos.SpaceQuotaSnapshot protoQuota = QuotaProtos.SpaceQuotaSnapshot.newBuilder()
.setQuotaStatus(QuotaProtos.SpaceQuotaStatus.newBuilder().setInViolation(true)
.setViolationPolicy(QuotaProtos.SpaceViolationPolicy.NO_INSERTS))
.setQuotaLimit(512L)
.setQuotaUsage(1024L)
.build();
expectedPut.addColumn(Bytes.toBytes("u"), Bytes.toBytes("p"), protoQuota.toByteArray());
notifier.transitionTable(tn, snapshot);
verify(quotaTable).put(argThat(new SingleCellMutationMatcher<Put>(expectedPut)));
}
代码示例来源:origin: apache/hbase
verifyCollectionsEqual(sfs, scr.getRequest().getFiles());
scr.execute(sc, NoLimitThroughputController.INSTANCE, null);
verify(sc, times(1)).compact(eq(scr.getRequest()), argThat(new ArgumentMatcher<List<byte[]>>() {
@Override
public boolean matches(List<byte[]> argument) {
代码示例来源:origin: Karumi/Dexter
private void thenPermissionIsDenied(String permission) {
verify(permissionListener).onPermissionDenied(
argThat(getPermissionDeniedResponseMatcher(permission, false)));
}
代码示例来源:origin: apache/hive
@Test
public void testQueryLifeTimeWithCompileError() throws Exception {
String query = "select * from foo";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHook mockHook = mock(QueryLifeTimeHook.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
int ret = driver.run(query).getResponseCode();
assertNotEquals("Expected compilation to fail", 0, ret);
verify(mockHook).beforeCompile(argThat(argMatcher));
verify(mockHook).afterCompile(argThat(argMatcher), eq(true));
verify(mockHook, never()).beforeExecution(any());
verify(mockHook, never()).afterExecution(any(), anyBoolean());
}
代码示例来源:origin: konmik/nucleus
@Test
public void testRequest() throws Throwable {
createServerApiMock();
createTestScheduler();
App.setObjectGraph(ObjectGraph.create(new MainPresenterTestModule()));
MainPresenter presenter = new MainPresenter();
presenter.onCreate(null);
presenter.request(FIRST_NAME + " " + LAST_NAME);
MainActivity mainActivity = mock(MainActivity.class);
presenter.takeView(mainActivity);
testScheduler.triggerActions();
verify(serverAPIMock).getItems(FIRST_NAME, LAST_NAME);
verify(mainActivity).onItems(argThat(new ArgumentMatcher<ServerAPI.Item[]>() {
@Override
public boolean matches(Object argument) {
return ((ServerAPI.Item[])argument)[0].text.equals(TEST_TEXT);
}
}), anyString());
}
代码示例来源:origin: Karumi/Dexter
private void thenShouldShowRationaleForPermission(String permission) {
verify(permissionListener).onPermissionRationaleShouldBeShown(
argThat(getPermissionRequestShouldShowTokenMatcher(permission)),
isA(PermissionToken.class));
}
代码示例来源:origin: apache/hive
@Test
public void testQueryLifeTimeWithParseHooksWithParseError() throws Exception {
String query = "invalidquery";
ArgumentMatcher<QueryLifeTimeHookContext> argMatcher = new QueryLifeTimeHookContextMatcher(query);
QueryLifeTimeHookWithParseHooks mockHook = mock(QueryLifeTimeHookWithParseHooks.class);
Driver driver = createDriver();
driver.getHookRunner().addLifeTimeHook(mockHook);
int ret = driver.run(query).getResponseCode();
assertNotEquals("Expected parsing to fail", 0, ret);
verify(mockHook).beforeParse(argThat(argMatcher));
verify(mockHook).afterParse(argThat(argMatcher), eq(true));
verify(mockHook, never()).beforeCompile(any());
verify(mockHook, never()).afterCompile(any(), anyBoolean());
verify(mockHook, never()).beforeExecution(any());
verify(mockHook, never()).afterExecution(any(), anyBoolean());
}
代码示例来源:origin: Mojang/brigadier
@SuppressWarnings("unchecked")
@Test
public void testExecuteRedirected() throws Exception {
final RedirectModifier<Object> modifier = mock(RedirectModifier.class);
final Object source1 = new Object();
final Object source2 = new Object();
when(modifier.apply(argThat(hasProperty("source", is(source))))).thenReturn(Lists.newArrayList(source1, source2));
final LiteralCommandNode<Object> concreteNode = subject.register(literal("actual").executes(command));
final LiteralCommandNode<Object> redirectNode = subject.register(literal("redirected").fork(subject.getRoot(), modifier));
final String input = "redirected actual";
final ParseResults<Object> parse = subject.parse(input, source);
assertThat(parse.getContext().getRange().get(input), equalTo("redirected"));
assertThat(parse.getContext().getNodes().size(), is(1));
assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot()));
assertThat(parse.getContext().getNodes().get(0).getRange(), equalTo(parse.getContext().getRange()));
assertThat(parse.getContext().getNodes().get(0).getNode(), is(redirectNode));
assertThat(parse.getContext().getSource(), is(source));
final CommandContextBuilder<Object> parent = parse.getContext().getChild();
assertThat(parent, is(notNullValue()));
assertThat(parent.getRange().get(input), equalTo("actual"));
assertThat(parent.getNodes().size(), is(1));
assertThat(parse.getContext().getRootNode(), equalTo(subject.getRoot()));
assertThat(parent.getNodes().get(0).getRange(), equalTo(parent.getRange()));
assertThat(parent.getNodes().get(0).getNode(), is(concreteNode));
assertThat(parent.getSource(), is(source));
assertThat(subject.execute(parse), is(2));
verify(command).run(argThat(hasProperty("source", is(source1))));
verify(command).run(argThat(hasProperty("source", is(source2))));
}
代码示例来源:origin: konmik/nucleus
@Test
public void testCreation() throws Exception {
assertEquals(mockPresenter, tested.getPresenter());
PowerMockito.verifyStatic(times(1));
ReflectionPresenterFactory.fromViewClass(argThat(new ArgumentMatcher<Class<?>>() {
@Override
public boolean matches(Object argument) {
return TestView.class.isAssignableFrom((Class)argument);
}
}));
verify(mockDelegate, times(1)).getPresenter();
verifyNoMoreInteractions(mockPresenter, mockDelegate, mockFactory);
}
代码示例来源:origin: pentaho/pentaho-kettle
@Test
public void testMissingFile() throws KettleException {
RowMeta inputRowMeta = new RowMeta();
ValueMetaString pathMeta = new ValueMetaString( "Path" );
inputRowMeta.addValueMeta( pathMeta );
String filepath = "missingFile";
Object[] rows = new Object[] { filepath };
RowSet inputRowSet = smh.getMockInputRowSet( rows );
inputRowSet.setRowMeta( inputRowMeta );
Calculator calculator = spy( new Calculator( smh.stepMeta, smh.stepDataInterface, 0, smh.transMeta, smh.trans ) );
calculator.addRowSetToInputRowSets( inputRowSet );
calculator.setInputRowMeta( inputRowMeta );
calculator.init( smh.initStepMetaInterface, smh.initStepDataInterface );
CalculatorMeta meta = new CalculatorMeta();
CalculatorMetaFunction[] calculations = new CalculatorMetaFunction[] {
new CalculatorMetaFunction( "result", CalculatorMetaFunction.CALC_MD5, "Path", null, null,
ValueMetaInterface.TYPE_STRING, 0, 0, false, "", "", "", "" ) };
meta.setCalculation( calculations );
meta.setFailIfNoFile( true );
boolean processed = calculator.processRow( meta, new CalculatorData() );
verify( calculator, times( 1 ) ).logError( argThat( new ArgumentMatcher<String>() {
@Override
public boolean matches( Object o ) {
return ((String) o ).contains( BaseMessages.getString( PKG, "Calculator.Log.NoFile" ) );
}
} ) );
assertFalse( processed );
}
代码示例来源:origin: konmik/nucleus
@Test
public void testCreation() throws Exception {
tested.onCreate(null);
assertEquals(mockPresenter, tested.getPresenter());
PowerMockito.verifyStatic(times(1));
ReflectionPresenterFactory.fromViewClass(argThat(new ArgumentMatcher<Class<?>>() {
@Override
public boolean matches(Object argument) {
return TestView.class.isAssignableFrom((Class) argument);
}
}));
verify(mockDelegate, times(1)).getPresenter();
verifyNoMoreInteractions(mockPresenter, mockDelegate, mockFactory);
}
内容来源于网络,如有侵权,请联系作者删除!