org.assertj.core.api.AbstractCharSequenceAssert.matches()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(11.2k)|赞(0)|评价(0)|浏览(85)

本文整理了Java中org.assertj.core.api.AbstractCharSequenceAssert.matches()方法的一些代码示例,展示了AbstractCharSequenceAssert.matches()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractCharSequenceAssert.matches()方法的具体详情如下:
包路径:org.assertj.core.api.AbstractCharSequenceAssert
类名称:AbstractCharSequenceAssert
方法名:matches

AbstractCharSequenceAssert.matches介绍

[英]Verifies that the actual CharSequence matches the given regular expression.

Example :

// assertion will pass 
assertThat("Frodo").matches("..o.o"); 
// assertion will fail 
assertThat("Frodo").matches(".*d");

[中]验证实际的CharSequence是否与给定的正则表达式匹配。
例子:

// assertion will pass 
assertThat("Frodo").matches("..o.o"); 
// assertion will fail 
assertThat("Frodo").matches(".*d");

代码示例

代码示例来源:origin: prestodb/presto

public void waitForPrompt()
  {
    assertThat(nextOutputToken()).matches(PRESTO_PROMPT_PATTERN);
  }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void hash_token() {
  String hash = underTest.hash("1234567890123456789012345678901234567890");

  assertThat(hash)
   .hasSize(96)
   .isEqualTo("b2501fc3833ae6feba7dc8a973a22d709b7c796ee97cbf66db2c22df873a9fa147b1b630878f771457b7769efd9ffa0d")
   .matches("[0-9a-f]+");
 }
}

代码示例来源:origin: stagemonitor/stagemonitor

@Test
public void getVersionFromPomProperties() throws Exception {
  assertThat(VersionUtils.getVersionFromPomProperties(ByteBuddy.class, BYTEBUDDY_GROUP, "byte-buddy")).matches(VERSION_PATTERN);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void test_format_of_uuid() {
  String uuid = underTest.create();

  assertThat(uuid.length()).isGreaterThan(10).isLessThan(40);

  // URL-safe: only letters, digits, dash and underscore.
  assertThat(uuid).matches("^[\\w\\-_]+$");
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
 public void test_format_of_uuid() {
  String uuid = underTest.create();

  assertThat(uuid.length()).isGreaterThan(10).isLessThan(40);

  // URL-safe: only letters, digits, dash and underscore.
  assertThat(uuid).matches("^[\\w\\-_]+$");
 }
}

代码示例来源:origin: cbeust/testng

@Test(dataProvider = "dp")
 public void verify(int number, String passed) {
  TestNG tng = create(TestContextSample.class);
  tng.setGroups(String.valueOf(number));

  InvokedMethodNameListener listener = new InvokedMethodNameListener();
  tng.addListener(listener);

  tng.run();

  assertThat(listener.getSucceedMethodNames()).hasSize(1);
  assertThat(listener.getSucceedMethodNames().get(0))
    .matches(passed + "\\(\\[foo(,foo){" + (number - 1) + "}?\\]\\)");
  assertThat(listener.getFailedMethodNames()).isEmpty();
 }
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void file_description() {
 UriReader uriReader = new UriReader(new UriReader.SchemeProcessor[0]);
 // the prefix file:/ is removed
 assertThat(uriReader.description(testFile)).doesNotMatch("file:/.*");
 assertThat(uriReader.description(testFile)).matches(".*foo\\.txt");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void uri_description() throws URISyntaxException {
 String description = new DefaultHttpDownloader(new MapSettings().asConfig()).description(new URI("http://sonarsource.org"));
 assertThat(description).matches("http://sonarsource.org \\(.*\\)");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void silently_catch_error_when_external_server_does_not_answer() throws Exception {
 Webhook webhook = new Webhook(WEBHOOK_UUID, PROJECT_UUID, CE_TASK_UUID, RandomStringUtils.randomAlphanumeric(40),"my-webhook", server.url("/ping").toString());
 server.shutdown();
 WebhookDelivery delivery = newSender().call(webhook, PAYLOAD);
 assertThat(delivery.getHttpStatus()).isEmpty();
 assertThat(delivery.getDurationInMs().get()).isGreaterThanOrEqualTo(0);
 // message can be "Connection refused" or "connect timed out"
 assertThat(delivery.getErrorMessage().get()).matches("(.*Connection refused.*)|(.*connect timed out.*)");
 assertThat(delivery.getAt()).isEqualTo(NOW);
 assertThat(delivery.getWebhook()).isSameAs(webhook);
 assertThat(delivery.getPayload()).isSameAs(PAYLOAD);
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void update_return_the_full_object_with_id() throws Exception {
 int id = insertMetric(newDefaultMetric().setDescription("another-description"));
 WsTester.Result requestResult = newRequest()
  .setParam(PARAM_ID, String.valueOf(id))
  .setParam(PARAM_DESCRIPTION, DEFAULT_DESCRIPTION)
  .execute();
 dbSession.commit();
 requestResult.assertJson(getClass(), "metric.json");
 assertThat(requestResult.outputAsString()).matches(".*\"id\"\\s*:\\s*\"" + id + "\".*");
}

代码示例来源:origin: SonarSource/sonarqube

@Test
public void return_metric_with_id() throws Exception {
 WsTester.Result result = newRequest()
  .setParam(PARAM_KEY, DEFAULT_KEY)
  .setParam(PARAM_NAME, DEFAULT_NAME)
  .setParam(PARAM_TYPE, DEFAULT_TYPE)
  .setParam(PARAM_DOMAIN, DEFAULT_DOMAIN)
  .setParam(PARAM_DESCRIPTION, DEFAULT_DESCRIPTION)
  .execute();
 result.assertJson(getClass(), "metric.json");
 assertThat(result.outputAsString()).matches(".*\"id\"\\s*:\\s*\"\\w+\".*");
}

代码示例来源:origin: sixt/ja-micro

@Test
public void testRpcCallExceptionJsonRpc() throws IOException {
  String input = "{\"service\":\"x\",\"method\":\"jsonRpcWithException\",\"params\":[{}],\"id\":\"dead-beef\"}";
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(MockHttpServletResponse.class);
  BufferedReader readerFromRequest = new BufferedReader(new StringReader(input));
  when(request.getReader()).thenReturn(readerFromRequest);
  CharArrayWriter charArryWriter = new CharArrayWriter(512);
  PrintWriter writer = new PrintWriter(charArryWriter);
  when(response.getWriter()).thenReturn(writer);
  doCallRealMethod().when(response).setStatus(anyInt());
  doCallRealMethod().when(response).getStatus();
  servlet.doPost(request, response);
  String responseAsString = charArryWriter.toString();
  LOGGER.debug(responseAsString);
  assertThat(responseAsString).contains("no p4s5!");
  assertThat(responseAsString).matches(Pattern.compile(".*retriable.+true.*"));
  assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
}

代码示例来源:origin: grandcentrix/ThirtyInch

@Test
public void testLogVarargs() throws Exception {
  final TiLog.Logger logger = mock(TiLog.Logger.class);
  final LoggingInterceptor loggingInterceptor = new LoggingInterceptor(logger);
  final TestView view = loggingInterceptor.intercept(new TestViewImpl());
  final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
  view.varargs("Buenos Aires", "Córdoba", "La Plata");
  verify(logger).log(anyInt(), anyString(), msgCaptor.capture());
  assertThat(msgCaptor.getValue())
      .matches("varargs\\(\\{Object\\[\\]\\[3\\]@[\\da-f]{1,8}\\} \\"
          + "[Buenos Aires, Córdoba, La Plata\\]\\)");
}

代码示例来源:origin: grandcentrix/ThirtyInch

@Test
public void testLogEmptyList() throws Exception {
  final TiLog.Logger logger = mock(TiLog.Logger.class);
  final LoggingInterceptor loggingInterceptor = new LoggingInterceptor(logger);
  final TestView view = loggingInterceptor.intercept(new TestViewImpl());
  final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
  view.twoArgs(new ArrayList(), "B");
  verify(logger).log(anyInt(), anyString(), msgCaptor.capture());
  assertThat(msgCaptor.getValue())
      .matches("twoArgs\\("
          + "\\{ArrayList\\[0\\]@[\\da-f]{1,8}\\} \\[\\], "
          + "B"
          + "\\)");
}

代码示例来源:origin: sixt/ja-micro

@Test
public void testRpcCallExceptionJsonRpcWithHttpExposed() throws IOException {
  String input = "{\"service\":\"x\",\"method\":\"jsonRpcWithException\",\"params\":[{}],\"id\":\"dead-beef\"}";
  HttpServletRequest request = mock(HttpServletRequest.class);
  HttpServletResponse response = mock(MockHttpServletResponse.class);
  BufferedReader readerFromRequest = new BufferedReader(new StringReader(input));
  when(request.getReader()).thenReturn(readerFromRequest);
  CharArrayWriter charArryWriter = new CharArrayWriter(512);
  PrintWriter writer = new PrintWriter(charArryWriter);
  when(response.getWriter()).thenReturn(writer);
  doCallRealMethod().when(response).setStatus(anyInt());
  doCallRealMethod().when(response).getStatus();
  ServiceProperties props = new ServiceProperties();
  props.addProperty(FeatureFlags.FLAG_EXPOSE_ERRORS_HTTP, "true");
  servlet = new JsonHandler(handlerDictionary, metricRegistry, handlerMetrics, props, null);
  servlet.doPost(request, response);
  String responseAsString = charArryWriter.toString();
  LOGGER.debug(responseAsString);
  assertThat(responseAsString).contains("no p4s5!");
  assertThat(responseAsString).matches(Pattern.compile(".*retriable.+true.*"));
  assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}

代码示例来源:origin: grandcentrix/ThirtyInch

@Test
public void testLogArray() throws Exception {
  final TiLog.Logger logger = mock(TiLog.Logger.class);
  final LoggingInterceptor loggingInterceptor = new LoggingInterceptor(logger);
  final TestView view = loggingInterceptor.intercept(new TestViewImpl());
  final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
  final String[] array = new String[]{"Buenos Aires", "Córdoba", "La Plata"};
  view.twoArgs(array, "B");
  verify(logger).log(anyInt(), anyString(), msgCaptor.capture());
  assertThat(msgCaptor.getValue())
      .matches("twoArgs\\(\\{String\\[\\]\\[3\\]@[\\da-f]{1,8}\\} \\"
          + "[Buenos Aires, Córdoba, La Plata\\], B\\)");
}

代码示例来源:origin: HubSpot/Singularity

@Test
public void itRetriesRequestsThatErrorDueToDeadHost() {
 when(httpClient.execute(any()))
   .thenReturn(response);
 when(response.getStatusCode())
   .thenReturn(503)
   .thenReturn(200);
 when(response.isServerError())
   .thenReturn(true)
   .thenReturn(false);
 singularityClient.pauseSingularityRequest("requestId", Optional.absent());
 verify(httpClient, times(2))
   .execute(requestCaptor.capture());
 HttpRequest sentRequest = requestCaptor.getValue();
 assertThat(sentRequest.getUrl().toString())
   .matches("http://host(1|2)/singularity/v2/api/requests/request/requestId/pause");
}

代码示例来源:origin: grandcentrix/ThirtyInch

@Test
public void testLogLists() throws Exception {
  final TiLog.Logger logger = mock(TiLog.Logger.class);
  final LoggingInterceptor loggingInterceptor = new LoggingInterceptor(logger);
  final TestView view = loggingInterceptor.intercept(new TestViewImpl());
  final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
  final List list = Arrays.asList("Buenos Aires", "Córdoba", "La Plata");
  view.twoArgs(list, "B");
  verify(logger).log(anyInt(), anyString(), msgCaptor.capture());
  assertThat(msgCaptor.getValue())
      .matches("twoArgs\\("
          + "\\{ArrayList\\[3\\]@[\\da-f]{1,8}\\} \\[Buenos Aires, Córdoba, La Plata\\], "
          + "B"
          + "\\)");
}

代码示例来源:origin: moelholm/smallexamples

@Test
public void sayHello() {
 // Given
 when(greeterDaoMock.findGreeting()).thenReturn("Hola contigo, %s");
 // When
 String greeting = greeterService.sayHello("Duke");
 // Then
 assertThat(greeting).matches("Hola contigo, Duke");
}

代码示例来源:origin: TNG/junit-dataprovider

@Test
public void testFormatAllHandleObjectCorrectly() {
  // Given:
  final List<Object> arguments = list(new Object());
  // When:
  String result = underTest.formatAll(arguments);
  // Then:
  assertThat(result).matches("java.lang.Object@[0-9a-f]+");
}

相关文章

微信公众号

最新文章

更多