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

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

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

AbstractCharSequenceAssert.containsSubsequence介绍

[英]Verifies that the actual CharSequence contains all the values of the given Iterable in the Iterable iteration order (possibly with other values between them).

Example:

String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}"; 
// this assertion succeeds 
assertThat(book).containsSubsequence(asList("'title'", ":", "'A Game of Thrones'")); 
// these ones succeed even if there are values between the given values 
assertThat(book).containsSubsequence(asList("{", "A Game of Thrones", "George Martin", "}")); 
assertThat(book).containsSubsequence(asList("A", "Game", "of", "George")); 
// but this one fails as "author" must come after "A Game of Thrones" 
assertThat(book).containsSubsequence(asList("{", "author", "A Game of Thrones", "}"));

[中]验证实际CharSequence是否包含给定Iterable迭代顺序中的所有Iterable值(可能在它们之间有其他值)。
例子:

String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}"; 
// this assertion succeeds 
assertThat(book).containsSubsequence(asList("'title'", ":", "'A Game of Thrones'")); 
// these ones succeed even if there are values between the given values 
assertThat(book).containsSubsequence(asList("{", "A Game of Thrones", "George Martin", "}")); 
assertThat(book).containsSubsequence(asList("A", "Game", "of", "George")); 
// but this one fails as "author" must come after "A Game of Thrones" 
assertThat(book).containsSubsequence(asList("{", "author", "A Game of Thrones", "}"));

代码示例

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

private void assertMessage(EmailMessage emailMessage, String expectedProfileDetails) {
 assertThat(emailMessage.getMessage())
  .containsSubsequence(
   "The following built-in profiles have been updated:\n\n",
   expectedProfileDetails,
   "\nThis is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + server.getPublicRootUrl() + "/profiles");
}

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

@Test
public void shouldNotDumpSensitiveGlobalProperties() throws Exception {
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 when(globalServerSettings.properties()).thenReturn(ImmutableMap.of("sonar.login", "my_token", "sonar.password", "azerty", "sonar.cpp.license.secured", "AZERTY"));
 DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
  .setBaseDir(temp.newFolder())
  .setWorkDir(temp.newFolder())
  .setProperty("sonar.projectKey", "foo"));
 when(store.allModules()).thenReturn(singletonList(rootModule));
 when(hierarchy.root()).thenReturn(rootModule);
 publisher.init(writer);
 assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence(
  "sonar.cpp.license.secured=******",
  "sonar.login=******",
  "sonar.password=******");
}

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

@Test
public void shouldShortenModuleProperties() throws Exception {
 File baseDir = temp.newFolder();
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
  .setBaseDir(baseDir)
  .setWorkDir(temp.newFolder())
  .setProperty("sonar.projectKey", "foo")
  .setProperty("sonar.projectBaseDir", baseDir.toString())
  .setProperty("sonar.aVeryLongProp", StringUtils.repeat("abcde", 1000)));
 when(store.allModules()).thenReturn(singletonList(rootModule));
 when(hierarchy.root()).thenReturn(rootModule);
 publisher.init(writer);
 assertThat(writer.getFileStructure().analysisLog()).exists();
 assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence(
  "sonar.aVeryLongProp=" + StringUtils.repeat("abcde", 199) + "ab...",
  "sonar.projectBaseDir=" + baseDir.toString(),
  "sonar.projectKey=foo");
}

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

@Test
public void shouldNotDumpEnvTwice() throws Exception {
 logTester.setLevel(LoggerLevel.DEBUG);
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 Map<String, String> env = new HashMap<>();
 env.put(FOO, "BAR");
 env.put(BIZ, "BAZ");
 when(system2.envVariables()).thenReturn(env);
 DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
  .setBaseDir(temp.newFolder())
  .setWorkDir(temp.newFolder())
  .setProperty("sonar.projectKey", "foo")
  .setProperty("env." + FOO, "BAR"));
 when(store.allModules()).thenReturn(singletonList(rootModule));
 when(hierarchy.root()).thenReturn(rootModule);
 publisher.init(writer);
 String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
 assertThat(content).containsOnlyOnce(FOO);
 assertThat(content).containsOnlyOnce(BIZ);
 assertThat(content).containsSubsequence(BIZ, FOO);
 content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8);
 assertThat(content).containsOnlyOnce(FOO);
 assertThat(content).containsOnlyOnce(BIZ);
 assertThat(content).doesNotContain("env." + FOO);
}

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

@Test
public void search_with_selection() {
 loginAsAdmin(db.getDefaultOrganization());
 String result = newRequest()
  .setParam(PARAM_PERMISSION, SCAN.getKey())
  .execute()
  .getInput();
 assertThat(result).containsSubsequence(DefaultGroups.ANYONE, "group-1", "group-2");
}

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

@Test
public void shouldNotDumpSensitiveModuleProperties() throws Exception {
 ScannerReportWriter writer = new ScannerReportWriter(temp.newFolder());
 DefaultInputModule rootModule = new DefaultInputModule(ProjectDefinition.create()
  .setBaseDir(temp.newFolder())
  .setWorkDir(temp.newFolder())
  .setProperty("sonar.projectKey", "foo")
  .setProperty("sonar.projectKey", "foo")
  .setProperty("sonar.login", "my_token")
  .setProperty("sonar.password", "azerty")
  .setProperty("sonar.cpp.license.secured", "AZERTY"));
 when(store.allModules()).thenReturn(singletonList(rootModule));
 when(hierarchy.root()).thenReturn(rootModule);
 publisher.init(writer);
 assertThat(writer.getFileStructure().analysisLog()).exists();
 assertThat(FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8)).containsSubsequence(
  "sonar.cpp.license.secured=******",
  "sonar.login=******",
  "sonar.password=******",
  "sonar.projectKey=foo");
}

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

@Test
public void notification_contains_profiles_sorted_by_language_then_by_profile_name() {
 String languageKey1 = "langkey1_" + randomAlphanumeric(20);
 String languageName1 = "langName1_" + randomAlphanumeric(20);
 String languageKey2 = "langKey2_" + randomAlphanumeric(20);
 String languageName2 = "langName2_" + randomAlphanumeric(20);
 String profileName1 = "profile1_" + randomAlphanumeric(20);
 String profileName2 = "profile2_" + randomAlphanumeric(20);
 String profileName3 = "profile3_" + randomAlphanumeric(20);
 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
  .addProfile(Profile.newBuilder().setProfileName(profileName3).setLanguageKey(languageKey2).setLanguageName(languageName2).build())
  .addProfile(Profile.newBuilder().setProfileName(profileName2).setLanguageKey(languageKey1).setLanguageName(languageName1).build())
  .addProfile(Profile.newBuilder().setProfileName(profileName1).setLanguageKey(languageKey2).setLanguageName(languageName2).build());
 EmailMessage emailMessage = underTest.format(notification.serialize());
 assertThat(emailMessage.getMessage()).containsSubsequence(
  "\"" + profileName2 + "\" - " + languageName1,
  "\"" + profileName1 + "\" - " + languageName2,
  "\"" + profileName3 + "\" - " + languageName2);
}

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

@Test
public void notification_contains_many_profiles() {
 String profileName1 = "profile1_" + randomAlphanumeric(20);
 String languageKey1 = "langkey1_" + randomAlphanumeric(20);
 String languageName1 = "langName1_" + randomAlphanumeric(20);
 String profileName2 = "profile2_" + randomAlphanumeric(20);
 String languageKey2 = "langkey2_" + randomAlphanumeric(20);
 String languageName2 = "langName2_" + randomAlphanumeric(20);
 BuiltInQualityProfilesNotification notification = new BuiltInQualityProfilesNotification()
  .addProfile(Profile.newBuilder()
   .setProfileName(profileName1)
   .setLanguageKey(languageKey1)
   .setLanguageName(languageName1)
   .setNewRules(2)
   .build())
  .addProfile(Profile.newBuilder()
   .setProfileName(profileName2)
   .setLanguageKey(languageKey2)
   .setLanguageName(languageName2)
   .setNewRules(13)
   .build());
 EmailMessage emailMessage = underTest.format(notification.serialize());
 assertThat(emailMessage.getMessage()).containsSubsequence("The following built-in profiles have been updated:\n",
  profileTitleText(profileName1, languageKey1, languageName1),
  " 2 new rules\n",
  profileTitleText(profileName2, languageKey2, languageName2),
  " 13 new rules\n",
  "This is a good time to review your quality profiles and update them to benefit from the latest evolutions: " + server.getPublicRootUrl() + "/profiles");
}

相关文章

微信公众号

最新文章

更多