lordofthejars / nosql-unit

NoSQL Unit is a JUnit extension that helps you write NoSQL unit tests.
Other
383 stars 123 forks source link

ClassCastException in Group at Util.extractField #161

Closed joergreichert closed 8 years ago

joergreichert commented 8 years ago

With calling aggregate and using group by sum for float field "my_attribute"

mongoTemplate.aggregate(agg, "my_collection", Map.class);

this causes a ClassCastException at line with Util.extractField (String cannot be cast to number)

com.github.fakemongo.impl.aggregation.Group.sum(DBCollection, Object)

Number result= null;
...
// object = { "my_attribute" : "123.45"}  
// field = "my_attribute"
result = Util.extractField(object, field); // com.github.fakemongo.impl.Util.extractField(DBObject, String)

Inside "object" the value is actual a string.

But using an explicit class instead, e.g. a custom class Result, having myAttribute with the correct type doesn't help: object still contains a string as value.

So either the code should try to parse the String as Number (instead of casting it) or assure that the value is of correct type.

lordofthejars commented 8 years ago

Can you paste the whole stack trace? It seems a problem with fakemongo rather than nosqlunit ?

joergreichert commented 8 years ago

Yes, you're right. I wasn't aware that nosqlunit and fongo are different projects. I created a new bug for fongo: https://github.com/fakemongo/fongo/issues/224

lordofthejars commented 8 years ago

Thank you very much for using nosqlunit

El 19 ago. 2016 10:19 a. m., "Jörg Reichert" notifications@github.com escribió:

Closed #161 https://github.com/lordofthejars/nosql-unit/issues/161.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/lordofthejars/nosql-unit/issues/161#event-760962031, or mute the thread https://github.com/notifications/unsubscribe-auth/ABcmYVZa46ejIEVl4xpe1__y9oGbm9xzks5qhWcJgaJpZM4Jli-w .

joergreichert commented 8 years ago

For your interest: https://github.com/fakemongo/fongo/issues/224#issuecomment-241468965

Bit I'm not sure, on which side the bug should be fixed.