Skip to content

Instantly share code, notes, and snippets.

@ghusta
Created October 8, 2015 10:07
Embed
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"));
    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