Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created October 8, 2015 10:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ghusta/47a87c26c2caa203c56b to your computer and use it in GitHub Desktop.
Save ghusta/47a87c26c2caa203c56b to your computer and use it in GitHub Desktop.
Java Unit Tests : Assert on Comparables (BigDecimal)

This is UGLY : With JUnit 4

    BigDecimal actual = new BigDecimal("8.0");
    assertTrue(actual.compareTo(new BigDecimal("8.00")) == 0);
    assertEquals(0, actual.compareTo(new BigDecimal("8.00")));

That's too verbose...

This is BEAUTIFUL : With AssertJ

    BigDecimal actual = new BigDecimal("8.0");
    assertThat(actual).isEqualByComparingTo(new BigDecimal("8.00"));
    assertThat(actual).isEqualByComparingTo("8.00");

That's better !

Thanks AssertJ ! assertj-core

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment