-
Notifications
You must be signed in to change notification settings - Fork 25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
STORAGE-2798 Updated B2StorageClientWebifierImpl methods to improve extensibility #205
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -103,6 +103,7 @@ | |
import static org.mockito.Matchers.eq; | ||
import static org.mockito.Mockito.mock; | ||
import static org.mockito.Mockito.reset; | ||
import static org.mockito.Mockito.spy; | ||
import static org.mockito.Mockito.times; | ||
import static org.mockito.Mockito.verify; | ||
|
||
|
@@ -1190,7 +1191,9 @@ public void testDownloadById() throws B2Exception { | |
final B2DownloadByIdRequest request = B2DownloadByIdRequest | ||
.builder(fileId(1)) | ||
.build(); | ||
webifier.downloadById(ACCOUNT_AUTH, request, noopContentHandler); | ||
final B2StorageClientWebifierImpl webifierSpy = spy(webifier); | ||
webifierSpy.downloadById(ACCOUNT_AUTH, request, noopContentHandler); | ||
verify(webifierSpy).getDownloadByIdUrl(ACCOUNT_AUTH, request); | ||
|
||
webApiClient.check("getContent.\n" + | ||
"url:\n" + | ||
|
@@ -1201,7 +1204,7 @@ public void testDownloadById() throws B2Exception { | |
" X-Bz-Test-Mode: force_cap_exceeded\n" | ||
); | ||
|
||
assertEquals(expectedUrl, webifier.getDownloadByIdUrl(ACCOUNT_AUTH, request)); | ||
assertEquals(expectedUrl, webifierSpy.getDownloadByIdUrl(ACCOUNT_AUTH, request)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why does this need to use the spy'ed object? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It doesn't need to be. Is it a good practice to only use the spy reference when using Mockito calls and the non spy in cases like this? I was thinking it might be less confusing if using the same spy reference throughout the code instead of mixing. Don't mind either way. I'll change it back |
||
|
||
checkRequestCategory(OTHER, w -> w.downloadById(ACCOUNT_AUTH, request, noopContentHandler)); | ||
} | ||
|
@@ -1303,7 +1306,9 @@ public void testDownloadByName() throws B2Exception { | |
final B2DownloadByNameRequest request = B2DownloadByNameRequest | ||
.builder(bucketName(1), fileName(1)) | ||
.build(); | ||
webifier.downloadByName(ACCOUNT_AUTH, request, noopContentHandler); | ||
final B2StorageClientWebifierImpl webifierSpy = spy(webifier); | ||
webifierSpy.downloadByName(ACCOUNT_AUTH, request, noopContentHandler); | ||
verify(webifierSpy).getDownloadByNameUrl(ACCOUNT_AUTH, request); | ||
|
||
webApiClient.check("getContent.\n" + | ||
"url:\n" + | ||
|
@@ -1313,7 +1318,7 @@ public void testDownloadByName() throws B2Exception { | |
" User-Agent: SecretAgentMan/3.19.28\n" + | ||
" X-Bz-Test-Mode: force_cap_exceeded\n" | ||
); | ||
assertEquals(expectedUrl, webifier.getDownloadByNameUrl(ACCOUNT_AUTH, request)); | ||
assertEquals(expectedUrl, webifierSpy.getDownloadByNameUrl(ACCOUNT_AUTH, request)); | ||
|
||
checkRequestCategory(OTHER, w -> w.downloadByName(ACCOUNT_AUTH, request, noopContentHandler)); | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... I think this tests that getDownloadByIdUrl is called but my brain is wondering how useful this verify actually is beyond that. isn't that just an implementation detail? how does verifying it actually tell us more about whether downloadById is working as designed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was thinking that the combination of the verify and the assertion in the test would test that
downloadById()
is working as designed.The verify checks that the getDownloadByIdUrl() is being called, which is an implementation detail, but an important one as that was the PR change
This verify alone doesn't test that the method is working properly however along with the assertion that the value from the verify call (expectedUrl) is the same as the one being passed to the web client call, we test that we call the right thing and that the right thing is passed.