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

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

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

AbstractCharSequenceAssert.isEmpty介绍

[英]Verifies that the actual CharSequence is empty, i.e., it has a length of 0 and is not null.

If you want to accept a null value as well as a 0 length, use org.assertj.core.api.AbstractCharSequenceAssert#isNullOrEmpty() instead.

This assertion will succeed:

String emptyString = "" 
assertThat(emptyString).isEmpty();

Whereas these assertions will fail:

String nullString = null; 
assertThat(nullString).isEmpty(); 
assertThat("a").isEmpty(); 
assertThat("   ").isEmpty();

[中]验证实际CharSequence是否为空,即其长度为0且不为null。
如果希望接受空值和0长度,请使用org。资产j。果心应用程序编程接口。AbstractCharSequenceAssert#改为isNullOrEmpty()。
此断言将成功:

String emptyString = "" 
assertThat(emptyString).isEmpty();

而这些断言将失败:

String nullString = null; 
assertThat(nullString).isEmpty(); 
assertThat("a").isEmpty(); 
assertThat("   ").isEmpty();

代码示例

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

@Test
public void write_content_when_closing_resource() throws IOException {
 underTest.write("content");
 assertThat(writer.toString()).isEmpty();
 underTest.close();
 assertThat(writer.toString()).isEqualTo("content");
}

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

@Test
public void load_source_hash_sequences() {
 when(sourceLinesHash.getLineHashesMatchingDBVersion(FILE)).thenReturn(Collections.singletonList("line"));
 Input<DefaultIssue> input = underTest.create(FILE);
 assertThat(input.getLineHashSequence()).isNotNull();
 assertThat(input.getLineHashSequence().getHashForLine(1)).isEqualTo("line");
 assertThat(input.getLineHashSequence().getHashForLine(2)).isEmpty();
 assertThat(input.getLineHashSequence().getHashForLine(3)).isEmpty();
 assertThat(input.getBlockHashSequence()).isNotNull();
}

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

@Test
public void format_date_time_null_safe() {
 assertThat(DateUtils.formatDateTimeNullSafe(new Date())).startsWith("20");
 assertThat(DateUtils.formatDateTimeNullSafe(new Date()).length()).isGreaterThan(20);
 assertThat(DateUtils.formatDateTimeNullSafe(null)).isEmpty();
}

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

@Test
public void aggregate_empty_distribution() {
 RangeDistributionBuilder builder = new RangeDistributionBuilder();
 String distribution = builder.build();
 assertThat(distribution).isEmpty();
}

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

@Test
public void return_empty_string_when_offset_is_empty() {
 assertThat(underTest.offsetToString(createTextRange(LINE_1, LINE_1, OFFSET_0, OFFSET_0),
  LINE_1, DEFAULT_LINE_LENGTH))
   .isEmpty();
}

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

@Test
public void param_as_input_stream() throws Exception {
 assertThat(underTest.paramAsInputStream("a_string")).isNull();
 assertThat(IOUtils.toString(underTest.setParam("a_string", "").paramAsInputStream("a_string"))).isEmpty();
 assertThat(IOUtils.toString(underTest.setParam("a_string", "foo").paramAsInputStream("a_string"))).isEqualTo("foo");
}

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

@Test
public void triggers_cancel_for_downloads_and_uninstalls() throws Exception {
 userSessionRule.logIn().setSystemAdministrator();
 underTest.handle(request, response);
 verify(pluginDownloader, times(1)).cancelDownloads();
 verify(pluginUninstaller, times(1)).cancelUninstalls();
 assertThat(response.outputAsString()).isEmpty();
}

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

@Test
public void if_plugin_is_installed_uninstallation_is_triggered() throws Exception {
 logInAsSystemAdministrator();
 when(serverPluginRepository.getPluginInfo(PLUGIN_KEY)).thenReturn(new PluginInfo(PLUGIN_KEY));
 underTest.handle(validRequest, response);
 verify(pluginUninstaller).uninstall(PLUGIN_KEY);
 assertThat(response.outputAsString()).isEmpty();
}

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

@Test
public void no_content_http_204_returned() {
 TestResponse result = call(organization.getKey(), user.getLogin());
 assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT);
 assertThat(result.getInput()).isEmpty();
}

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

@Test
public void read_nothing() {
 SymbolsLineReader symbolsLineReader = newReader();
 assertThat(symbolsLineReader.read(line1)).isEmpty();
 assertThat(line1.getSymbols()).isEmpty();
}

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

@Test
public void empty_204_response() {
 logInAsSystemAdministrator();
 TestResponse result = ws.newRequest()
  .setParam("keys", "my.key")
  .execute();
 assertThat(result.getStatus()).isEqualTo(HTTP_NO_CONTENT);
 assertThat(result.getInput()).isEmpty();
}

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

@Test
public void empty_204_response() {
 TestResponse result = ws.newRequest()
  .setParam("key", "my.key")
  .setParam("value", "my value")
  .execute();
 assertThat(result.getStatus()).isEqualTo(HttpURLConnection.HTTP_NO_CONTENT);
 assertThat(result.getInput()).isEmpty();
}

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

@Test
public void set_accepts_empty_value_and_trims_it() {
 MapSettings underTest = new MapSettings();
 Random random = new Random();
 String key = randomAlphanumeric(3);
 underTest.set(key, blank(random));
 assertThat(underTest.getString(key)).isEmpty();
}

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

@Test
public void if_plugin_has_an_update_download_is_triggered_with_latest_version_from_updatecenter() throws Exception {
 logInAsSystemAdministrator();
 Version version = Version.create("1.0");
 when(updateCenter.findPluginUpdates()).thenReturn(ImmutableList.of(
  PluginUpdate.createWithStatus(new Release(Plugin.factory(PLUGIN_KEY), version), Status.COMPATIBLE)));
 underTest.handle(validRequest, response);
 verify(pluginDownloader).download(PLUGIN_KEY, version);
 assertThat(response.outputAsString()).isEmpty();
}

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

@Test
public void read_symbols() {
 SymbolsLineReader symbolsLineReader = newReader(newSymbol(
  newSingleLineTextRangeWithExpectedLabel(LINE_1, OFFSET_2, OFFSET_4, RANGE_LABEL_1),
  newSingleLineTextRangeWithExpectedLabel(LINE_3, OFFSET_1, OFFSET_3, RANGE_LABEL_2)));
 assertThat(symbolsLineReader.read(line1)).isEmpty();
 assertThat(symbolsLineReader.read(line2)).isEmpty();
 assertThat(symbolsLineReader.read(line3)).isEmpty();
 assertThat(line1.getSymbols()).isEqualTo(RANGE_LABEL_1 + ",1");
 assertThat(line2.getSymbols()).isEmpty();
 assertThat(line3.getSymbols()).isEqualTo(RANGE_LABEL_2 + ",1");
}

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

@Test
public void no_response() {
 ComponentDto project = db.components().insertPrivateProject();
 ProjectLinkDto link = db.componentLinks().insertCustomLink(project);
 logInAsProjectAdministrator(project);
 TestResponse response = deleteLink(link);
 assertThat(response.getStatus()).isEqualTo(204);
 assertThat(response.getInput()).isEmpty();
}

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

@Test
public void user_can_delete_its_own_tokens() {
 UserDto user = db.users().insertUser();
 UserTokenDto token = db.users().insertToken(user);
 userSession.logIn(user);
 String response = newRequest(null, token.getName());
 assertThat(response).isEmpty();
 assertThat(dbClient.userTokenDao().selectByUser(dbSession, user)).isEmpty();
}

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

private void checkWithIfNoneMatchHeader(ComponentDto application, MetricDto metric, TestResponse response) {
 TestResponse newResponse = ws.newRequest()
  .setHeader("If-None-Match", response.getHeader("ETag"))
  .setParam("project", application.getKey())
  .setParam("metric", metric.getKey())
  .execute();
 assertThat(newResponse.getInput()).isEmpty();
 assertThat(newResponse.getStatus()).isEqualTo(304);
}
private MetricDto createQualityGateMetric() {

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

@Test
public void test_response_with_no_content() {
 Request request = new TestRequest().setPath("api/foo");
 RequestHandler handler = (req, resp) -> resp.noContent();
 DumbResponse response = run(request, newWs("api/foo", a -> a.setHandler(handler)));
 assertThat(response.stream().outputAsString()).isEmpty();
 assertThat(response.stream().status()).isEqualTo(204);
}

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

@Test
public void test_categories() {
 PropertyDefinitions def = new PropertyDefinitions(
  PropertyDefinition.builder("inCateg").name("In Categ").category("categ").build(),
  PropertyDefinition.builder("noCateg").name("No categ").build());
 assertThat(def.getCategory("inCateg")).isEqualTo("categ");
 assertThat(def.getCategory("noCateg")).isEmpty();
}

相关文章

微信公众号

最新文章

更多