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

Add unit tests for Utils #4193

Merged
merged 1 commit into from
Jan 7, 2022

Conversation

joshknopp
Copy link
Contributor

@joshknopp joshknopp commented Jan 5, 2022

What's the purpose of this PR

Increase test coverage on one class to help push toward 80% coverage goal.

Which issue(s) this PR fixes:

Fixes #3874

Brief changelog

Add 100% test coverage for a single Utils class

Follow this checklist to help us incorporate your contribution quickly and easily:

  • Read the Contributing Guide before making this pull request.
  • Write a pull request description that is detailed enough to understand what the pull request does, how, and why.
  • Write necessary unit tests to verify the code.
  • Run mvn clean test to make sure this pull request doesn't break anything.
  • Update the CHANGES log.

@github-actions
Copy link

github-actions bot commented Jan 5, 2022

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@joshknopp
Copy link
Contributor Author

I have read the CLA Document and I hereby sign the CLA

@joshknopp joshknopp force-pushed the add-tests-for-utils branch from 85f9758 to 6f4b525 Compare January 5, 2022 12:28
@joshknopp
Copy link
Contributor Author

Squashed commits, should now show as one commit.

Please note comment intended for @nobodyiam regarding case sensitivity.

@codecov-commenter
Copy link

codecov-commenter commented Jan 5, 2022

Codecov Report

Merging #4193 (b7d4619) into master (02f0dca) will not change coverage.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff            @@
##             master    #4193   +/-   ##
=========================================
  Coverage     52.60%   52.60%           
  Complexity     2621     2621           
=========================================
  Files           484      484           
  Lines         15192    15192           
  Branches       1571     1571           
=========================================
  Hits           7991     7991           
  Misses         6645     6645           
  Partials        556      556           
Impacted Files Coverage Δ
...rk/apollo/spring/property/SpringValueRegistry.java 83.78% <0.00%> (-5.41%) ⬇️
...om/ctrip/framework/foundation/internals/Utils.java 83.33% <0.00%> (+33.33%) ⬆️

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 02f0dca...b7d4619. Read the comment docs.

@Anilople
Copy link
Contributor

Anilople commented Jan 5, 2022

Welcome~ @joshknopp

import static org.junit.jupiter.api.Assertions.assertTrue;

/**
* @author Josh Knopp(https://github.com/joshknopp)
Copy link
Contributor

Choose a reason for hiding this comment

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

Please delete the author in javadoc, because your change will be show in git's commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No problem - was trying to follow style guide, but I'm indifferent 😄

Comment on lines 46 to 67
private String actualOsName;

@BeforeEach
void setUp() {
actualOsName = System.getProperty("os.name");
}
Copy link
Contributor

Choose a reason for hiding this comment

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

How about delete the setUp method?
Just assign value to actualOsName once.

Suggested change
private String actualOsName;
@BeforeEach
void setUp() {
actualOsName = System.getProperty("os.name");
}
private final String actualOsName = System.getProperty("os.name");

Copy link
Contributor Author

@joshknopp joshknopp Jan 5, 2022

Choose a reason for hiding this comment

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

Thanks @Anilople for the feedback! Updated in new commit.

@joshknopp joshknopp changed the title Add tests for utils Add unit tests for Utils Jan 5, 2022
@joshknopp joshknopp force-pushed the add-tests-for-utils branch 2 times, most recently from 0d142d3 to 1b87ff7 Compare January 5, 2022 13:59
@joshknopp
Copy link
Contributor Author

Just realized I have added JUnit5 tests, and everything else appears to be JUnit4 🤦‍♂️ Is there appetite for 5, or should I reset and try again?

@joshknopp joshknopp requested a review from Anilople January 5, 2022 20:47
@nobodyiam
Copy link
Member

Just realized I have added JUnit5 tests, and everything else appears to be JUnit4 🤦‍♂️ Is there appetite for 5, or should I reset and try again?

It may keep some sort of consistency if we write the unit tests in JUnit 4 styles but generally, I think it's all right. What do you think @Anilople ?

@joshknopp
Copy link
Contributor Author

Just realized I have added JUnit5 tests, and everything else appears to be JUnit4 🤦‍♂️ Is there appetite for 5, or should I reset and try again?

It may keep some sort of consistency if we write the unit tests in JUnit 4 styles but generally, I think it's all right. What do you think @Anilople ?

Looks like Codecov is not picking up JUnit 5 so I'll try rewriting with 4.

@joshknopp joshknopp force-pushed the add-tests-for-utils branch from 1b87ff7 to b7d4619 Compare January 6, 2022 03:18
@joshknopp joshknopp requested a review from nobodyiam January 6, 2022 03:19
@hezhangjian
Copy link
Member

@nobodyiam com.ctrip.framework.apollo.core.utils.StringUtils has a method isBlank too.
What's the relationship between com.ctrip.framework.foundation and com.ctrip.framework.apollo.
Maybe we only need one #isBlank method

@hezhangjian
Copy link
Member

@nobodyiam do we consider use apache common-langs ?

@Anilople
Copy link
Contributor

Anilople commented Jan 6, 2022

@nobodyiam do we consider use apache common-langs ?

A reliable middleware need to reduce dependencies as it can. So if we can implement the function via a few code, it's better implement without third dependencies.

Just a bit of my thoughts.

@Anilople Anilople added the area/test Categorizes issue or PR as related to testing label Jan 6, 2022
@Anilople
Copy link
Contributor

Anilople commented Jan 6, 2022

Just realized I have added JUnit5 tests, and everything else appears to be JUnit4 🤦‍♂️ Is there appetite for 5, or should I reset and try again?

It may keep some sort of consistency if we write the unit tests in JUnit 4 styles but generally, I think it's all right. What do you think @Anilople ?

I think it's all right too in this pr.

An issue #4195 was opend to disscus upgrade to junit 5 or not.

@hezhangjian
Copy link
Member

hezhangjian commented Jan 6, 2022

@Anilople commons-lang is stable, Anyway and at least, I don't think that we need two isBlank method in com.ctrip.framework.foundation and com.ctrip.framework.apollo

Copy link
Member

@nobodyiam nobodyiam left a comment

Choose a reason for hiding this comment

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

LGTM

@nobodyiam
Copy link
Member

@Anilople commons-lang is stable, Anyway and at least, I don't think that we need two isBlank method in com.ctrip.framework.foundation and com.ctrip.framework.apollo

@shoothzj
I checked the commit history and found these 2 isBlank methods were introduced in different historic reasons. But I agree with you it's unnecessary to have 2 isBlank methods with the same purpose. I think we could open another pr to fix this and keep this pr only to serve the unit test purpose.
As for commons-lang, I agree with @Anilople that it's generally a good practice to keep the sdk's dependencies as less as possible, e.g. apollo-core now only has 3 compile scope dependencies (gson, guava, slf4j-api). So unless it's really necessary, I would suggest we keep the custom version of StringUtils.

@hezhangjian
Copy link
Member

Agreed. I will start another issue discuss this

@Anilople Anilople merged commit fec79aa into apolloconfig:master Jan 7, 2022
@github-actions github-actions bot locked and limited conversation to collaborators Jan 7, 2022
@nobodyiam nobodyiam added this to the 2.0.0 milestone Jan 23, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area/test Categorizes issue or PR as related to testing
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: improve coverage
5 participants