Skip to content

Commit 367e498

Browse files
committed
Remove specific verify use occurrences and replace with atLeastOnce()
1 parent dbda7b4 commit 367e498

File tree

2 files changed

+32
-23
lines changed

2 files changed

+32
-23
lines changed

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/DefaultDbRefResolverUnitTests.java

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,15 +164,16 @@ void resolveEmptyMapIsNotNull() {
164164

165165
Object target = resolver.resolveReference(property, source, lookupDelegate, entityReader);
166166

167-
verify(property, times(3)).isMap();
168-
verify(property, times(2)).isDocumentReference();
169-
verify(property, times(2)).getDocumentReference();
170-
verify(property, times(3)).isCollectionLike();
171-
verify(documentReference, times(1)).lookup();
172-
verify(documentReference, times(1)).sort();
173-
verify(documentReference, times(1)).lazy();
174-
verify(source, times(3)).getTargetSource();
167+
verify(property, atLeastOnce()).isMap();
168+
verify(property, atLeastOnce()).isDocumentReference();
169+
verify(property, atLeastOnce()).getDocumentReference();
170+
verify(property, atLeastOnce()).isCollectionLike();
171+
verify(documentReference, atLeastOnce()).lookup();
172+
verify(documentReference, atLeastOnce()).sort();
173+
verify(documentReference, atLeastOnce()).lazy();
174+
verify(source, atLeastOnce()).getTargetSource();
175175
verifyNoMoreInteractions(documentReference, property, source); // Make sure we only call the properties we mocked.
176+
176177
assertThat(target)
177178
.isNotNull()
178179
.isInstanceOf(Map.class);
@@ -200,13 +201,13 @@ void resolveLazyLoadedEmptyMapIsNotNull() {
200201

201202
Object target = resolver.resolveReference(property, source, lookupDelegate, entityReader);
202203

203-
verify(property, times(1)).isMap();
204-
verify(property, times(1)).isDocumentReference();
205-
verify(property, times(1)).getDocumentReference();
206-
verify(property, times(1)).isCollectionLike();
207-
verify(property, times(1)).getType();
208-
verify(documentReference, times(1)).lazy();
209-
verify(source, times(1)).getTargetSource();
204+
verify(property, atLeastOnce()).isMap();
205+
verify(property, atLeastOnce()).isDocumentReference();
206+
verify(property, atLeastOnce()).getDocumentReference();
207+
verify(property, atLeastOnce()).isCollectionLike();
208+
verify(property, atLeastOnce()).getType();
209+
verify(documentReference, atLeastOnce()).lazy();
210+
verify(source, atLeastOnce()).getTargetSource();
210211
verifyNoMoreInteractions(documentReference, property, source); // Make sure we only call the properties we mocked.
211212

212213
assertThat(target)

spring-data-mongodb/src/test/java/org/springframework/data/mongodb/core/convert/ReferenceLookupDelegateUnitTests.java

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -111,18 +111,26 @@ void shouldResolveEmptyMapOnEmptyDocumentReferenceMapProperty() {
111111
when(property.isCollectionLike()).thenReturn(false);
112112
DocumentReferenceSource source = mock(DocumentReferenceSource.class);
113113
when(source.getTargetSource()).thenReturn(Document.parse("{}"));
114+
115+
// Placeholder mock. It should never get called.
114116
ReferenceLookupDelegate.LookupFunction lookupFunction = mock(ReferenceLookupDelegate.LookupFunction.class);
115117

116118
Object target = lookupDelegate.readReference(property, source, lookupFunction, entityReader);
117119

118-
verify(lookupFunction, never()).apply(any(), any()); // Since we mocked it, make sure it is never called.
119-
verify(property, times(2)).isMap();
120-
verify(property, times(1)).isDocumentReference();
121-
verify(property, times(1)).getDocumentReference();
122-
verify(property, times(2)).isCollectionLike();
123-
verify(documentReference, times(1)).lookup();
124-
verify(documentReference, times(1)).sort();
125-
verifyNoMoreInteractions(documentReference, property, source); // Make sure we only call the properties we mocked.
120+
// Since we mocked a placeholder that should never be called, make sure it is never called.
121+
verify(lookupFunction, never()).apply(any(), any());
122+
123+
// Verify that all the mocks we created are used.
124+
verify(property, atLeastOnce()).isMap();
125+
verify(property, atLeastOnce()).isDocumentReference();
126+
verify(property, atLeastOnce()).getDocumentReference();
127+
verify(property, atLeastOnce()).isCollectionLike();
128+
verify(documentReference, atLeastOnce()).lookup();
129+
verify(documentReference, atLeastOnce()).sort();
130+
131+
// Make sure we only call the properties we mocked.
132+
verifyNoMoreInteractions(documentReference, property, source);
133+
126134
assertThat(target)
127135
.isNotNull()
128136
.isInstanceOf(Map.class);

0 commit comments

Comments
 (0)