Skip to content

Commit

Permalink
test(apollo-core): PropertiesUtilTest (#4113)
Browse files Browse the repository at this point in the history
* Create PropertiesUtilTest.java

* Update apollo-core/src/test/java/com/ctrip/framework/apollo/core/utils/PropertiesUtilTest.java

Co-authored-by: wxq <[email protected]>

* Update PropertiesUtilTest.java

Co-authored-by: wxq <[email protected]>
  • Loading branch information
youyulan and Anilople authored Nov 27, 2021
1 parent 80a33ab commit 4a20206
Showing 1 changed file with 60 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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.assertEquals;
import static org.junit.Assert.assertNotEquals;


import java.io.IOException;
import java.util.Properties;


public class PropertiesUtilTest {


@Test
public void testToString() throws IOException {

assertEquals("", PropertiesUtil.toString(new Properties()));
assertNotEquals(" ", PropertiesUtil.toString(new Properties()));

Properties properties = new Properties();
properties.put("a", "aaa");
assertEquals("a=aaa" + System.lineSeparator(), PropertiesUtil.toString(properties));
}

@Test
public void testFilterPropertiesComment() {

StringBuffer sb1 = new StringBuffer(System.lineSeparator());
PropertiesUtil.filterPropertiesComment(sb1);
boolean equals = "".equals(sb1.toString());
assertEquals(false, equals);

StringBuffer sb2 = new StringBuffer("#aaa" + System.lineSeparator());
PropertiesUtil.filterPropertiesComment(sb2);
assertEquals("", sb2.toString());

StringBuffer sb3 = new StringBuffer("#aaaaa" + System.lineSeparator() + "bbb");
PropertiesUtil.filterPropertiesComment(sb3);
assertEquals("bbb", sb3.toString());
assertNotEquals("#aaaaa" + System.lineSeparator() + "bbb", sb3.toString());
}
}

0 comments on commit 4a20206

Please sign in to comment.