I have a test written in Kotlin. It throws UnknownFormatConversionException when I try to assert a String containing % character. The same test in Java works properly.
A hint: Java test calls method
org.assertj.core.api.AbstractAssert#isEqualTo, while Kotlin test callsorg.assertj.core.api.AbstractStringAssert#isEqualTo(which is buggie when there is no args).
import org.junit.Test;
import static org.assertj.core.api.Assertions.assertThat;
public class AssertJTest {
@Test
public void assertJ12() {
assertThat("foo %").isEqualTo("foo %");
}
}
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
class AssertJTest {
@Test
fun assertJ12() {
assertThat("foo %").isEqualTo("foo %")
}
}
Failure message is:
java.util.UnknownFormatConversionException: Conversion = '%'
at java.base/java.util.Formatter.checkText(Formatter.java:2732)
at java.base/java.util.Formatter.parse(Formatter.java:2718)
at java.base/java.util.Formatter.format(Formatter.java:2655)
at java.base/java.util.Formatter.format(Formatter.java:2609)
at java.base/java.lang.String.format(String.java:2897)
at org.assertj.core.api.AbstractStringAssert.isEqualTo(AbstractStringAssert.java:310)
at controllers.api.AssertJTest.assertJ12(AssertJTest.kt:9)
@asolntsev Although your fix looks like to address the immediate issue, I wonder why is kotlin resolving isEqualTo(String template, Object... args) instead of isEqualTo(Object expected) ?
This issue is I believe the same as https://github.com/joel-costigliola/assertj-core/issues/1440#issuecomment-465032464
@asolntsev Although your fix looks like to address the immediate issue, I wonder why is kotlin resolving
isEqualTo(String template, Object... args)instead ofisEqualTo(Object expected)?
Good question. I don't know. It's some specific of Kotlin.
Kotlin has a lot of surprises, you know :) Interoperability with Java is not as good as it should be :(
I guess Kotlin prefer to use function with more specific argument type.
@asolntsev @maximusKon As suggested by @epeee, would adding the following overload method to AbstractStringAssert solve the issue for kotlin users ?
public SELF isEqualTo(String s) {
return super.isEqualTo(s);
}
If Kotlin chooses the method with the most specific arguments then I believe it should address the problem.
Probably. I need to check it.
On Sun, Mar 3, 2019, 11:50 Joel Costigliola notifications@github.com
wrote:
@asolntsev https://github.com/asolntsev @maximusKon
https://github.com/maximusKon As suggested by @epeee
https://github.com/epeee, would adding the following overload method to
AbstractStringAssert solve the issue for kotlin users ?public SELF isEqualTo(String s) {
return super.isEqualTo(s);
}—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/joel-costigliola/assertj-core/issues/1441#issuecomment-469006330,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AARE3W-ACpIFo6nKsTWd3lY2HtF4vkyMks5vS5sCgaJpZM4bBs90
.
@joel-costigliola @maximusKon @epeee
Yes, it also works!
I prepared an alternative PR for the same issue. Probably you find it better:
https://github.com/joel-costigliola/assertj-core/pull/1465
When do you plan to release this fix?
@kevcodez in a few weeks hopefully
Most helpful comment
Probably. I need to check it.
On Sun, Mar 3, 2019, 11:50 Joel Costigliola notifications@github.com
wrote: