Skip to content

Instantly share code, notes, and snippets.

Created October 8, 2015 10:07
What would you like to do?
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"));

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