|
| 1 | +/* |
| 2 | + * Copyright 2021 Apollo Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + * |
| 16 | + */ |
| 17 | +package com.ctrip.framework.apollo.core.utils; |
| 18 | + |
| 19 | +import org.junit.Test; |
| 20 | + |
| 21 | +import static org.junit.Assert.assertEquals; |
| 22 | +import static org.junit.Assert.assertNotEquals; |
| 23 | + |
| 24 | + |
| 25 | +import java.io.IOException; |
| 26 | +import java.util.Properties; |
| 27 | + |
| 28 | + |
| 29 | +public class PropertiesUtilTest { |
| 30 | + |
| 31 | + |
| 32 | + @Test |
| 33 | + public void testToString() throws IOException { |
| 34 | + |
| 35 | + assertEquals("", PropertiesUtil.toString(new Properties())); |
| 36 | + assertNotEquals(" ", PropertiesUtil.toString(new Properties())); |
| 37 | + |
| 38 | + Properties properties = new Properties(); |
| 39 | + properties.put("a", "aaa"); |
| 40 | + assertEquals("a=aaa" + System.lineSeparator(), PropertiesUtil.toString(properties)); |
| 41 | + } |
| 42 | + |
| 43 | + @Test |
| 44 | + public void testFilterPropertiesComment() { |
| 45 | + |
| 46 | + StringBuffer sb1 = new StringBuffer(System.lineSeparator()); |
| 47 | + PropertiesUtil.filterPropertiesComment(sb1); |
| 48 | + boolean equals = "".equals(sb1.toString()); |
| 49 | + assertEquals(false, equals); |
| 50 | + |
| 51 | + StringBuffer sb2 = new StringBuffer("#aaa" + System.lineSeparator()); |
| 52 | + PropertiesUtil.filterPropertiesComment(sb2); |
| 53 | + assertEquals("", sb2.toString()); |
| 54 | + |
| 55 | + StringBuffer sb3 = new StringBuffer("#aaaaa" + System.lineSeparator() + "bbb"); |
| 56 | + PropertiesUtil.filterPropertiesComment(sb3); |
| 57 | + assertEquals("bbb", sb3.toString()); |
| 58 | + assertNotEquals("#aaaaa" + System.lineSeparator() + "bbb", sb3.toString()); |
| 59 | + } |
| 60 | +} |
0 commit comments