/*
 * Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
 *
 * WSO2 Inc. licenses this file to you 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.helpers.init;

import com.github.jknack.handlebars.HandlebarsException;
import org.testng.Assert;
import org.testng.annotations.Test;
import org.wso2.carbon.uuf.renderablecreator.hbs.exception.HbsRenderableCreationException;

import java.util.Optional;

import static org.wso2.carbon.uuf.renderablecreator.hbs.helpers.init.InitHelpersTestUtil.createHbsPagePreprocessor;

/**
 * Test cases for {@code {{layout}}} helper.
 *
 * @since 1.0.0
 */
public class LayoutHelperTest {

    @Test
    public void test() {
        String pageTemplateContent = "foo\nbar\n{{layout \"test-layout\"}}bla bla\nfoobar";
        Optional<String> layoutName = createHbsPagePreprocessor(pageTemplateContent).getLayoutName();

        Assert.assertEquals(layoutName.orElse(null), "test-layout");
    }

    @Test
    public void testSettingMultiple() {
        String pageTemplateContent = "foo\nbar\n{{layout \"layout-1\"}}bla bla\n{{layout \"layout-2\"}}\nfoobar";
        try {
            Optional<String> layoutName = createHbsPagePreprocessor(pageTemplateContent).getLayoutName();
            Assert.fail("{{layout}} helper can be called twice in a page!");
        } catch (HandlebarsException e) {
            Assert.assertTrue((e.getCause() instanceof HbsRenderableCreationException),
                              "Cause of the thrown exception should be '" + HbsRenderableCreationException.class +
                                      "'. Instead found '" + e.getCause().getClass() + "'.");
        }
    }
}

@@ -734,65 +734,8 @@
 t;%0A%0A
-import com.github.jknack.handlebars.HandlebarsException;%0A
 impo
@@ -1616,545 +1616,120 @@
     
-try %7B%0A            Optional%3CString%3E layoutName = createHbsPagePreprocessor(pageTemplateContent).getLayoutName();%0A            Assert.fail(%22%7B%7Blayout%7D%7D helper can be called twice in a page!%22);%0A        %7D catch (HandlebarsException e) %7B%0A            Assert.assertTrue((e.getCause() instanceof HbsRenderableCreationException),%0A                              %22Cause of the thrown exception should be '%22 + HbsRenderableCreationException.class +%0A                                      %22'. Instead found '%22 + e.getCause().getClass() + %22'.%22);%0A        %7D
+Assert.assertThrows(HbsRenderableCreationException.class, () -%3E createHbsPagePreprocessor(pageTemplateContent));
 %0A   

fix LayoutHelperTest for multiple layouts test case