• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

expected:5 but was:5.0000000

 
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i'm sure i've read the solution to this somewhere but just cant find it...

junit.framework.AssertionFailedError: expected:<5> but was:<5.000000000000000000000000000000>
at junit.framework.Assert.fail(Assert.java:47)
at junit.framework.Assert.failNotEquals(Assert.java:282)
at junit.framework.Assert.assertEquals(Assert.java:64)
at junit.framework.Assert.assertEquals(Assert.java:71)
at bd.CenarioTest.testAm(CenarioTest.java:165)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:478)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:344)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:196)



i'm using java5, hibernate2 and mysql4; if instead i use hsql all is fine, but with mysql i get this junit error: how can i turn this around?

if i view database table, 5.00000000... indeed appears just like that, instead of, simply, 5!

TiA
 
author
Posts: 11962
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the Java type returned from "am.getPagoPeloUtente()" and what is the data type for that whatever it is in the database column?

In any case, try comparing the primitive values of the BigDecimal and the other number object. For example, using BigDecimal#longValue(), or BigDecimal#doubleValue() with the help of the third argument for assertEquals(double expected, double actual, double allowedDiff).
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Lasse Koskela:
What is the Java type returned from "am.getPagoPeloUtente()" and what is the data type for that whatever it is in the database column?



returned dataType is BigDecimal
in mysql, when generated by hibernate is:
pagoPeloUtente numeric

and in mysql appears like:
DECIMAL(31,30)
[ February 15, 2006: Message edited by: miguel lisboa ]
 
miguel lisboa
Ranch Hand
Posts: 1282
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
in the meanwhile i tried your suggestion and it worked:

but what i remember is that one could change i dont know what at mysql table fileds so that big decimal 5 is stored as 5 and not as 5.00000000000000.....

thanks for the idea, anyway
 
Ranch Hand
Posts: 33
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
assertEquals(Object obj1, Object obj2) uses the equalsmethod.

But new BigDecimal("2").equals(new BigDecimal("2.0") is false because the equals takes in consideration the scale as well.

Possible solutions:
1. use assertTrue(num1.compareTo(num2)==0);


2. set the same scale for both numbers
 
reply
    Bookmark Topic Watch Topic
  • New Topic