/*
 *  Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 *  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 org.wso2.carbon.uuf.renderablecreator.hbs.internal.io;

import org.testng.Assert;
import org.testng.annotations.Test;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

public class PlaceholderWriterTest {

    @Test
    public void testWithoutPlaceholders() throws IOException {
        PlaceholderWriter placeholderWriter = new PlaceholderWriter();
        placeholderWriter.write("First line.\n");
        placeholderWriter.write("Second line.\n");
        placeholderWriter.write("Third line.\n");
        placeholderWriter.write("Final text.");
        Assert.assertEquals(placeholderWriter.toString(), "First line.\nSecond line.\nThird line.\nFinal text.");
        placeholderWriter.close();
    }

    @Test
    public void testWithPlaceholders() throws IOException {
        PlaceholderWriter placeholderWriter = new PlaceholderWriter();
        placeholderWriter.addPlaceholder("p0");
        placeholderWriter.write("First line.\n");
        placeholderWriter.write("Second line.\n");
        placeholderWriter.addPlaceholder("p1");
        placeholderWriter.addPlaceholder("p2");
        placeholderWriter.write("Third line.\n");
        placeholderWriter.write("Forth line.\n");
        placeholderWriter.addPlaceholder("p3");
        Map<String, String> placeholderValues = new HashMap<>(4);
        placeholderValues.put("p0", "Placeholder zero,");
        placeholderValues.put("p1", "Placeholder one,");
        placeholderValues.put("p2", "Placeholder two,");
        placeholderValues.put("p3", "Placeholder three");
        String output = placeholderWriter.toString(placeholderValues);
        output = output.replaceAll("<!--.*-->\n", "");
        String expectedOutput = "Placeholder zero,First line.\nSecond line.\nPlaceholder one,Placeholder two," +
                "Third line.\nForth line.\nPlaceholder three";
        Assert.assertEquals(output, expectedOutput);
        placeholderWriter.close();
    }
}
@@ -1,14 +1,13 @@
 /*%0A *
- 
  Copyrig
@@ -82,17 +82,43 @@
 %0A * 
- Licensed
+WSO2 Inc. licenses this file to you
  und
@@ -139,16 +139,19 @@
 License,
+%0A *
  Version
@@ -171,20 +171,16 @@
 cense%22);
-%0A * 
  you may
@@ -204,16 +204,19 @@
 e except
+%0A *
  in comp
@@ -242,17 +242,16 @@
 ense.%0A *
- 
  You may
@@ -288,17 +288,16 @@
 at%0A *%0A *
- 
  http://
@@ -337,17 +337,16 @@
 .0%0A *%0A *
- 
  Unless 
@@ -396,16 +396,19 @@
 writing,
+%0A *
  softwar
@@ -408,20 +408,16 @@
 software
-%0A * 
  distrib
@@ -459,16 +459,19 @@
 ed on an
+%0A *
  %22AS IS%22
@@ -477,20 +477,16 @@
 %22 BASIS,
-%0A * 
  WITHOUT
@@ -517,16 +517,19 @@
 S OF ANY
+%0A *
  KIND, e
@@ -553,19 +553,16 @@
 implied.
-%0A *
   See th
@@ -578,16 +578,19 @@
  for the
+%0A *
  specifi
@@ -625,20 +625,16 @@
 ions and
-%0A * 
  limitat
@@ -637,16 +637,19 @@
 itations
+%0A *
  under t
@@ -869,16 +869,98 @@
 l.Map;%0A%0A
+/**%0A * Test cases for the %7B@link PlaceholderWriter%7D class.%0A *%0A * @since 1.0.0%0A */%0A
 public c
@@ -2715,8 +2715,9 @@
 %0A    %7D%0A%7D
+%0A

fix license & javadoc in PlaceholderWriterTest test class