FEST
  1. FEST
  2. FEST-420

Provide more verbose message when comparison failure of objects with same toString()

    Details

    • Type: Improvement Improvement
    • Status: Reopened Reopened
    • Priority: Major Major
    • Resolution: Unresolved
    • Affects Version/s: FEST-Assert 1.3
    • Fix Version/s: FEST-Assert 2.0
    • Component/s: Assert
    • Labels:
      None
    • Testcase included:
      yes
    • Patch Submitted:
      Yes
    • Number of attachments :
      0

      Description

      It's very confusing when comparison failure occurs but compared objects have the same toString() value. For instance objects representing 42.0f and 42.0d are not equal but the failure will yield:

      org.junit.ComparisonFailure: [message] 
      Expected :42.0
      Actual   :42.0

      ...which seems a bit confusing. The same applies to more complex objects not having all properties tested in equals() included in toString(), so that toString() appears to be the same. I implemented more verbose mechanism of reporting comparison failures that detects equal toString() representations and (only then) includes more details about compared objects:

      org.junit.ComparisonFailure: [message] 
      Expected :42.0 (Float@42280000)
      Actual   :42.0 (Double@40450000)

      See changes made in this (including test cases): https://github.com/nurkiewicz/fest-assert-1.x/commits/comparison

        Activity

        Hide
        Joel Costigliola added a comment -

        does not work yet for :

        List<Long> longs = list(5L, 7L); 
        assertThat(longs).contains(5, 7); 
        

        Message was :

        expecting:<[5, 7]> to contain:<[5, 7]> but could not find:<[5, 7]>
        Show
        Joel Costigliola added a comment - does not work yet for : List< Long > longs = list(5L, 7L); assertThat(longs).contains(5, 7); Message was : expecting:<[5, 7]> to contain:<[5, 7]> but could not find:<[5, 7]>
        Hide
        Joel Costigliola added a comment -

        The problem is not completely fixed but some improvements have been made to differentiate long from integer and float from double.

        try {
          List<Long> longs = list(5L, 7L);
          assertThat(longs).contains(5, 7);
        } catch (AssertionError e) {
          assertThat(e).hasMessage("expecting:<[5L, 7L]> to contain:<[5, 7]> but could not find:<[5, 7]>");
        }
        
        Show
        Joel Costigliola added a comment - The problem is not completely fixed but some improvements have been made to differentiate long from integer and float from double. try { List< Long > longs = list(5L, 7L); assertThat(longs).contains(5, 7); } catch (AssertionError e) { assertThat(e).hasMessage( "expecting:<[5L, 7L]> to contain:<[5, 7]> but could not find:<[5, 7]>" ); }

          People

          • Assignee:
            Joel Costigliola
            Reporter:
            Tomasz Nurkiewicz
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated: