square / assertj-android

A set of AssertJ helpers geared toward testing Android.
https://square.github.io/assertj-android/
Apache License 2.0
1.58k stars 156 forks source link

AbstractTextViewAssert.hasText() leads to java.util.UnknownFormatConversionException if text contains "%" #90

Open larsblumberg opened 10 years ago

larsblumberg commented 10 years ago

Assuming that a text view contains the '%' character, calling

assertThat(textView).hasText("any text")

will throw java.util.UnknownFormatConversionException if the assertion fails (expected text is not actual text).

This is due to AssertionError.failureIfErrorMessageIsOverriden() calling MessageFormatter.instance().format().

The solution would be to escape '%' characters in the description to be formatted.

JakeWharton commented 10 years ago

Nice find.

JakeWharton commented 10 years ago

This seems like a bug in FEST, not this library specifically. It's attempting to do that format twice without proper escaping. I'll have to test with normal assertions to see if this happens.

larsblumberg commented 10 years ago

Thank you Jake