本文整理汇总了Java中org.mockito.Matchers类的典型用法代码示例。如果您正苦于以下问题:Java Matchers类的具体用法?Java Matchers怎么用?Java Matchers使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Matchers类属于org.mockito包,在下文中一共展示了Matchers类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testNoDataFlowServer
import org.mockito.Matchers; //导入依赖的package包/类
@Test
@DirtiesContext
public void testNoDataFlowServer() throws Exception{
String exceptionMessage = null;
final String ERROR_MESSAGE =
"I/O error on GET request for \"http://localhost:9393\": Connection refused; nested exception is java.net.ConnectException: Connection refused";
Mockito.doThrow(new ResourceAccessException(ERROR_MESSAGE))
.when(this.taskOperations).launch(Matchers.anyString(),
(Map<String,String>) Matchers.any(),
(List<String>) Matchers.any());
TaskLauncherTasklet taskLauncherTasklet = getTaskExecutionTasklet();
ChunkContext chunkContext = chunkContext();
try {
taskLauncherTasklet.execute(null, chunkContext);
}
catch (ResourceAccessException rae) {
exceptionMessage = rae.getMessage();
}
assertEquals(ERROR_MESSAGE, exceptionMessage);
}
开发者ID:spring-cloud-task-app-starters,项目名称:composed-task-runner,代码行数:21,代码来源:TaskLauncherTaskletTests.java
示例2: getNextResponse_should_return_valid_response
import org.mockito.Matchers; //导入依赖的package包/类
@Test(groups = "SearchFiles.getNextResponse")
public void getNextResponse_should_return_valid_response() {
try {
SearchFiles searchFiles = new SearchFiles(config, null,
searchRequest);
PowerMockito.when(
HttpUtils.doGet(Mockito.anyString(),
Matchers.<Map<String, String>> any())).thenReturn(
TEST_RESPONSE);
SearchFilesResponse response = searchFiles.getNextResponse();
SearchFilesTest.checkTestResponse(response);
Assert.assertEquals(searchFiles.currentSearchPageIndex(), 0);
} catch (StockException e) {
Assert.fail("Didn't expect the StockException!", e);
}
}
示例3: getNextResponse_should_throw_exception_since_offset_exceed_result_count
import org.mockito.Matchers; //导入依赖的package包/类
@Test(groups = "SearchFiles.getNextResponse", expectedExceptions = { StockException.class }, expectedExceptionsMessageRegExp = "No more search results available!")
public void getNextResponse_should_throw_exception_since_offset_exceed_result_count()
throws StockException {
searchRequest.getSearchParams().setOffset(
TEST_NB_RESULTS - TEST_DEFAULT_LIMIT);
SearchFiles searchFiles = new SearchFiles(config, null, searchRequest);
PowerMockito.when(
HttpUtils.doGet(Mockito.anyString(),
Matchers.<Map<String, String>> any())).thenReturn(
TEST_RESPONSE);
searchFiles.getNextResponse();
// calling next again will exceed results count limit
searchFiles.getNextResponse();
}
示例4: getNextResponse_should_throw_exception_when_result_count_zero
import org.mockito.Matchers; //导入依赖的package包/类
@Test(groups = "SearchFiles.getNextResponse", expectedExceptions = { StockException.class }, expectedExceptionsMessageRegExp = "No more search results available!")
public void getNextResponse_should_throw_exception_when_result_count_zero()
throws StockException, IOException {
String responseString = "{\"nb_results\":0,\"files\":[] }";
PowerMockito.mockStatic(DownSampleUtil.class);
searchRequest.getSearchParams().setSimilarImage(true);
searchRequest.setLocale("en-US");
searchRequest.setSimilarImage(new byte[10]);
SearchFiles searchFiles = new SearchFiles(config, "accessToken",
searchRequest);
PowerMockito.when(
HttpUtils.doMultiPart(Mockito.anyString(),
Mockito.any(byte[].class),
Matchers.<Map<String, String>> any())).thenReturn(
responseString);
PowerMockito.when(
DownSampleUtil.downSampleImageUtil(
Mockito.any(byte[].class))).thenReturn(
new byte[10]);
searchFiles.getNextResponse();
searchFiles.getNextResponse();
}
示例5: prefetchData_withoutTemplates_bug12479
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void prefetchData_withoutTemplates_bug12479() {
// given
List<Product> products = new ArrayList<Product>();
products.add(product);
products.add(customerProduct);
LocalizerFacade facadeMock = spy(facade);
// when
ProductAssembler.prefetchData(products, facadeMock,
PerformanceHint.ONLY_FIELDS_FOR_LISTINGS);
// then
verify(facadeMock, times(1)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<Long> objectkeys = objectKeyCaptor.getValue();
assertEquals(2, objectkeys.size());
assertEquals(Long.valueOf(product.getKey()), objectkeys.get(0));
assertEquals(Long.valueOf(customerProduct.getKey()), objectkeys.get(1));
}
示例6: getServicePort
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void getServicePort() throws MalformedURLException {
// given
Map<String, Setting> settings = getSettingsForMode("SAML_SP");
IdentityService idSvcMock = Mockito.mock(IdentityService.class);
Service serviceMock = Mockito.mock(Service.class);
doReturn(serviceMock).when(besDAO).createWebService(any(URL.class),
any(QName.class));
when(
serviceMock.getPort(Matchers.any(QName.class),
eq(IdentityService.class))).thenReturn(idSvcMock);
// when
IdentityService idSvc = besDAO.getServicePort(IdentityService.class,
settings);
// then
assertTrue(IdentityService.class.isAssignableFrom(idSvc.getClass()));
}
示例7: saveLangauges
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void saveLangauges() throws Exception {
// given
List<POSupportedLanguage> poList = new ArrayList<POSupportedLanguage>();
poList.add(getPOSupportedLanguage(1, "en", true, true));
poList.add(getPOSupportedLanguage(2, "de", true, false));
poList.add(getPOSupportedLanguage(3, "ja", true, false));
poList.add(getPOSupportedLanguage(4, "te", false, false));
doNothing().when(operatorServiceLocal).saveLanguages(
Matchers.anyListOf(SupportedLanguage.class));
// when
service.saveLanguages(poList);
// then
verify(service.operatorService, times(1)).saveLanguages(
Matchers.anyListOf(SupportedLanguage.class));
}
示例8: delete_SubscriptionsChargeableActive_TechnicalServiceNotAliveException
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void delete_SubscriptionsChargeableActive_TechnicalServiceNotAliveException()
throws Exception {
Set<Subscription> subs = createSubs(SubscriptionStatus.ACTIVE);
Subscription sub = subs.iterator().next();
sub.getPriceModel().setType(PriceModelType.PRO_RATA);
// ensure that exception is not thrown
Mockito.doThrow(new TechnicalServiceNotAliveException())
.when(applicationServiceMock)
.deactivateInstance(Matchers.eq(sub));
paymentInfo.setSubscriptions(subs);
accountServiceBean.deletePaymentInfo(pi);
// verify that setRollbackOnly has been called never
Mockito.verify(sessionContextMock, Mockito.never()).setRollbackOnly();
Assert.assertNull(sub.getPaymentInfo());
Assert.assertEquals(SubscriptionStatus.SUSPENDED, sub.getStatus());
Mockito.verify(paymentServiceMock, Mockito.times(1))
.deregisterPaymentInPSPSystem(Matchers.eq(paymentInfo));
Mockito.verify(applicationServiceMock, Mockito.times(1))
.deactivateInstance(Matchers.eq(sub));
}
示例9: shouldTestInitNoConfiguration
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void shouldTestInitNoConfiguration() {
// given
Element element = mock(Element.class);
MediaWrapper<MediaBase> mediaDescriptor = mock(MediaWrapper.class);
when(mediaDescriptor.getMediaObject()).thenReturn(mediaBase);
when(mediaBase.getElement()).thenReturn(element);
instance.setMediaWrapper(mediaDescriptor);
mediaConfiguration = new BaseMediaConfiguration(new HashMap<String, String>(), false);
instance.setBaseMediaConfiguration(mediaConfiguration);
// when
instance.init();
// then
verify(mediaBase).setPreload(Matchers.eq(getAssumedMediaPreloadType()));
verify(mediaBase).setControls(Matchers.eq(true));
for (Map.Entry<HTML5MediaEventsType, MediaEventTypes> typePair : createEventsPairMap().entrySet()) {
verify(html5MediaNativeListeners).addListener(element, typePair.getKey().toString());
}
}
示例10: shouldInitiateValues_whenMediaBaseIsSet
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void shouldInitiateValues_whenMediaBaseIsSet() {
// given
Element element = mock(Element.class);
MediaWrapper<MediaBase> mediaDescriptor = mock(MediaWrapper.class);
when(mediaDescriptor.getMediaObject()).thenReturn(mediaBase);
when(mediaBase.getElement()).thenReturn(element);
instance.setMediaWrapper(mediaDescriptor);
instance.setBaseMediaConfiguration(mediaConfiguration);
// when
instance.init();
// then
verify(mediaBase).setPreload(Matchers.eq(getAssumedMediaPreloadType()));
verify(mediaBase).setControls(Matchers.eq(false));
for (Map.Entry<HTML5MediaEventsType, MediaEventTypes> typePair : createEventsPairMap().entrySet()) {
verify(html5MediaNativeListeners).addListener(element, typePair.getKey().toString());
}
}
示例11: testAuthenticateLoginMissingHeader
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void testAuthenticateLoginMissingHeader() throws Exception {
Mockito.when(session.getAttribute(Matchers.eq("loggedInUserId")))
.thenReturn(null);
Mockito.when(req.getHeader(Matchers.eq("Authorization")))
.thenReturn(null);
// And go!
filter.doFilter(req, resp, chain);
// Check whether user will be asked for login
Mockito.verify(resp).setStatus(Matchers.eq(401));
Mockito.verify(resp).setHeader(Matchers.eq("WWW-Authenticate"),
Matchers.startsWith("Basic "));
}
示例12: dragEndHandlerTest
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void dragEndHandlerTest() {
DragEndHandler endHandler = mock(DragEndHandler.class);
ArgumentCaptor<DragEndEventWrapper> captor = ArgumentCaptor.forClass(DragEndEventWrapper.class);
when(draggableWidget.addDragStopHandler(Matchers.any(DragStopEventHandler.class))).then(new Answer<HandlerRegistration>() {
@Override
public HandlerRegistration answer(InvocationOnMock invocation) throws Throwable {
stopHandler = (DragStopEventHandler) invocation.getArguments()[0];
return null;
}
});
doNothing().when(instance).setData(Matchers.anyString(), Matchers.anyString());
doReturn(null).when(instance).getData(Matchers.anyString());
instance.wrap(endHandler);
stopHandler.onDragStop(mock(DragStopEvent.class));
verify(endHandler).onDragEnd(captor.capture());
DragEndEventWrapper event = captor.getValue();
event.setData("text", "text");
event.getData("text");
verify(instance).setData(Matchers.eq("text"), Matchers.eq("text"));
verify(instance).getData(Matchers.eq("text"));
}
示例13: testDragNoConnect
import org.mockito.Matchers; //导入依赖的package包/类
/** Drag together two incompatible blocks. */
@Test
public void testDragNoConnect() throws BlockLoadingException {
// Setup
mTouchedBlock = mDraggedBlock = mBlockFactory.obtainBlockFrom(
new BlockTemplate().ofType("simple_input_output"));
mTargetBlock = mBlockFactory.obtainBlockFrom(new BlockTemplate().ofType("output_no_input"));
Mockito.when(mMockBlockClipDataHelper.isBlockData(any(ClipDescription.class)))
.thenReturn(true);
Mockito.when(mMockConnectionManager.findBestConnection(any(Block.class), anyInt()))
.thenReturn(null);
setupDrag();
dragBlockToTarget();
Mockito.verify(mMockConnectionManager, atLeastOnce())
.findBestConnection(Matchers.same(mTouchedBlock), anyInt());
Mockito.verify(mMockController, never())
.connect(any(Connection.class), any(Connection.class));
}
示例14: prefetchData_withTemplates_bug12479
import org.mockito.Matchers; //导入依赖的package包/类
@Test
public void prefetchData_withTemplates_bug12479() {
// given
List<Product> products = new ArrayList<Product>();
products.add(product);
Product anotherProduct = new Product();
anotherProduct.setType(ServiceType.PARTNER_TEMPLATE);
anotherProduct.setConfiguratorUrl("some value");
anotherProduct.setTemplate(template);
products.add(anotherProduct);
products.add(customerProduct);
LocalizerFacade facadeMock = spy(facade);
// when
ProductAssembler.prefetchData(products, facadeMock,
PerformanceHint.ONLY_FIELDS_FOR_LISTINGS);
// then
verify(facadeMock, times(1)).prefetch(objectKeyCaptor.capture(),
Matchers.anyListOf(LocalizedObjectTypes.class));
List<Long> objectkeys = objectKeyCaptor.getValue();
assertEquals(3, objectkeys.size());
assertEquals(Long.valueOf(product.getKey()), objectkeys.get(0));
assertEquals(Long.valueOf(template.getKey()), objectkeys.get(1));
assertEquals(Long.valueOf(customerProduct.getKey()), objectkeys.get(2));
}
示例15: getPreviousLicenseHistory_should_return_valid_response
import org.mockito.Matchers; //导入依赖的package包/类
@Test(groups = "LicenseHistory.getPreviousLicenseHistory")
public void getPreviousLicenseHistory_should_return_valid_response() {
try {
licenseHistoryRequest.getSearchParams().setOffset(TEST_DEFAULT_LIMIT);
LicenseHistory licenseHistory = new LicenseHistory(config, null,
licenseHistoryRequest);
PowerMockito.when(
HttpUtils.doGet(Mockito.anyString(),
Matchers.<Map<String, String>> any())).thenReturn(
TEST_RESPONSE);
LicenseHistoryResponse response = licenseHistory.getPreviousLicenseHistory();
LicenseHistoryTest.checkTestResponse(response);
Assert.assertEquals(licenseHistory.currentLicenseHistoryPageIndex(), 0);
} catch (StockException e) {
Assert.fail("Didn't expect the StockException!", e);
}
}