热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

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

本文整理了Java中org.assertj.core.api.AbstractCharSequenceAssert.hasSize()方法的一些代码示例,展示了

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

AbstractCharSequenceAssert.hasSize介绍

[英]Verifies that the actual CharSequence has the expected length using the length() method.

This assertion will succeed:

String bookName = "A Game of Thrones"
assertThat(bookName).hasSize(17);

Whereas this assertion will fail:

String bookName = "A Clash of Kings"
assertThat(bookName).hasSize(4);

[中]使用length()方法验证实际CharSequence是否具有预期的长度。
此断言将成功:

String bookName = "A Game of Thrones"
assertThat(bookName).hasSize(17);

而此断言将失败:

String bookName = "A Clash of Kings"
assertThat(bookName).hasSize(4);

代码示例

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

@Test
public void create_error_msg_from_long_content() {
String cOntent= StringUtils.repeat("mystring", 1000);
assertThat(ScannerWsClient.createErrorMessage(new HttpException("url", 400, content))).hasSize(15 + 128);
}

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

@Test
public void shouldFormatDate() {
assertThat(DateUtils.formatDate(new Date())).startsWith("20");
assertThat(DateUtils.formatDate(new Date())).hasSize(10);
}

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

@Test
public void hash_token() {
String hash = underTest.hash("1234567890123456789012345678901234567890");
assertThat(hash)
.hasSize(96)
.isEqualTo("b2501fc3833ae6feba7dc8a973a22d709b7c796ee97cbf66db2c22df873a9fa147b1b630878f771457b7769efd9ffa0d")
.matches("[0-9a-f]+");
}
}

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

@Test
public void test_content() throws IOException {
Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
Files.createDirectories(testFile.getParent());
String cOntent= "test é string";
Files.write(testFile, content.getBytes(StandardCharsets.ISO_8859_1));
assertThat(Files.readAllLines(testFile, StandardCharsets.ISO_8859_1).get(0)).hasSize(content.length());
Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
.setStatus(InputFile.Status.ADDED)
.setCharset(StandardCharsets.ISO_8859_1);
assertThat(inputFile.contents()).isEqualTo(content);
try (InputStream inputStream = inputFile.inputStream()) {
String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
assertThat(result).isEqualTo(content);
}
}

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

@Test
public void test_content_exclude_bom() throws IOException {
Path testFile = baseDir.resolve(PROJECT_RELATIVE_PATH);
Files.createDirectories(testFile.getParent());
try (BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(testFile.toFile()), StandardCharsets.UTF_8))) {
out.write('\ufeff');
}
String cOntent= "test é string €";
Files.write(testFile, content.getBytes(StandardCharsets.UTF_8), StandardOpenOption.APPEND);
assertThat(Files.readAllLines(testFile, StandardCharsets.UTF_8).get(0)).hasSize(content.length() + 1);
Metadata metadata = new Metadata(42, 30, "", new int[0], new int[0], 10);
DefaultInputFile inputFile = new DefaultInputFile(indexedFile, f -> f.setMetadata(metadata))
.setStatus(InputFile.Status.ADDED)
.setCharset(StandardCharsets.UTF_8);
assertThat(inputFile.contents()).isEqualTo(content);
try (InputStream inputStream = inputFile.inputStream()) {
String result = new BufferedReader(new InputStreamReader(inputStream, inputFile.charset())).lines().collect(Collectors.joining());
assertThat(result).isEqualTo(content);
}
}

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

@Test
public void reformatParam_truncates_if_too_long() {
String param = repeat("a", SqlLogFormatter.PARAM_MAX_WIDTH + 10);
String formattedParam = SqlLogFormatter.reformatParam(param);
assertThat(formattedParam)
.hasSize(SqlLogFormatter.PARAM_MAX_WIDTH)
.endsWith("...")
.startsWith(repeat("a", SqlLogFormatter.PARAM_MAX_WIDTH - 3));
}

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

@Test
public void prevent_too_long_messages() {
assertThat(new DefaultIssueLocation()
.on(inputFile)
.message(StringUtils.repeat("a", 4000)).message()).hasSize(4000);
assertThat(new DefaultIssueLocation()
.on(inputFile)
.message(StringUtils.repeat("a", 4001)).message()).hasSize(4000);
}

代码示例来源:origin: springside/springside4

@Test
public void generateString() {
System.out.println(RandomUtil.randomStringFixLength(5));
System.out.println(RandomUtil.randomStringRandomLength(5, 10));
System.out.println(RandomUtil.randomStringFixLength(RandomUtil.threadLocalRandom(), 5));
System.out.println(RandomUtil.randomStringRandomLength(RandomUtil.threadLocalRandom(), 5, 10));
assertThat(RandomUtil.randomStringFixLength(5)).hasSize(5);
assertThat(RandomUtil.randomStringFixLength(RandomUtil.threadLocalRandom(), 5)).hasSize(5);
System.out.println(RandomUtil.randomLetterFixLength(5));
System.out.println(RandomUtil.randomLetterRandomLength(5, 10));
System.out.println(RandomUtil.randomLetterFixLength(RandomUtil.threadLocalRandom(), 5));
System.out.println(RandomUtil.randomLetterRandomLength(RandomUtil.threadLocalRandom(), 5, 10));
assertThat(RandomUtil.randomLetterFixLength(5)).hasSize(5);
assertThat(RandomUtil.randomLetterFixLength(RandomUtil.threadLocalRandom(), 5)).hasSize(5);
System.out.println(RandomUtil.randomAsciiFixLength(5));
System.out.println(RandomUtil.randomAsciiRandomLength(5, 10));
System.out.println(RandomUtil.randomAsciiFixLength(RandomUtil.threadLocalRandom(), 5));
System.out.println(RandomUtil.randomAsciiRandomLength(RandomUtil.threadLocalRandom(), 5, 10));
assertThat(RandomUtil.randomAsciiFixLength(5)).hasSize(5);
assertThat(RandomUtil.randomAsciiFixLength(RandomUtil.threadLocalRandom(), 5)).hasSize(5);
}

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

@Test
public void generate_different_tokens() {
// this test is not enough to ensure that generated strings are unique,
// but it still does a simple and stupid verification
String firstToken = underTest.generate();
String secOndToken= underTest.generate();
assertThat(firstToken)
.isNotEqualTo(secondToken)
.hasSize(40);
}

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

@Test
public void processSpanBuilderImpl_testNoExplicitLengthLimit() throws Exception {
String value = "";
for (int i = 0; i <255; i++) {
value += "0";
}
addServletParameter("m_tagWithoutExplicitLengthLimit", value);
addMetadataDefinition("tagWithoutExplicitLengthLimit", "string");
processSpanBuilderImpl(spanBuilder, servletParameters);
assertThat(tracer.finishedSpans()).hasSize(1);
MockSpan mockSpan = tracer.finishedSpans().get(0);
assertThat(mockSpan.tags()).hasSize(1);
assertThat(mockSpan.tags().get("tagWithoutExplicitLengthLimit").toString()).hasSize(MAX_LENGTH);
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void computeShouldReturnStringWithoutTruncation() throws Exception {
String body = StringUtils.leftPad("a", 100, "b");
assertThat(testee.compute(Optional.of(body)))
.hasSize(100)
.isEqualTo(body);
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void slugifyRespectsAllowedLength() {
final int allowedLength = 256;
final String tooLOngString= StringUtils.repeat("a", allowedLength - 1) + "bc";
assertThat(tooLongString).hasSize(allowedLength + 1);
final String actual = LocalizedString.ofEnglish(tooLongString).slugified().get(Locale.ENGLISH);
assertThat(actual).hasSize(allowedLength).endsWith("ab");
}

代码示例来源:origin: commercetools/commercetools-jvm-sdk

@Test
public void slugifyUniqueRespectsAllowedLength() {
final int allowedLength = 256;
final String tooLOngString= StringUtils.repeat("a", allowedLength + 1);
assertThat(tooLongString).hasSize(allowedLength + 1);
final String actual = LocalizedString.ofEnglish(tooLongString).slugifiedUnique().get(Locale.ENGLISH);
assertThat(actual).hasSize(allowedLength).matches("a{247}-\\d{8}");
}

代码示例来源:origin: zanata/zanata-platform

@Test
public void canChangeToDeletedSlugWithSuffixInPlaceIfOldSlugIsTooLong() {
// 36 characters long
SlugEntityBase slugEntityBase =
new SlugClass("abcdefghijklmnopqrstuvwxyz1234567890");
String newSlug = slugEntityBase.changeToDeletedSlug();
assertThat(newSlug)
.isEqualTo("abcdefghijklmnopqrstuvwxyz1" + DELETED_SUFFIX)
.hasSize(40);
}
}

代码示例来源:origin: org.apache.james/james-server-jmap

@Test
public void computeShouldReturnStringIsLimitedTo256Length() throws Exception {
String body = StringUtils.leftPad("a", 300, "b");
String expected = StringUtils.leftPad("b", MessagePreviewGenerator.MAX_PREVIEW_LENGTH, "b");
assertThat(testee.compute(Optional.of(body)))
.hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)
.isEqualTo(expected);
}

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

@Test
public void itTruncatesText() throws Exception {
assertThat(filter.filter(StringUtils.rightPad("", 256, 'x') + "y", interpreter, "255", "True").toString()).hasSize(258).endsWith("x...");
}

代码示例来源:origin: xing/xing-android-sdk

private static void assertRequestHasBody(Request request, TestMsg expected, int contentLength) throws IOException {
RequestBody body = request.body();
assertThat(body.contentLength()).isEqualTo(contentLength);
assertThat(body.contentType().subtype()).isEqualTo("json");
Buffer buffer = new Buffer();
body.writeTo(buffer);
assertThat(buffer.readUtf8())
.contains("\"msg\":\"" + expected.msg + '"')
.contains("\"code\":" + expected.code)
.startsWith("{")
.endsWith("}")
.hasSize(contentLength);
}

代码示例来源:origin: com.hubspot.jinjava/jinjava

@Test
public void itTruncatesText() throws Exception {
assertThat(filter.filter(StringUtils.rightPad("", 256, 'x') + "y", interpreter, "255", "True").toString()).hasSize(258).endsWith("x...");
}

代码示例来源:origin: org.apache.james/james-server-jmap-integration-testing

@Then("^the preview should not contain consecutive spaces or blank characters$")
public void assertPreviewShouldBeNormalized() {
String actual = httpClient.jsonPath.read(FIRST_MESSAGE + ".preview");
assertThat(actual).hasSize(MessagePreviewGenerator.MAX_PREVIEW_LENGTH)
.doesNotMatch(" ")
.doesNotContain(StringUtils.CR)
.doesNotContain(StringUtils.LF);
}

代码示例来源:origin: tomasbjerre/git-changelog-lib

@Test
public void testThatTagsThatAreEmptyAfterCommitsHaveBeenIgnoredAreRemoved() throws Exception {
final String templatePath = "templatetest/testAuthorsCommitsExtended.mustache";
assertThat(
gitChangelogApiBuilder() //
.withFromCommit(ZERO_COMMIT) //
.withToRef("test") //
.withTemplatePath(templatePath) //
.withIgnoreCommitsWithMessage(".*") //
.render() //
.trim())
.hasSize(74);
}

推荐阅读
  • Explore a common issue encountered when implementing an OAuth 1.0a API, specifically the inability to encode null objects and how to resolve it. ... [详细]
  • PHP 5.2.5 安装与配置指南
    本文详细介绍了 PHP 5.2.5 的安装和配置步骤,帮助开发者解决常见的环境配置问题,特别是上传图片时遇到的错误。通过本教程,您可以顺利搭建并优化 PHP 运行环境。 ... [详细]
  • 本文详细介绍了Java中org.eclipse.ui.forms.widgets.ExpandableComposite类的addExpansionListener()方法,并提供了多个实际代码示例,帮助开发者更好地理解和使用该方法。这些示例来源于多个知名开源项目,具有很高的参考价值。 ... [详细]
  • 使用 Azure Service Principal 和 Microsoft Graph API 获取 AAD 用户列表
    本文介绍了一段通用代码示例,该代码不仅能够操作 Azure Active Directory (AAD),还可以通过 Azure Service Principal 的授权访问和管理 Azure 订阅资源。Azure 的架构可以分为两个层级:AAD 和 Subscription。 ... [详细]
  • 本文详细介绍了Java编程语言中的核心概念和常见面试问题,包括集合类、数据结构、线程处理、Java虚拟机(JVM)、HTTP协议以及Git操作等方面的内容。通过深入分析每个主题,帮助读者更好地理解Java的关键特性和最佳实践。 ... [详细]
  • 如何在窗口右下角添加调整大小的手柄
    本文探讨了如何在传统MFC/Win32 API编程中实现类似C# WinForms中的SizeGrip功能,即在窗口的右下角显示一个用于调整窗口大小的手柄。我们将介绍具体的实现方法和相关API。 ... [详细]
  • 本文深入探讨了Linux系统中网卡绑定(bonding)的七种工作模式。网卡绑定技术通过将多个物理网卡组合成一个逻辑网卡,实现网络冗余、带宽聚合和负载均衡,在生产环境中广泛应用。文章详细介绍了每种模式的特点、适用场景及配置方法。 ... [详细]
  • RecyclerView初步学习(一)
    RecyclerView初步学习(一)ReCyclerView提供了一种插件式的编程模式,除了提供ViewHolder缓存模式,还可以自定义动画,分割符,布局样式,相比于传统的ListVi ... [详细]
  • 本文详细介绍了Java中org.neo4j.helpers.collection.Iterators.single()方法的功能、使用场景及代码示例,帮助开发者更好地理解和应用该方法。 ... [详细]
  • 本文详细记录了在基于Debian的Deepin 20操作系统上安装MySQL 5.7的具体步骤,包括软件包的选择、依赖项的处理及远程访问权限的配置。 ... [详细]
  • 优化ListView性能
    本文深入探讨了如何通过多种技术手段优化ListView的性能,包括视图复用、ViewHolder模式、分批加载数据、图片优化及内存管理等。这些方法能够显著提升应用的响应速度和用户体验。 ... [详细]
  • 本文详细介绍了 GWT 中 PopupPanel 类的 onKeyDownPreview 方法,提供了多个代码示例及应用场景,帮助开发者更好地理解和使用该方法。 ... [详细]
  • 资源推荐 | TensorFlow官方中文教程助力英语非母语者学习
    来源:机器之心。本文详细介绍了TensorFlow官方提供的中文版教程和指南,帮助开发者更好地理解和应用这一强大的开源机器学习平台。 ... [详细]
  • 扫描线三巨头 hdu1928hdu 1255  hdu 1542 [POJ 1151]
    学习链接:http:blog.csdn.netlwt36articledetails48908031学习扫描线主要学习的是一种扫描的思想,后期可以求解很 ... [详细]
  • This document outlines the recommended naming conventions for HTML attributes in Fast Components, focusing on readability and consistency with existing standards. ... [详细]
author-avatar
youth冰点
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有