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

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

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

AbstractCharSequenceAssert.isEqualToIgnoringWhitespace介绍

[英]Verifies that the actual CharSequence is equal to the given one, ignoring whitespace differences

Examples :

// assertions will pass 
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game   of   Thrones") 
.isEqualToIgnoringWhitespace("  Game of   Thrones  ") 
.isEqualToIgnoringWhitespace("  Game of Thrones  ") 
.isEqualToIgnoringWhitespace("Gameof      Thrones") 
.isEqualToIgnoringWhitespace("Game of\tThrones") 
.isEqualToIgnoringWhitespace("GameofThrones"); 
// assertion will fail 
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game OF Thrones");

This assertion behavior has changed in 2.8.0 to really ignore all whitespaces, the old behaviour has been kept in the better named #isEqualToNormalizingWhitespace(CharSequence).
[中]验证实际字符序列是否等于给定的字符序列,忽略空格差异
示例:

// assertions will pass 
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game   of   Thrones") 
.isEqualToIgnoringWhitespace("  Game of   Thrones  ") 
.isEqualToIgnoringWhitespace("  Game of Thrones  ") 
.isEqualToIgnoringWhitespace("Gameof      Thrones") 
.isEqualToIgnoringWhitespace("Game of\tThrones") 
.isEqualToIgnoringWhitespace("GameofThrones"); 
// assertion will fail 
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game OF Thrones");

这种断言行为在2.8.0中发生了变化,实际上忽略了所有的空白,旧的行为保留在了更好的名称#IsequalToNormalingWhitespace(CharSequence)中。

代码示例

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

/**
 * Assert the given string equals the given file's content.
 *
 * The white space differences are ignored.
 *
 * @param expectedFilePath the expected file path
 * @param actual the actual string
 * @throws IOException the io exception
 */
public static void assertStringEqualFileContent(final String expectedFilePath,
  final String actual)
  throws IOException {
 final String expected = new String(Files.readAllBytes(Paths.get(expectedFilePath)),
   StandardCharsets.UTF_8);
 assertThat(actual).isEqualToIgnoringWhitespace(expected);
}

代码示例来源:origin: athkalia/Just-Another-Android-App

@Test
@SuppressWarnings("checkstyle:LineLength")
public void test_should_trigger_when_other_than_material_color_used_in_allowed_file() throws Exception {
  String file = "values/colors__allowed_from_palette.xml";
  String expectedOutcome = "values/colors__allowed_from_palette.xml:7: Error: Attempting to use a color reference out of the material colors palette file [NonMaterialColors]\n"
      + "    <color name=\"red_400\">@color/red</color>\n"
      + "    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
      + "1 errors, 0 warnings\n";
  String outcome = lintFiles(file);
  // There's a weird invisible char that makes equalTo fail :/
  assertThat(outcome).isEqualToIgnoringWhitespace(expectedOutcome);
}

代码示例来源:origin: athkalia/Just-Another-Android-App

@Test
public void test_detector_triggering() throws Exception {
  String file = "AndroidLogExistingTestCase.java";
  String expectedOutcome = "AndroidLogExistingTestCase.java:8: Error: Don't use Android Log class methods. [InvalidLogStatement]\n"
      + "        Log.d(\"tag\", \"log message\");\n"
      + "        ~~~~~\n"
      + "1 errors, 0 warnings\n";
  String outcome = lintFiles(file);
  // There's a weird invisible char that makes equalTo fail :/
  assertThat(outcome).isEqualToIgnoringWhitespace(expectedOutcome);
}

代码示例来源:origin: athkalia/Just-Another-Android-App

@Test
@SuppressWarnings("checkstyle:LineLength")
public void test_should_trigger_when_material_palette_color_referenced_directly_in_code() throws Exception {
  String file = "layout/direct_material_palette_color_usage_test_case.xml";
  String expectedOutcome = "layout/direct_material_palette_color_usage_test_case.xml:15: Error: Attempting to use a palette color directly. [DirectMaterialColorUsage]\n"
      + "        android:textColor=\"@color/material_red_400\" />\n"
      + "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
      + "1 errors, 0 warnings\n";
  String outcome = lintFiles(file);
  // There's a weird invisible char that makes equalTo fail :/
  assertThat(outcome).isEqualToIgnoringWhitespace(expectedOutcome);
}

代码示例来源:origin: athkalia/Just-Another-Android-App

@Test
@SuppressWarnings("checkstyle:LineLength")
public void test_should_trigger_when_there_is_a_hardcoded_color() throws Exception {
  String file = "layout/hardcoded_colors_existing_test_case.xml";
  String expectedOutcome = "layout/hardcoded_colors_existing_test_case.xml:15: Error: Don't use harcoded colors, link through colors file [HardcodedColors]\n"
      + "        android:textColor=\"#FFFFFFFF\" />\n"
      + "        ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~\n"
      + "1 errors, 0 warnings\n";
  String outcome = lintFiles(file);
  // There's a weird invisible char that makes equalTo fail :/
  assertThat(outcome).isEqualToIgnoringWhitespace(expectedOutcome);
}

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

@Test
public void remove_saves_error_message_and_stacktrace_when_exception_is_provided() {
 Throwable error = new NullPointerException("Fake NPE to test persistence to DB");
 CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
 Optional<CeTask> peek = underTest.peek(WORKER_UUID_1);
 underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
 Optional<CeActivityDto> activityDto = db.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid());
 assertThat(activityDto).isPresent();
 assertThat(activityDto.get().getErrorMessage()).isEqualTo(error.getMessage());
 assertThat(activityDto.get().getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error));
 assertThat(activityDto.get().getErrorType()).isNull();
}

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

@Test
public void remove_saves_error_when_TypedMessageException_is_provided() {
 Throwable error = new TypedExceptionImpl("aType", "aMessage");
 CeTask task = submit(CeTaskTypes.REPORT, newProjectDto("PROJECT_1"));
 Optional<CeTask> peek = underTest.peek(WORKER_UUID_1);
 underTest.remove(peek.get(), CeActivityDto.Status.FAILED, null, error);
 CeActivityDto activityDto = db.getDbClient().ceActivityDao().selectByUuid(session, task.getUuid()).get();
 assertThat(activityDto.getErrorType()).isEqualTo("aType");
 assertThat(activityDto.getErrorMessage()).isEqualTo("aMessage");
 assertThat(activityDto.getErrorStacktrace()).isEqualToIgnoringWhitespace(stacktraceToString(error));
}

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

@Test
public void testProcessTermination() throws Exception {
 final TriggerInstance triggerInstance = createTriggerInstance();
 this.processor.processTermination(triggerInstance);
 this.sendEmailLatch.await(10L, TimeUnit.SECONDS);
 verify(this.message).setSubject(
   "flow trigger for flow 'flowId', project 'proj' has been cancelled on azkaban");
 assertThat(TestUtils.readResource("/emailTemplate/flowtriggerfailureemail.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

@Test
public void createFailedUpdateMessage() throws Exception {
 final ExecutorManagerException exception = createTestStracktrace();
 assertTrue(this.mailCreator
   .createFailedUpdateMessage(Arrays.asList(this.executableFlow, this.executableFlow),
     this.executor, exception, this.message, this.azkabanName, this.scheme,
     this.clientHostname, this.clientPortNumber));
 assertEquals("Flow status could not be updated from executor1-host on unit-tests",
   this.message.getSubject());
 assertThat(TestUtils.readResource("failedUpdateMessage.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

@Test
public void testSendErrorEmail() throws Exception {
 final Flow flow = this.project.getFlow("jobe");
 flow.addFailureEmails(this.receiveAddrList);
 Assert.assertNotNull(flow);
 final ExecutableFlow exFlow = new ExecutableFlow(this.project, flow);
 final CommonMetrics commonMetrics = new CommonMetrics(new MetricsManager(new MetricRegistry()));
 final Emailer emailer = new Emailer(this.props, commonMetrics, this.messageCreator,
   this.executorLoader);
 emailer.alertOnError(exFlow);
 verify(this.message).addAllToAddress(this.receiveAddrList);
 verify(this.message).setSubject("Flow 'jobe' has failed on azkaban");
 assertThat(TestUtils.readResource("errorEmail2.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

@Test
public void alertOnFailedUpdate() throws Exception {
 final Flow flow = this.project.getFlow("jobe");
 flow.addFailureEmails(this.receiveAddrList);
 Assert.assertNotNull(flow);
 final ExecutableFlow exFlow = new ExecutableFlow(this.project, flow);
 final CommonMetrics commonMetrics = new CommonMetrics(new MetricsManager(new MetricRegistry()));
 final Emailer emailer = new Emailer(this.props, commonMetrics, this.messageCreator,
   this.executorLoader);
 final Executor executor = new Executor(1, "executor1-host", 1234, true);
 final List<ExecutableFlow> executions = Arrays.asList(exFlow, exFlow);
 final ExecutorManagerException exception = DefaultMailCreatorTest.createTestStracktrace();
 emailer.alertOnFailedUpdate(executor, executions, exception);
 verify(this.message).addAllToAddress(this.receiveAddrList);
 verify(this.message)
   .setSubject("Flow status could not be updated from executor1-host on azkaban");
 assertThat(TestUtils.readResource("failedUpdateMessage2.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

private void assertTriggerInstancesEqual(final TriggerInstance actual,
  final TriggerInstance expected, final boolean ignoreFlowTrigger) {
 if (!ignoreFlowTrigger) {
  if (actual.getFlowTrigger() != null && expected.getFlowTrigger() != null) {
   assertThat(actual.getFlowTrigger().toString())
     .isEqualToIgnoringWhitespace(expected.getFlowTrigger().toString());
  } else {
   assertThat(actual.getFlowTrigger()).isNull();
   assertThat(expected.getFlowTrigger()).isNull();
  }
 }
 assertThat(actual).isEqualToIgnoringGivenFields(expected, "depInstances", "flowTrigger");
 assertThat(actual.getDepInstances())
   .usingComparatorForElementFieldsWithType((d1, d2) -> {
    if (d1 == null && d2 == null) {
     return 0;
    } else if (d1 != null && d2 != null && d1.getTime() == d2.getTime()) {
     return 0;
    } else {
     return -1;
    }
   }, Date.class)
   .usingElementComparatorIgnoringFields("triggerInstance", "context")
   .containsExactlyInAnyOrder(expected.getDepInstances()
     .toArray(new DependencyInstance[expected.getDepInstances().size()]));
}

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

@Test
public void createFirstErrorMessage() throws Exception {
 setJobStatus(Status.FAILED);
 this.executableFlow.setStatus(Status.FAILED_FINISHING);
 assertTrue(this.mailCreator.createFirstErrorMessage(
   this.executableFlow, this.message, this.azkabanName, this.scheme, this.clientHostname,
   this.clientPortNumber));
 assertEquals("Flow 'mail-creator-test' has encountered a failure on unit-tests",
   this.message.getSubject());
 assertThat(TestUtils.readResource("firstErrorMessage.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

@Test
public void createSuccessEmail() throws Exception {
 setJobStatus(Status.SUCCEEDED);
 this.executableFlow.setEndTime(END_TIME_MILLIS);
 this.executableFlow.setStatus(Status.SUCCEEDED);
 assertTrue(this.mailCreator.createSuccessEmail(
   this.executableFlow, this.message, this.azkabanName, this.scheme, this.clientHostname,
   this.clientPortNumber));
 assertEquals("Flow 'mail-creator-test' has succeeded on unit-tests", this.message.getSubject());
 assertThat(TestUtils.readResource("successEmail.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

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

@Test
public void testUploadTriggerInstance() {
 final TriggerInstance expectedTriggerInst = this.createTriggerInstance(this.flowTrigger, this
   .flow_id, this.flow_version, this.submitUser, this.project, System.currentTimeMillis());
 this.triggerInstLoader.uploadTriggerInstance(expectedTriggerInst);
 final TriggerInstance actualTriggerInst = this.triggerInstLoader
   .getTriggerInstanceById(expectedTriggerInst.getId());
 assertThat(expectedTriggerInst.getFlowTrigger().toString())
   .isEqualToIgnoringWhitespace(actualTriggerInst.getFlowTrigger().toString());
 assertThat(expectedTriggerInst).isEqualToIgnoringGivenFields(actualTriggerInst,
   "depInstances", "flowTrigger");
 assertThat(expectedTriggerInst.getDepInstances())
   .usingElementComparatorIgnoringFields("triggerInstance", "context")
   .containsAll(actualTriggerInst.getDepInstances())
   .hasSameSizeAs(actualTriggerInst.getDepInstances());
}

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

@Test
public void createErrorEmail() throws Exception {
 setJobStatus(Status.FAILED);
 this.executableFlow.setEndTime(END_TIME_MILLIS);
 this.executableFlow.setStatus(Status.FAILED);
 final List<ExecutableFlow> executableFlows = new ArrayList<>();
 final ExecutableFlow executableFlow1 = new ExecutableFlow(this.project, this.flow);
 executableFlow1.setExecutionId(1);
 executableFlow1.setStartTime(START_TIME_MILLIS);
 executableFlow1.setEndTime(END_TIME_MILLIS);
 executableFlow1.setStatus(Status.FAILED);
 executableFlows.add(executableFlow1);
 final ExecutableFlow executableFlow2 = new ExecutableFlow(this.project, this.flow);
 executableFlow2.setExecutionId(2);
 executableFlow2.setStartTime(START_TIME_MILLIS);
 executableFlow2.setEndTime(END_TIME_MILLIS);
 executableFlow2.setStatus(Status.SUCCEEDED);
 executableFlows.add(executableFlow2);
 assertTrue(this.mailCreator.createErrorEmail(
   this.executableFlow, executableFlows, this.message, this.azkabanName, this.scheme, this
     .clientHostname, this.clientPortNumber));
 assertEquals("Flow 'mail-creator-test' has failed on unit-tests", this.message.getSubject());
 assertThat(TestUtils.readResource("errorEmail.html", this))
   .isEqualToIgnoringWhitespace(this.message.getBody());
}

代码示例来源:origin: org.drools/drools-compiler

@Test
public void testExpandDRL() throws Exception {
  String dsl = "[condition]Something=Something()" + NL + "[then]another=another();";
  String drl = "rule 'foo' " + NL + " when " + NL + " Something " + NL + " then " + NL + " another " + NL + "end";
  
  DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
  String result = parser.getExpandedDRL( drl, new StringReader(dsl));
  Assertions.assertThat("rule 'foo' " + NL + " when " + NL + " Something() " + NL + " then " + NL + " another(); " + NL + "end")
       .isEqualToIgnoringWhitespace(result);
}

代码示例来源:origin: org.drools/drools-compiler

public static void DrlFile(String filename) throws Exception {
  DrlParser parser = new DrlParser(LanguageLevelOption.DRL5);
  final PackageDescr pkgOriginal = parser.parse( new InputStreamReader( DumperTestHelper.class.getResourceAsStream( filename ) ) );
  final DrlDumper dumper = new DrlDumper();
  String result1 = dumper.dump( pkgOriginal );
  final PackageDescr pkgDerivated = parser.parse( new StringReader( result1 ) );
  String result2 = dumper.dump( pkgDerivated );
  System.out.println( result1 );
  Assertions.assertThat(result1).isEqualToIgnoringWhitespace(result2);
}

代码示例来源:origin: org.drools/drools-compiler

@Test
public void testParseRule() throws Exception {
  final XmlPackageReader xmlPackageReader = getXmReader();
  xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseRule.xml" ) ) );
  final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
  String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseRule.drl" ) ) );
  // remove license header as that one is not stored in the XML
  String expectedWithoutHeader = removeLicenseHeader(expected);
  System.out.println(expectedWithoutHeader);
  String actual = new DrlDumper().dump( packageDescr );
  
  Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}

代码示例来源:origin: org.drools/drools-compiler

@Test
public void testParseCollect() throws Exception {
  final XmlPackageReader xmlPackageReader = getXmReader();
  xmlPackageReader.read( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.xml" ) ) );
  final PackageDescr packageDescr = xmlPackageReader.getPackageDescr();
  String expected = StringUtils.readFileAsString( new InputStreamReader( getClass().getResourceAsStream( "test_ParseCollect.drl" ) ) );
  String expectedWithoutHeader = removeLicenseHeader( expected );
  String actual = new DrlDumper().dump( packageDescr );
  
  Assertions.assertThat(expectedWithoutHeader).isEqualToIgnoringWhitespace(actual);
}

相关文章

微信公众号

最新文章

更多