[JAVA-205] don't mark methods final Created: 28/Oct/10 Updated: 18/Jun/12 Resolved: 02/Feb/12 |
|
| Status: | Closed |
| Project: | Java Driver |
| Component/s: | API |
| Affects Version/s: | 2.2 |
| Fix Version/s: | 2.8.0 |
| Type: | Improvement | Priority: | Minor - P4 |
| Reporter: | Sam Perman | Assignee: | Jeffrey Yemin |
| Resolution: | Done | Votes: | 8 |
| Labels: | None | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||
| Description |
|
We try to write unit tests for all of our application logic. It is very difficult to do this with mongo. Ideally, we could test our application without having a real mongo server running. Unfortunately, many of the methods inside classes like Mongo, DBCollection, and DB are marked final. This means we can't either stub them out or mock them out. Removing the "final" keyword would make this a lot easier for us. |
| Comments |
| Comment by Jeffrey Yemin [ 18/Jun/12 ] |
|
Closing for 2.8.0 release. |
| Comment by auto [ 02/Feb/12 ] |
|
Author: {u'login': u'jyemin', u'name': u'Jeff Yemin', u'email': u'jeff.yemin@10gen.com'}Message: |
| Comment by Jeffrey Yemin [ 02/Feb/12 ] |
|
@Christian: we can't make them interfaces without breaking binary compatibility, so if we do that it will have to wait until a 3.0 release (see http://semver.org/, which we are going to start following). @Daniel: No need. I'm doing it now. |
| Comment by Daniel Spilker [ 02/Feb/12 ] |
|
The final methods keep us from writing unit tests for the database layer because mock frameworks like Mockito cannot mock final methods. As a result the database layer is the component with the worst unit test coverage. Most methods in DB and DBCollection are not final anyway. I can offer to provide a pull request which removes the final modifiers from DB.getCollection, DB.createCollection, DBCollection.find, DBCollection.findOne, DBCollection.createIndex, DBCollection.ensureIndex, DBCollection.apply and DBCollection.save. Any thoughts on this? |
| Comment by Christian pesch [ 02/Nov/11 ] |
|
What is the problem in removing the "final" keyword or (even better |
| Comment by Jesper Niclasen [ 06/Jun/11 ] |
|
Will you removed the "final" keyword from the methods that still are marked final and when can we expect it to be done? Thank you |
| Comment by Ryan Nitz [ 22/Mar/11 ] |
|
|
| Comment by Ryan Nitz [ 22/Mar/11 ] |
|
As of the 2.5 release, these classes are both abstract: http://api.mongodb.org/java/2.5/com/mongodb/DBCollection.html http://api.mongodb.org/java/2.5/com/mongodb/DB.html Mongo is also no longer final in 2.5: |
| Comment by Daniel Spilker [ 01/Dec/10 ] |
|
I agree with Sam and Remon. Ideally DBCollection and DB should be interfaces, but removing the final qualifiers would do for us. |
| Comment by Remon van Vliet [ 17/Nov/10 ] |
|
I agree, we're running into the same problem and there's no easy way around it. There are very few good reasons to use the final keyword on methods. |
| Comment by Sam Perman [ 28/Oct/10 ] |
|
Having an interface that these class implement would be even better. This would let us implement tests with whatever simulated behavior we wanted. |