title: How can I compare BigDecimals to make my tests pass?
body: <p>I have the following same strange situation into a <code>JUnit</code> test.</p>
  
  <p>So I have this test method:</p>
  
  <pre><code>@Test
  public void getNavInfoTest() throws ParseException {
  
      TirAliquotaRamoI expectedObject = new TirAliquotaRamoI();
  
      DateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
      Date date;
  
      date = formatter.parse("2015-08-01");
  
      Date dataInizio = formatter.parse("2015-08-01");
      Date dataFine = formatter.parse("2100-12-31");
  
      expectedObject.setDataElaborazione(date);
      expectedObject.setTassoLordoAnnuoAppl(BigDecimal.ZERO);
      expectedObject.setTassoGiornalieroNetto(BigDecimal.ZERO);
      expectedObject.setAliquota(BigDecimal.ONE);
      expectedObject.setDataInizio(dataInizio);
      expectedObject.setDataFine(dataFine);
  
      TirAliquotaRamoI tirAliquotaRamoI = pucManager.getNavInfo(date);
  
      assertEquals(tirAliquotaRamoI.getAliquota(), expectedObject.getAliquota());
  
  }
  </code></pre>
  
  <p>At the end I am simply testing if the <code>tirAliquotaRamoI.getAliquota()</code> (obtained from a DB query) have the same value of the same field defined for the created <code>expectedObject</code>:</p>
  
  <pre><code>assertEquals(tirAliquotaRamoI.getAliquota(), expectedObject.getAliquota());
  </code></pre>
  
  <p>So the field for the expected object is created using the <code>BigDecimal.ONE</code> constand and using the debugger I can see that its value is <code>1</code>.</p>
  
  <p>And the <code>tirAliquotaRamoI.getAliquota()</code> obtaind value is <code>1.000000000</code></p>
  
  <p>So, in theory, both represent the same value 1 but the test fail and I obtain:</p>
  
  <pre><code>java.lang.AssertionError: expected:&lt;1.000000000&gt; but was:&lt;1&gt;
      at org.junit.Assert.fail(Assert.java:88)
      at org.junit.Assert.failNotEquals(Assert.java:834)
      at org.junit.Assert.assertEquals(Assert.java:118)
      at org.junit.Assert.assertEquals(Assert.java:144)
      at com.fideuram.dbmanager.PucManagerTest.getNavInfoTest(PucManagerTest.java:90)
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
      at java.lang.reflect.Method.invoke(Method.java:597)
      at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
      at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
      at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
      at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
      at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
      at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
      at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
      at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
      at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
      at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
      at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
      at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
      at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
      at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
      at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
      at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
  </code></pre>
  
  <p>Why if both represent the ame 1.0 value? How can I fix this issue to pass the test?</p>