Skip to content
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

test: convert remaining StorageImpl tests from easymock to mockito #667

Closed
wants to merge 3 commits into from

Conversation

dmitry-fa
Copy link
Contributor

Fixes #270

For the convenience of reviewers this PR comprises two commits, the second commit allows to see the converted tests as if there were changed, not added.

@dmitry-fa dmitry-fa requested a review from a team December 17, 2020 12:24
@product-auto-label product-auto-label bot added the api: storage Issues related to the googleapis/java-storage API. label Dec 17, 2020
@google-cla google-cla bot added the cla: yes This human has signed the Contributor License Agreement. label Dec 17, 2020
@codecov
Copy link

codecov bot commented Dec 17, 2020

Codecov Report

Merging #667 (7124048) into master (62b7713) will increase coverage by 0.50%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master     #667      +/-   ##
============================================
+ Coverage     64.26%   64.76%   +0.50%     
  Complexity      621      621              
============================================
  Files            32       32              
  Lines          5322     5322              
  Branches        521      521              
============================================
+ Hits           3420     3447      +27     
+ Misses         1740     1713      -27     
  Partials        162      162              
Impacted Files Coverage Δ Complexity Δ
...ain/java/com/google/cloud/storage/StorageImpl.java 84.61% <0.00%> (+3.29%) 138.00% <0.00%> (ø%)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 62b7713...7124048. Read the comment docs.

@@ -16,27 +16,38 @@

package com.google.cloud.storage;

import static com.google.cloud.storage.SignedUrlEncodingHelper.Rfc3986UriEncode;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO, this isn't familiar enough to static import.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

assertEquals("https://storage.googleapis.com/my-bucket/", policy.getUrl());

// test fields, no conditions
policy =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reassigning local variables is a code smell that suggests this could be broken up into multiple tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

agree, done.
Please take a look.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elharo, it would be awesome if you take another look at this change before the New Year

@fazunenko
Copy link

@frankyn, If you could find time to look and merge this change before conflicts arise, it would be awesome.

Copy link
Contributor

@elharo elharo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://engdoc.corp.google.com/eng/doc/devguide/java/testing/mocking.md?cl=head#google-style suggests you don't want both doReturn and doThrow on one mock.

public void testUpdateBucket() {
BucketInfo updatedBucketInfo = BUCKET_INFO1.toBuilder().setIndexPage("some-page").build();
doReturn(updatedBucketInfo.toPb())
.doThrow(UNEXPECTED_CALL_EXCEPTION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why you're throwing this exception here. Is this testing the bucket is still updated when an exception is thrown?

@Test
public void testUpdateBucketWithOptions() {
BucketInfo updatedBucketInfo = BUCKET_INFO1.toBuilder().setIndexPage("some-page").build();
doReturn(updatedBucketInfo.toPb())
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I don't understand using both doReturn and doThrow in the same chain. What's happening here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@elharo doThrow(UNEXPECTED_CALL_EXCEPTION) after doReturn() makes unit tests stronger. It guarantees that the method is calling only once(or the expected number of times). If someone updates the code to call the method twice (by mistake) the test will discover that.

public void testUpdateBlob() {
BlobInfo updatedBlobInfo = BLOB_INFO1.toBuilder().setContentType("some-content-type").build();
doReturn(updatedBlobInfo.toPb())
.doThrow(UNEXPECTED_CALL_EXCEPTION)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this supposed to fail the test if there's a second call? I'm not sure that's something that should be tested here. Mockito tries to be more forgiving than EasyMock.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doThrow() is not necessary of course. Removing .doThrow will make the tests weaker.

suztomo
suztomo previously approved these changes Feb 15, 2022
@eaball35 eaball35 added the kokoro:force-run Add this label to force Kokoro to re-run the tests. label Jun 9, 2022
@frankyn
Copy link
Member

frankyn commented Aug 4, 2022

Closing this PR out. We will revisit in the future.

@frankyn frankyn closed this Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api: storage Issues related to the googleapis/java-storage API. cla: yes This human has signed the Contributor License Agreement. kokoro:force-run Add this label to force Kokoro to re-run the tests.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Convert StorageImplTest from EasyMock to Mockito
6 participants