Avoid JUnit's assertEquals

JUnit tests inherit assertion methods for testing. Typically you will assert that an expected result is matched by an actual result.

A common pitfall is to use JUnit's assertEquals, only to find that it does not work correctly for numerical comparisons (and with a slightly confusing error message to boot).

CER converts all instances of Number to its own numerical format (backed by java.math.BigDecimal) before processing, to ensure no loss of precision. This conversion can be problematic and unintuitive if you use JUnit's assertEquals method.

CER includes a replacement in a helper class. Use CREOLETestHelper.assertEquals, which will correctly compare numbers of any type.

For other data types, CREOLETestHelper.assertEquals behaves identically to JUnit's assertEquals, so in general it is good practice to use CREOLETestHelper.assertEquals throughout your tests, to avoid possible confusion (even in the places where technically it is unnecessary).

public void creoleTestHelperNotUsed() {

    final FlexibleRetirementYear flexibleRetirementYear =
        FlexibleRetirementYear_Factory.getFactory().newInstance(
            session);

    flexibleRetirementYear.retirementCause().specifyValue(
        "Reached statutory retirement age.");

    /**
     * Will not work - getValue returns CER's own numerical handler,
     * but 65 is an integer.
     *
     * JUnit will report the somewhat confusing message:
     * junit.framework.AssertionFailedError: expected:<65> but
     * was:<65>
     *
     * Use CREOLETestHelper.assertEquals instead.
     */
    assertEquals(65, flexibleRetirementYear.ageAtRetirement()
        .getValue());

  }