本文整理了Java中org.assertj.core.api.AbstractCharSequenceAssert.is()
方法的一些代码示例,展示了AbstractCharSequenceAssert.is()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。AbstractCharSequenceAssert.is()
方法的具体详情如下:
包路径:org.assertj.core.api.AbstractCharSequenceAssert
类名称:AbstractCharSequenceAssert
方法名:is
[英]Verifies that the actual CharSequence is blank, i.e. is null, empty or consists of one or more whitespace characters (according to Character#isWhitespace(char)).
The definition of this method has changed, the old behaviour is now under #containsOnlyWhitespaces().
These assertions succeed:
assertThat(" ").isBlank();
assertThat("").isBlank();
assertThat(" ").isBlank();
String nullString = null;
assertThat(nullString).isBlank();
Whereas these assertions fail:
assertThat("a").isBlank();
assertThat(" b").isBlank();
assertThat(" c ").isBlank();
[中]验证实际字符序列是否为空,即为null、空或由一个或多个空白字符组成(根据字符#isWhitespace(char))。
此方法的定义已更改,旧行为现在位于#containsOnlyWhitespaces()下。
这些断言成功了:
assertThat(" ").isBlank();
assertThat("").isBlank();
assertThat(" ").isBlank();
String nullString = null;
assertThat(nullString).isBlank();
而这些断言失败:
assertThat("a").isBlank();
assertThat(" b").isBlank();
assertThat(" c ").isBlank();
代码示例来源:origin: facebook/litho
@Test
public void testMatcher() {
final HamcrestCondition<Object> aString =
new HamcrestCondition<>(IsInstanceOf.instanceOf(String.class));
assertThat("abc").is(aString);
assertThat(123).isNot(aString);
}
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void getRequestWithQueryString() throws IOException {
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo?param=value").build());
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
.withContent("$ curl 'http://localhost/foo?param=value' -i -X GET"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void responseWithNoBody() throws IOException {
new ResponseBodySnippet().document(this.operationBuilder.response().build());
assertThat(this.generatedSnippets.snippet("response-body"))
.is(codeBlock(null, "nowrap").withContent(""));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void multipartPostWithNoSubmittedFileName() throws IOException {
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/upload").method("POST")
.header(HttpHeaders.CONTENT_TYPE, MediaType.MULTIPART_FORM_DATA_VALUE)
.part("metadata", "{\"description\": \"foo\"}".getBytes()).build());
String expectedContent = "$ curl 'http://localhost/upload' -i -X POST -H "
+ "'Content-Type: multipart/form-data' -F "
+ "'metadata={\"description\": \"foo\"}'";
assertThat(this.generatedSnippets.curlRequest())
.is(codeBlock("bash").withContent(expectedContent));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void arrayResponseWithAlwaysNullField() throws IOException {
new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("[]a.b").description("one")))
.document(this.operationBuilder.response().content(
"[{\"a\": {\"b\": null}}," + "{\"a\": {\"b\": null}}]")
.build());
assertThat(this.generatedSnippets.responseFields())
.is(tableWithHeader("Path", "Type", "Description").row("`[]a.b`",
"`Null`", "one"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void presentOptionalRequestParameter() throws IOException {
new RequestParametersSnippet(
Arrays.asList(parameterWithName("a").description("one").optional()))
.document(this.operationBuilder.request("http://localhost")
.param("a", "one").build());
assertThat(this.generatedSnippets.requestParameters())
.is(tableWithHeader("Parameter", "Description").row("`a`", "one"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void missingIgnoredOptionalRequestFieldDoesNotRequireAType()
throws IOException {
new RequestFieldsSnippet(Arrays
.asList(fieldWithPath("a.b").description("one").ignored().optional()))
.document(this.operationBuilder.request("http://localhost")
.content("{}").build());
assertThat(this.generatedSnippets.requestFields())
.is(tableWithHeader("Path", "Type", "Description"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void putRequestWithOneParameter() throws IOException {
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").method("PUT").param("k1", "v1").build());
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
.withContent("$ curl 'http://localhost/foo' -i -X PUT -d 'k1=v1'"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void presentOptionalResponseField() throws IOException {
new ResponseFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional()))
.document(this.operationBuilder.response()
.content("{\"a\": { \"b\": \"bravo\"}}").build());
assertThat(this.generatedSnippets.responseFields())
.is(tableWithHeader("Path", "Type", "Description").row("`a.b`",
"`String`", "one"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void undocumentedAttributeDoesNotCauseFailure() throws IOException {
new ResponseFieldsSnippet(
Arrays.asList(fieldWithPath("a").description("one").type("a"))).document(
this.operationBuilder.response().content("<a id=\"foo\">bar</a>")
.header(HttpHeaders.CONTENT_TYPE,
MediaType.APPLICATION_XML_VALUE)
.build());
assertThat(this.generatedSnippets.responseFields()).is(
tableWithHeader("Path", "Type", "Description").row("`a`", "`a`", "one"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void ignoredRequestField() throws IOException {
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a").ignored(),
fieldWithPath("b").description("Field b")))
.document(this.operationBuilder.request("http://localhost")
.content("{\"a\": 5, \"b\": 4}").build());
assertThat(this.generatedSnippets.requestFields())
.is(tableWithHeader("Path", "Type", "Description").row("`b`", "`Number`",
"Field b"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void presentOptionalRequestField() throws IOException {
new RequestFieldsSnippet(Arrays.asList(fieldWithPath("a.b").description("one")
.type(JsonFieldType.STRING).optional()))
.document(this.operationBuilder.request("http://localhost")
.content("{\"a\": { \"b\": \"bravo\"}}").build());
assertThat(this.generatedSnippets.requestFields())
.is(tableWithHeader("Path", "Type", "Description").row("`a.b`",
"`String`", "one"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void pathParametersWithQueryString() throws IOException {
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two"))).document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}?foo=bar")
.build());
assertThat(this.generatedSnippets.pathParameters())
.is(tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void ignoredRequestParameter() throws IOException {
new RequestParametersSnippet(Arrays.asList(parameterWithName("a").ignored(),
parameterWithName("b").description("two")))
.document(this.operationBuilder.request("http://localhost")
.param("a", "bravo").param("b", "bravo").build());
assertThat(this.generatedSnippets.requestParameters())
.is(tableWithHeader("Parameter", "Description").row("`b`", "two"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void postRequestWithMultipleParameters() throws IOException {
new CurlRequestSnippet(this.commandFormatter).document(
this.operationBuilder.request("http://localhost/foo").method("POST")
.param("k1", "v1", "v1-bis").param("k2", "v2").build());
assertThat(this.generatedSnippets.curlRequest()).is(
codeBlock("bash").withContent("$ curl 'http://localhost/foo' -i -X POST"
+ " -d 'k1=v1&k1=v1-bis&k2=v2'"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void missingOptionalPathParameter() throws IOException {
new PathParametersSnippet(Arrays.asList(parameterWithName("a").description("one"),
parameterWithName("b").description("two").optional()))
.document(this.operationBuilder.attribute(
RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}").build());
assertThat(this.generatedSnippets.pathParameters())
.is(tableWithTitleAndHeader(getTitle("/{a}"), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void postWithContentAndParameters() throws IOException {
new CurlRequestSnippet(this.commandFormatter).document(this.operationBuilder
.request("http://localhost/foo").param("a", "alpha").method("POST")
.param("b", "bravo").content("Some content").build());
assertThat(this.generatedSnippets.curlRequest()).is(codeBlock("bash")
.withContent("$ curl 'http://localhost/foo?a=alpha&b=bravo' -i "
+ "-X POST -d 'Some content'"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void subsectionOfMapResponseWithCommonsPrefix() throws IOException {
responseFields(beneathPath("a"))
.andWithPrefix("b.", fieldWithPath("c").description("two"))
.document(this.operationBuilder.response()
.content("{\"a\": {\"b\": {\"c\": \"charlie\"}}}").build());
assertThat(this.generatedSnippets.snippet("response-fields-beneath-a"))
.is(tableWithHeader("Path", "Type", "Description").row("`b.c`",
"`String`", "two"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void subsectionOfMapRequestWithCommonPrefix() throws IOException {
requestFields(beneathPath("a"))
.andWithPrefix("b.", fieldWithPath("c").description("two"))
.document(this.operationBuilder.request("http://localhost")
.content("{\"a\": {\"b\": {\"c\": \"charlie\"}}}").build());
assertThat(this.generatedSnippets.snippet("request-fields-beneath-a"))
.is(tableWithHeader("Path", "Type", "Description").row("`b.c`",
"`String`", "two"));
}
代码示例来源:origin: spring-projects/spring-restdocs
@Test
public void additionalDescriptors() throws IOException {
RequestDocumentation.pathParameters(parameterWithName("a").description("one"))
.and(parameterWithName("b").description("two"))
.document(this.operationBuilder
.attribute(RestDocumentationGenerator.ATTRIBUTE_NAME_URL_TEMPLATE,
"/{a}/{b}")
.build());
assertThat(this.generatedSnippets.pathParameters())
.is(tableWithTitleAndHeader(getTitle(), "Parameter", "Description")
.row("`a`", "one").row("`b`", "two"));
}
内容来源于网络,如有侵权,请联系作者删除!