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

[Improvement-12296][Test] Close static mock #12300

Merged
merged 1 commit into from
Oct 11, 2022

Conversation

rickchengx
Copy link
Contributor

@rickchengx rickchengx commented Oct 10, 2022

Purpose of the pull request

Brief change log

In some UT cases, static mocks are not closed after used. This may cause unexpected UT failure. The best practice is to handle it with try-with-resource, see the code below for an example:

try (MockedStatic<DateUtils> mockedDateUtils = Mockito.mockStatic(DateUtils.class)) {
mockedDateUtils.when(() -> DateUtils.getCurrentTime(YYYYMMDDHHMMSS)).thenReturn("20190101101059");
Assert.assertEquals("/tmp/dolphinscheduler/download/20190101101059/test",
FileUtils.getDownloadFilename("test"));
}

Verify this pull request

manually tested

@EricGao888 EricGao888 self-requested a review October 11, 2022 02:38
@EricGao888 EricGao888 added improvement make more easy to user or prompt friendly test labels Oct 11, 2022
@EricGao888 EricGao888 added this to the 3.2.0 milestone Oct 11, 2022
@codecov-commenter
Copy link

codecov-commenter commented Oct 11, 2022

Codecov Report

Merging #12300 (e032794) into dev (a973054) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##                dev   #12300   +/-   ##
=========================================
  Coverage     38.53%   38.53%           
  Complexity     4075     4075           
=========================================
  Files          1023     1023           
  Lines         38267    38267           
  Branches       4393     4393           
=========================================
  Hits          14748    14748           
  Misses        21796    21796           
  Partials       1723     1723           

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@rickchengx
Copy link
Contributor Author

rebased dev to remove conflicts

Copy link
Member

@EricGao888 EricGao888 left a comment

Choose a reason for hiding this comment

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

LGTM, waiting for CI to pass

@EricGao888 EricGao888 self-requested a review October 11, 2022 06:09
@sonarcloud
Copy link

sonarcloud bot commented Oct 11, 2022

Kudos, SonarCloud Quality Gate passed!    Quality Gate passed

Bug A 0 Bugs
Vulnerability A 0 Vulnerabilities
Security Hotspot A 0 Security Hotspots
Code Smell A 0 Code Smells

No Coverage information No Coverage information
0.0% 0.0% Duplication

@EricGao888
Copy link
Member

If no more comments, I will proceed to merge this PR later this afternoon.

@EricGao888 EricGao888 merged commit 05099bd into apache:dev Oct 11, 2022
xdu-chenrj pushed a commit to xdu-chenrj/dolphinscheduler that referenced this pull request Oct 13, 2022
fuchanghai pushed a commit to fuchanghai/dolphinscheduler that referenced this pull request Nov 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend improvement make more easy to user or prompt friendly
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Improvement][Test] Close static mock
3 participants