assertj/assertj-guava

unexpected behavior in "Guava assertions quickstart guide"

lbalazscs opened this issue · 8 comments

Using guava 18.0, assertj-core 1.7.1 and assertj-guava 1.3.0, the example program shows the following message:

Exception in thread "main" java.lang.AssertionError: 
Expecting:
<[10‥12]>
to have upper endpoint equal to:
<10>
but was
<10>

Expected 10, but found 10???
The code in question is the following:

    Range<Integer> range = Range.closed(10, 12);
    assertThat(range).isNotEmpty()
            .contains(10, 11, 12)
            .hasClosedLowerBound()
            .hasUpperEndpointEqualTo(10);

The full code is at http://joel-costigliola.github.io/assertj/assertj-guava.html#quickstart

I'm not able to reproduce the problem after using guava 18.0, assertj-core 1.7.1 and assertj-guava 1.3.0 in assertj-examples master branch.

What is your environment ?

Mine was:

Maven home: /home/joel/prog/apache-maven-3.2.2
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: /home/joel/prog/jdk1.7.0_45/jre
Default locale: en_AU, platform encoding: UTF-8
OS name: "linux", version: "3.13.0-45-generic", arch: "amd64", family: "unix"

java.runtime.version=1.7.0_60-b19
os.name=Windows 8.1
user.language=en
user.language.format=hu

but I get the same result with java 8 (java.runtime.version=1.8.0_25-b18)

My full source code is here: https://gist.github.com/lbalazscs/c4c7b395f6e3b46c9a88

I debugged a little bit, and found that the problem is the hasUpperEndpointEqualTo method of RangeAssert: in the line

if (!actual.upperEndpoint().equals(value)) {

12 is compared to 10 in the equals method of Integer. I am not sure what should happen here - if I understand correctly, the upper bound is 12, and the test should fail, but the error message (expected 10, found 10) is incorrect even if the test is supposed to fail.

Ok, I was able to reproduce the problem, this is a bug in the error message, assertion is correct but the error message is not as it uses the lower end point instead the upper one.

I have just release assertj-guava 1.3.1, should be soon available in maven central.

Yes, the 1.3.1 code is OK, but note that the webpage at http://joel-costigliola.github.io/assertj/assertj-guava.html#quickstart still recommends the use of version 1.3.0 (in the "1 - Add assertj-guava dependency to your project pom.xml" step)...

I know that, I was just waiting the version to be available in maven central, will update that today along with the release notes.
Thanks for reporting this issue.