-
-
Notifications
You must be signed in to change notification settings - Fork 10.2k
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
Changes from 5 commits
0d335f9
950255f
b84bebb
595549d
567b3e2
964767c
388bd53
271d990
5896ae9
2f73515
16904e7
f5a46ca
d5286d6
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 | ||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,54 @@ | ||||||||||||||||||||||||||
/* | ||||||||||||||||||||||||||
* Copyright 2021 Apollo Authors | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||||||||||||||||||||||||||
* you may not use this file except in compliance with the License. | ||||||||||||||||||||||||||
* You may obtain a copy of the License at | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
* http://www.apache.org/licenses/LICENSE-2.0 | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
* Unless required by applicable law or agreed to in writing, software | ||||||||||||||||||||||||||
* distributed under the License is distributed on an "AS IS" BASIS, | ||||||||||||||||||||||||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||||||||||||||||||||||||||
* See the License for the specific language governing permissions and | ||||||||||||||||||||||||||
* limitations under the License. | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
package com.ctrip.framework.apollo.core.utils; | ||||||||||||||||||||||||||
import org.junit.Test; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import static org.junit.Assert.assertFalse; | ||||||||||||||||||||||||||
import static org.junit.Assert.assertTrue; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
import java.io.IOException; | ||||||||||||||||||||||||||
import java.io.StringWriter; | ||||||||||||||||||||||||||
import java.util.Properties; | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
/** | ||||||||||||||||||||||||||
* @author Wu Mingkan(Dalian University of Technology) | ||||||||||||||||||||||||||
* @since 2021/11/23 | ||||||||||||||||||||||||||
* | ||||||||||||||||||||||||||
*/ | ||||||||||||||||||||||||||
public class PropertiesUtilTest { | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||
public void TestProperties() throws IOException { | ||||||||||||||||||||||||||
youyulan marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||
assertTrue("".equals(PropertiesUtil.toString(new Properties()))); | ||||||||||||||||||||||||||
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. Use assertEqual or assertEquals instead of assertTrue |
||||||||||||||||||||||||||
assertFalse(" ".equals(PropertiesUtil.toString(new Properties()))); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
Properties properties = new Properties(); | ||||||||||||||||||||||||||
properties.put("a","aaa"); | ||||||||||||||||||||||||||
assertTrue("a=aaa\r\n".equals(PropertiesUtil.toString(properties)) | ||||||||||||||||||||||||||
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. User System.lineSeperator instead of hard code |
||||||||||||||||||||||||||
|| "a=aaa\n".equals(PropertiesUtil.toString(properties))); | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
|
||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||
public void TestFilterComment(){ | ||||||||||||||||||||||||||
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.
Suggested change
Keep the method name's convention of test case. |
||||||||||||||||||||||||||
StringBuffer sb=new StringBuffer("#aaaaa\nbbb"); | ||||||||||||||||||||||||||
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. String.join(System.lineSepeartor, "#aaaaa“, "bbb"); ? |
||||||||||||||||||||||||||
PropertiesUtil.filterPropertiesComment(sb); | ||||||||||||||||||||||||||
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. You can add more test case to cover all conditional branchs apollo/apollo-core/src/main/java/com/ctrip/framework/apollo/core/utils/PropertiesUtil.java Lines 46 to 57 in 9e19898
|
||||||||||||||||||||||||||
assertTrue("bbb".equals(sb.toString())); | ||||||||||||||||||||||||||
assertFalse("#aaaaa\nbbb".equals(sb.toString())); | ||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||
} |
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.
Should delete author in community project.