Skip to content

Instantly share code, notes, and snippets.

@trishagee
Last active December 19, 2015 09:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save trishagee/5935645 to your computer and use it in GitHub Desktop.
Save trishagee/5935645 to your computer and use it in GitHub Desktop.
class DBCollectionSpecification extends Specification {
private final Mongo mongo = Mock()
private final ServerSelectingSession session = Mock()
private final DB database = new DB(mongo, 'myDatabase', new DocumentCodec())
@Subject
private final DBCollection collection = new DBCollection('collectionName', database, new DocumentCodec())
def setup() {
mongo.getSession() >> { session }
}
def 'should throw com.mongodb.MongoException if rename fails'() {
setup:
session.execute(_) >> { throw new org.mongodb.MongoException('The error from the new Java layer') }
when:
collection.rename('newCollectionName');
then:
thrown(com.mongodb.MongoException)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment