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(apollo-core): PropertiesUtilTest #4113

Merged
merged 13 commits into from
Nov 27, 2021

Conversation

youyulan
Copy link
Contributor

What's the purpose of this PR

I write a test file for \apollo-core\src\main\java\com\ctrip\framework\apollo\core\utils\PropertiesUtils.java

Which issue(s) this PR fixes:

Fixes #3874

Brief changelog

write two test method for the two function in PropertiesUtils.java seperately.

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 Nov 23, 2021

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

@youyulan
Copy link
Contributor Author

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

@codecov-commenter
Copy link

codecov-commenter commented Nov 24, 2021

Codecov Report

Merging #4113 (d5286d6) into master (80a33ab) will increase coverage by 0.05%.
The diff coverage is n/a.

Impacted file tree graph

@@             Coverage Diff              @@
##             master    #4113      +/-   ##
============================================
+ Coverage     52.49%   52.55%   +0.05%     
- Complexity     2614     2616       +2     
============================================
  Files           484      484              
  Lines         15206    15206              
  Branches       1572     1572              
============================================
+ Hits           7983     7992       +9     
+ Misses         6671     6660      -11     
- Partials        552      554       +2     
Impacted Files Coverage Δ
...ervice/service/ReleaseMessageServiceWithCache.java 85.88% <0.00%> (-1.18%) ⬇️
...ip/framework/apollo/core/utils/PropertiesUtil.java 76.92% <0.00%> (+76.92%) ⬆️

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 80a33ab...d5286d6. Read the comment docs.

Copy link
Contributor

@Anilople Anilople left a comment

Choose a reason for hiding this comment

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

Thank you for your time to participate in open source contributions.

Welcome!


@Test
public void TestProperties() throws IOException {
assertTrue("".equals(PropertiesUtil.toString(new Properties())));
Copy link
Contributor

Choose a reason for hiding this comment

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

Use assertEqual or assertEquals instead of assertTrue


Properties properties = new Properties();
properties.put("a","aaa");
assertTrue("a=aaa\r\n".equals(PropertiesUtil.toString(properties))
Copy link
Contributor

Choose a reason for hiding this comment

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

User System.lineSeperator instead of hard code \r\n \n


@Test
public void TestFilterComment(){
StringBuffer sb=new StringBuffer("#aaaaa\nbbb");
Copy link
Contributor

Choose a reason for hiding this comment

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

String.join(System.lineSepeartor, "#aaaaa“, "bbb"); ?

}

@Test
public void TestFilterComment(){
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
public void TestFilterComment(){
public void testFilterPropertiesComment(){

Keep the method name's convention of test case.

@Test
public void TestFilterComment(){
StringBuffer sb=new StringBuffer("#aaaaa\nbbb");
PropertiesUtil.filterPropertiesComment(sb);
Copy link
Contributor

Choose a reason for hiding this comment

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

You can add more test case to cover all conditional branchs

static boolean filterPropertiesComment(StringBuffer stringBuffer) {
//check whether has comment in the first line
if (stringBuffer.charAt(0) != '#') {
return false;
}
int commentLineIndex = stringBuffer.indexOf("\n");
if (commentLineIndex == -1) {
return false;
}
stringBuffer.delete(0, commentLineIndex + 1);
return true;
}

import java.util.Properties;

/**
* @author Wu Mingkan(Dalian University of Technology)
Copy link
Member

Choose a reason for hiding this comment

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

Should delete author in community project.

@Anilople Anilople changed the title A PR for PropertiesTest.java test(apollo-core): PropertiesUtilTest Nov 27, 2021
Copy link
Contributor

@Anilople Anilople left a comment

Choose a reason for hiding this comment

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

LGTM

@Anilople Anilople merged commit 4a20206 into apolloconfig:master Nov 27, 2021
@github-actions github-actions bot locked and limited conversation to collaborators Nov 27, 2021
@Anilople Anilople added good first issue good first issue Good for beginners area/test Categorizes issue or PR as related to testing labels Nov 27, 2021
@nobodyiam nobodyiam added this to the 2.0.0 milestone Jan 1, 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 good first issue good first issue Good for beginners
Projects
None yet
Development

Successfully merging this pull request may close these issues.

test: improve coverage
5 participants