Skip to content

Unquoted string produced by BasicErrorMessageFactory is quoted by StandardRepresentation in 3.27.x #3733

@wilkinsona

Description

@wilkinsona

Describe the bug

#3617 has introduced a regression in StandardRepresentation when handling an UnquotedString. UnquotedString implements CharSequence so it's now handled as such. This results in it being wrapped in quotes.

  • assertj core version: 3.27.x
  • java version: Any
  • test framework version: N/A
  • os (if relevant): N/A

Test case reproducing the bug

@Test
void hasNotFailedWhenFailedShouldFail() {
	assertThat(new TestErrorMessageFactory().create()).isEqualTo("alpha \"bravo\"");
}

static class TestErrorMessageFactory extends BasicErrorMessageFactory {

	public TestErrorMessageFactory() {
		super("%s %s", unquotedString("alpha"), "bravo");
	}

}

A possible workaround is to implement a custom QuotedString class that doesn't implement CharSequence so that StandardRepresentation then falls back to calling toString():

static class TestErrorMessageFactory extends BasicErrorMessageFactory {

public TestErrorMessageFactory() {
	super("%s %s", new UnquotedString("alpha"), "bravo");
}

private static class UnquotedString {

	private final String string;

	private UnquotedString(String string) {
		this.string = string;
	}

	@Override
	public String toString() {
		return this.string;
	}

}

Is this a reasonable approach? I'm wondering if the loss of the various CharSequence methods or the lack of hashCode and equals may cause problems.

Metadata

Metadata

Labels

No labels
No labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions