/*
 * Copyright 2022 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());
  }
}

@@ -1881,18 +1881,165 @@
 oString());%0A
+    %0A    StringBuffer sb4 = new StringBuffer(%22#aaaa%22);%0A    PropertiesUtil.filterPropertiesComment(sb4);%0A    assertEquals(%22#aaaa%22, sb4.toString());%0A
   %7D%0A%7D%0A

Test coverage (#4287)