Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unexpected UnknownFormatConversionException when doing containsExactly on ListAssert #3288

Closed
BernhardBln opened this issue Dec 7, 2023 · 1 comment
Labels
type: bug A general bug
Milestone

Comments

@BernhardBln
Copy link

Describe the bug
When doing a containsExactly on a ListAssert,

only for the case that all elements are there but the order is wrong (like, containsExactlyInAnyOrder would pass but containsExactly would not),

there will be a UnknownFormatConversionException if a % is part of the data.

  • assertj core version: 3.24.2
  • java version: 17.0.9
  • test framework version: junit 5.10

Test case reproducing the bug

    @Test
    void fails() {

        var actual = List.of("xxx", "%");

        // passes
        assertThat(actual).containsExactlyInAnyOrder("%", "xxx");

        // fails with UnknownFormatConversionException
        assertThat(actual).containsExactly("%", "xxx");

    }

The stacktrace:

java.util.UnknownFormatConversionException: Conversion = '"'

	at java.base/java.util.Formatter.parse(Formatter.java:2750)
	at java.base/java.util.Formatter.format(Formatter.java:2671)
	at java.base/java.util.Formatter.format(Formatter.java:2625)
	at java.base/java.lang.String.format(String.java:4145)
	at org.assertj.core.util.Strings.formatIfArgs(Strings.java:86)
	at org.assertj.core.error.MessageFormatter.format(MessageFormatter.java:62)
	at org.assertj.core.error.BasicErrorMessageFactory.create(BasicErrorMessageFactory.java:107)
	at org.assertj.core.internal.Failures.assertionErrorMessage(Failures.java:144)
	at org.assertj.core.internal.Failures.failure(Failures.java:133)
	at org.assertj.core.internal.Iterables.shouldContainExactlyWithIndexAssertionError(Iterables.java:1169)
	at org.assertj.core.internal.Iterables.assertElementOrder(Iterables.java:1150)
	at org.assertj.core.internal.Iterables.assertContainsExactly(Iterables.java:1137)
	at org.assertj.core.api.AbstractIterableAssert.containsExactlyForProxy(AbstractIterableAssert.java:427)
	at org.assertj.core.api.AbstractIterableAssert.containsExactly(AbstractIterableAssert.java:420)
@joel-costigliola
Copy link
Member

Thanks for reporting this @BernhardBln !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants