本文整理了Java中org.mockito.Mockito.matches()
方法的一些代码示例,展示了Mockito.matches()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.matches()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:matches
暂无
代码示例来源:origin: cloudfoundry/uaa
@Test
public void request_with_max_age_redirect_expected() throws Exception {
SecurityContextHolder.getContext().setAuthentication(authentication);
when(authentication.getAuthenticatedTime()).thenReturn(System.currentTimeMillis() - 2000);
request.setParameter("client_id", "testclient");
request.setParameter("max_age", "1");
request.setParameter("scope", "openid");
filter.doFilterInternal(request, response, chain);
verify(chain, never()).doFilter(same(request), same(response));
// verify that the redirect was happening and the url does not contain the max_age parameter
verify(response, times(1)).sendRedirect(matches("^((?!max_age).)*$"));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void request_with_prompt_login() throws Exception {
SecurityContextHolder.getContext().setAuthentication(authentication);
request.setParameter("client_id", "testclient");
request.setParameter("prompt", "login");
request.setParameter("scope", "openid");
filter.doFilterInternal(request, response, chain);
verify(chain, never()).doFilter(same(request), same(response));
// verify that the redirect is happening and the redirect url does not contain the prompt parameter
verify(response, times(1)).sendRedirect(matches("^((?!prompt).)*$"));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void doesContinueWithFilterChain_EvenIfClientSecretExpired() throws IOException, ServletException, ParseException {
BaseClientDetails clientDetails = new BaseClientDetails("client-1", "none", "uaa.none", "client_credentials", "http://localhost:5000/uaadb" );
Calendar expiredDate = Calendar.getInstance();
expiredDate.set(2016, 1, 1);
clientDetails.setAdditionalInformation(createTestAdditionalInformation(expiredDate));
when(clientDetailsService.loadClientByClientId(Mockito.matches("app"))).thenReturn(clientDetails);
MockFilterChain chain = mock(MockFilterChain.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Basic " + CREDENTIALS_HEADER_STRING);
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, chain);
verify(clientAuthenticationManager).authenticate(any(Authentication.class));
}
代码示例来源:origin: cloudfoundry/uaa
@Test
public void doesContinueWithFilterChain_IfClientSecretNotExpired() throws IOException, ServletException, ParseException {
BaseClientDetails clientDetails = new BaseClientDetails("client-1", "none", "uaa.none", "client_credentials",
"http://localhost:5000/uaadb" );
Calendar previousDay = Calendar.getInstance();
previousDay.roll(Calendar.DATE, -1);
clientDetails.setAdditionalInformation(createTestAdditionalInformation(previousDay));
when(clientDetailsService.loadClientByClientId(Mockito.matches("app"))).thenReturn(clientDetails);
UsernamePasswordAuthentication authResult =
new UsernamePasswordAuthentication("app","appclientsecret");
authResult.setAuthenticated(true);
when(clientAuthenticationManager.authenticate(any())).thenReturn(authResult);
MockFilterChain chain = mock(MockFilterChain.class);
MockHttpServletRequest request = new MockHttpServletRequest();
request.addHeader("Authorization", "Basic " + CREDENTIALS_HEADER_STRING);
MockHttpServletResponse response = new MockHttpServletResponse();
filter.doFilter(request, response, chain);
verify(clientAuthenticationManager).authenticate(any(Authentication.class));
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testReadDuplicateComponentIds() throws IOException {
JPEGImageReader reader = createReader();
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/duplicate-component-ids.jpg")));
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
reader.addIIOReadWarningListener(listener);
assertEquals(367, reader.getWidth(0));
assertEquals(242, reader.getHeight(0));
BufferedImage image = reader.read(0, null);
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component ID.*(?-i)SOF.*"), contains("1")));
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component ID.*(?-i)SOS.*"), contains("1")));
assertNotNull(image);
assertEquals(367, image.getWidth());
assertEquals(242, image.getHeight());
assertEquals(ColorSpace.TYPE_RGB, image.getColorModel().getColorSpace().getType());
}
finally {
reader.dispose();
}
}
代码示例来源:origin: haraldk/TwelveMonkeys
@Test
public void testReadAdobeAPP14CMYKAnd3channelData() throws IOException {
JPEGImageReader reader = createReader();
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/exif-jfif-app13-app14ycck-3channel.jpg")));
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
reader.addIIOReadWarningListener(listener);
assertEquals(310, reader.getWidth(0));
assertEquals(384, reader.getHeight(0));
BufferedImage image = reader.read(0, null);
verify(listener, times(1)).warningOccurred(eq(reader), matches("(?i).*Adobe App14.*(?-i)CMYK.*SOF.*"));
assertNotNull(image);
assertEquals(310, image.getWidth());
assertEquals(384, image.getHeight());
assertEquals(ColorSpace.TYPE_RGB, image.getColorModel().getColorSpace().getType());
}
finally {
reader.dispose();
}
}
代码示例来源:origin: sixhours-team/memcached-spring-boot
@Test
public void whenGetWithValueLoaderThrowsExceptionThenValueRetrievalException() {
when(memcachedClient.get(namespaceKey))
.thenReturn(NAMESPACE_KEY_VALUE)
.thenReturn(null);
assertThatThrownBy(() ->
memcachedCache.get(CACHED_OBJECT_KEY, () -> {
throw new Exception("exception to be wrapped");
}))
.isInstanceOf(Cache.ValueRetrievalException.class)
.hasFieldOrPropertyWithValue("key", CACHED_OBJECT_KEY);
verify(memcachedClient, times(2)).get(namespaceKey);
verify(memcachedClient, times(2)).get(matches(CACHED_KEY_REGEX));
verify(memcachedClient).set(eq(namespaceKey), eq(CACHE_EXPIRATION), anyString());
}
代码示例来源:origin: mcekovic/tennis-crystal-ball
Visitor visitAndVerifyFirstVisit(String ipAddress, VerificationMode mode) {
when(repository.find(ipAddress)).thenReturn(Optional.empty());
when(repository.create(any(), any(), any(), any())).thenAnswer(invocation -> {
Object[] args = invocation.getArguments();
return new Visitor(1L, (String)args[0], (String)args[1], (String)args[2], (String)args[3], 1, Instant.now());
});
Visitor visitor = manager.visit(ipAddress, WEB_BROWSER.name());
assertThat(visitor.getIpAddress()).isEqualTo(ipAddress);
assertThat(visitor.getHits()).isEqualTo(1);
verify(repository, mode).find(ipAddress);
verify(repository, mode).create(matches(ipAddress), any(), any(), any());
verifyNoMoreInteractions(repository);
verify(geoIPService, mode).getCountry(ipAddress);
verifyNoMoreInteractions(geoIPService);
return visitor;
}
}
代码示例来源:origin: kaif-open/kaif
@Test
public void resendActivation() {
Account account = service.createViaEmail("myname", "foo@gmail.com", "pwd123", lc);
Mockito.reset(mockMailAgent);
service.resendActivation(account, lc);
verify(mockMailAgent).sendAccountActivation(eq(lc),
eq(account),
Mockito.matches("[a-z\\-0-9]{36}"));
assertEquals(2, accountDao.listOnceTokens().size());
}
代码示例来源:origin: kaif-open/kaif
@Test
public void sendResetPassword() {
Account account = service.createViaEmail("myname", "foo@gmail.com", "pwd123", lc);
Mockito.reset(mockMailAgent);
service.sendResetPassword("myname", "foo@gmail.com", lc);
verify(mockMailAgent).sendResetPassword(eq(lc),
eq(account),
Mockito.matches("[a-z\\-0-9]{36}"));
assertTrue(accountDao.listOnceTokens()
.stream()
.anyMatch(token -> token.getTokenType() == AccountOnceToken.Type.FORGET_PASSWORD));
}
代码示例来源:origin: it.tidalwave.northernwind.rca/it-tidalwave-northernwind-rca-ui-structure-editor
/*******************************************************************************************************************
*
******************************************************************************************************************/
@Test
public void must_populate_the_presentation_on_reception_of_selected_node()
throws IOException
{
// given
// when(properties.getProperty(eq(PROPERTY_FULL_TEXT), anyString())).thenReturn("full text");
// when(properties.getProperty(eq(PROPERTY_TITLE), anyString())).thenReturn("title");
reset(presentation);
// when
underTest.onSiteNodeSelected(SiteNodeSelectedEvent.of(siteNode));
// then
verify(presentation).populate(matches("Viewer not implemented for .*"));
verify(presentation).populateProperties(same(pm));
verify(presentation).showUp();
verifyNoMoreInteractions(presentation);
// assertThat(underTest.bindings.document.get(), is("full text"));
// assertThat(underTest.bindings.title.get(), is("title"));
}
代码示例来源:origin: apache/hadoop-common
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
} else {
Mockito.verify(response).setHeader(Mockito.eq(KerberosAuthenticator.WWW_AUTHENTICATE),
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
代码示例来源:origin: hopshadoop/hops
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
} else {
Mockito.verify(response).setHeader(Mockito.eq(KerberosAuthenticator.WWW_AUTHENTICATE),
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
代码示例来源:origin: io.hops/hadoop-auth
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_OK);
} else {
Mockito.verify(response).setHeader(Mockito.eq(KerberosAuthenticator.WWW_AUTHENTICATE),
Mockito.matches(KerberosAuthenticator.NEGOTIATE + " .*"));
Mockito.verify(response).setStatus(HttpServletResponse.SC_UNAUTHORIZED);
代码示例来源:origin: info.magnolia/magnolia-core
verify(callback, after(TIMEOUT).atLeastOnce()).processEvent(eq(Event.PROPERTY_ADDED), matches(propertyPathRegex.pattern()));
verifyNoMoreInteractions(callback);
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg
@Test
public void testReadDuplicateComponentIds() throws IOException {
JPEGImageReader reader = createReader();
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/duplicate-component-ids.jpg")));
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
reader.addIIOReadWarningListener(listener);
assertEquals(367, reader.getWidth(0));
assertEquals(242, reader.getHeight(0));
BufferedImage image = reader.read(0, null);
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component ID.*(?-i)SOF.*"), contains("1")));
verify(listener, times(1)).warningOccurred(eq(reader), and(matches("(?i).*duplicate component ID.*(?-i)SOS.*"), contains("1")));
assertNotNull(image);
assertEquals(367, image.getWidth());
assertEquals(242, image.getHeight());
assertEquals(ColorSpace.TYPE_RGB, image.getColorModel().getColorSpace().getType());
}
finally {
reader.dispose();
}
}
代码示例来源:origin: blurpy/kouchat-android
/**
* Tests sendClient().
*
* Expects: 13132531!CLIENT#Christian:(KouChat v0.9.9-dev null)[134]{Linux}<2222>/4444\
*/
@Test
public void testSendClientMessage() {
final String startsWith = "(" + me.getClient() + ")[";
final String middle = ".+\\)\\[\\d+\\]\\{.+"; // like:)[134[{
final String endsWidth = "]{" + me.getOperatingSystem() + "}<2222>/4444\\";
messages.sendClient();
verify(service).sendMessageToAllUsers(startsWith(createMessage("CLIENT") + startsWith));
verify(service).sendMessageToAllUsers(matches(middle));
verify(service).sendMessageToAllUsers(endsWith(endsWidth));
}
代码示例来源:origin: com.twelvemonkeys.imageio/imageio-jpeg
@Test
public void testReadAdobeAPP14CMYKAnd3channelData() throws IOException {
JPEGImageReader reader = createReader();
try {
reader.setInput(ImageIO.createImageInputStream(getClassLoaderResource("/jpeg/exif-jfif-app13-app14ycck-3channel.jpg")));
IIOReadWarningListener listener = mock(IIOReadWarningListener.class);
reader.addIIOReadWarningListener(listener);
assertEquals(310, reader.getWidth(0));
assertEquals(384, reader.getHeight(0));
BufferedImage image = reader.read(0, null);
verify(listener, times(1)).warningOccurred(eq(reader), matches("(?i).*Adobe App14.*(?-i)CMYK.*SOF.*"));
assertNotNull(image);
assertEquals(310, image.getWidth());
assertEquals(384, image.getHeight());
assertEquals(ColorSpace.TYPE_RGB, image.getColorModel().getColorSpace().getType());
}
finally {
reader.dispose();
}
}
代码示例来源:origin: opencb/opencga
@Test
public void testCustomAnnotation() throws Exception {
annotate(new Query(), new QueryOptions());
checkAnnotation(v -> true);
DummyVariantDBAdaptor dbAdaptor = mockVariantDBAdaptor();
File file = opencga.createFile(studyId, "custom_annotation/myannot.gff", sessionId);
QueryOptions options = new QueryOptions()
.append(VariantAnnotationManager.LOAD_FILE, file.getId())
.append(VariantAnnotationManager.CUSTOM_ANNOTATION_KEY, "myAnnot");
options.put(StorageOperation.CATALOG_PATH, outputId);
variantManager.annotate(String.valueOf(studyId), new Query(), opencga.createTmpOutdir(studyId, "annot", sessionId), options, sessionId);
verify(dbAdaptor, atLeastOnce()).updateCustomAnnotations(any(), matches("myAnnot"), any(), anyLong(), any());
file = opencga.createFile(studyId, "custom_annotation/myannot.bed", sessionId);
options = new QueryOptions()
.append(VariantAnnotationManager.LOAD_FILE, file.getId())
.append(VariantAnnotationManager.CUSTOM_ANNOTATION_KEY, "myAnnot2");
options.put(StorageOperation.CATALOG_PATH, outputId);
variantManager.annotate(String.valueOf(studyId), new Query(), opencga.createTmpOutdir(studyId, "annot", sessionId), options, sessionId);
verify(dbAdaptor, atLeastOnce()).updateCustomAnnotations(any(), matches("myAnnot2"), any(), anyLong(), any());
}
代码示例来源:origin: kaif-open/kaif
@Test
public void createViaEmail() {
Account account = service.createViaEmail("myname", "foo@gmail.com", "pwd123", lc);
Account loaded = accountDao.findById(account.getAccountId()).get();
assertEquals(account, loaded);
assertEquals("foo@gmail.com", loaded.getEmail());
assertFalse(loaded.isActivated());
assertEquals(EnumSet.of(Authority.TOURIST), loaded.getAuthorities());
verify(mockMailAgent).sendAccountActivation(eq(lc),
eq(account),
Mockito.matches("[a-z\\-0-9]{36}"));
AccountOnceToken token = accountDao.listOnceTokens().get(0);
assertEquals(account.getAccountId(), token.getAccountId());
assertEquals(AccountOnceToken.Type.ACTIVATION, token.getTokenType());
assertFalse(token.isExpired(Instant.now().plus(Duration.ofHours(23))));
assertFalse(token.isComplete());
AccountStats stats = service.loadAccountStats(account.getUsername());
assertEquals(AccountStats.zero(account.getAccountId()), stats);
}
内容来源于网络,如有侵权,请联系作者删除!