Repository navigation
Support authorizedCollections option for listCollections helpers - #1270
Conversation
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.coroutine.ListCollectionsFlowTest.
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.coroutine.syncadapter.SyncListCollectionsIterable.
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.coroutine.ListCollectionsFlow.
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.syncadapter.SyncListCollectionsIterable.
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.ListCollectionsIterable.
There was a problem hiding this comment.
Is based on com.mongodb.kotlin.client.ListCollectionsIterableTest.
There was a problem hiding this comment.
Is based on com.mongodb.reactivestreams.client.syncadapter.SyncListCollectionsIterable.
There was a problem hiding this comment.
Is based on com.mongodb.reactivestreams.client.ListCollectionsPublisherVerification.
There was a problem hiding this comment.
Is based on org.mongodb.scala.ListCollectionsObservable.
There was a problem hiding this comment.
Is based on org.mongodb.scala.ListCollectionsObservableSpec.
72a7033 to
619a974
Compare
There was a problem hiding this comment.
Is based on com.mongodb.reactivestreams.client.internal.ListCollectionsPublisherImplTest.
jyemin
left a comment
There was a problem hiding this comment.
Started with a review of the API, will proceed with the implementation after initial comments are resolved.
jyemin
left a comment
There was a problem hiding this comment.
Waiting on the unit test we discussed. Otherwise LGTM.
| if (nameOnly) { | ||
| command.append("nameOnly", BsonBoolean.TRUE); | ||
| } | ||
| putIfTrue(command, "authorizedCollections", authorizedCollections); |
There was a problem hiding this comment.
As discussed, add a unit test for this.
There was a problem hiding this comment.
Done.
The added ListCollectionsOperationTest tests the public method ListCollectionsOperation.execute instead of testing the (currently private) method getCommand. This way it covers more of ListCollectionsOperation. Since mocking is needed for this, I introduced MongoMockito.mock (see its documentation for the detailed explanation and links to demo tests). I demonstrated it to @vbabanin and @rozza, and my understanding was that they liked this improvement over Mockito.mock.
| @Test | ||
| void stubbingWithInsufficientStubbingDetector() { | ||
| MongoMockito.mock(ReadBinding.class, bindingMock -> | ||
| when(bindingMock.getOperationContext()).thenReturn(new OperationContext()) | ||
| ); | ||
| } |
There was a problem hiding this comment.
For some reason, unused Mockito stubbing is not reported when we run tests (ideally, stubbingWithInsufficientStubbingDetector must fail with UnnecessaryStubbingException because the test never calls getOperationContext). This has nothing to do with MongoMockito, as I tried the same with Mockito, and nothing was reported there either. Even calling Mockito.validateMockitoUsage didn't help. If someone has any ideas, please comment.
There was a problem hiding this comment.
Add the juniper extension and 💥
@ExtendWith(MockitoExtension.class)
final class InsufficientStubbingDetectorDemoTest {
There was a problem hiding this comment.
Indeed, thank you! After looking at MockitoExtension's code, I discovered that the following manually written code also enables validation:
private MockitoSession session;
@BeforeEach
void beforeEach() {
session = Mockito.mockitoSession().startMocking();
}
@AfterEach
void afterEach() {
session.finishMocking();
}finishMocking calls Mockito.validateMockitoUsage, but only after notifying Mockito.framework() that a test has finished via UniversalTestListener.testFinished.
There was a problem hiding this comment.
Oh, actually, it's the UniversalTestListener.testFinished that checks unused stubbing, not Mockito.validateMockitoUsage.
JAVA-4353
This is the 3rd incarnation of the PR. The previous are (from younger to older): #1263, #855 (the original one).
API changes
MongoDatabase.listCollectionNamesChanged the return type of a method. The change preserves source-code compatibility (existing source code that uses the changed methods does not have to be changed), breaks binary compatibility (existing source code that uses the changed methods has to be recompiled against the updated driver dependency).
com.mongodb.clientMongoDatabaselistCollectionNamesMongoIterableListCollectionNamesIterablecom.mongodb.reactivestreams.clientMongoDatabaselistCollectionNamesPublisherListCollectionNamesPublisherorg.mongodb.scalaMongoDatabaselistCollectionNamesObservableListCollectionNamesObservablecom.mongodb.kotlin.clientMongoDatabaselistCollectionNamesMongoIterableListCollectionNamesIterablecom.mongodb.kotlin.client.coroutineMongoDatabaselistCollectionNamesFlowListCollectionNamesFlowauthorizedCollectionsAdded classes/interfaces with a new method
authorizedCollections.com.mongodb.clientListCollectionsIterableListCollectionNamesIterablecom.mongodb.reactivestreams.clientListCollectionsPublisherListCollectionNamesPublisherorg.mongodb.scalaListCollectionsObservableListCollectionNamesObservablecom.mongodb.kotlin.clientListCollectionsIterableListCollectionNamesIterablecom.mongodb.kotlin.client.coroutineListCollectionsFlowListCollectionNamesFlowJAVA-4353