package net.masterthought.cucumber.generators;

import org.apache.velocity.app.event.ReferenceInsertionEventHandler;
import org.junit.Test;

import static org.apache.commons.lang.StringEscapeUtils.escapeHtml;
import static org.assertj.core.api.Assertions.assertThat;

/**
 * @author M.P. Korstanje (mpkorstanje@github)
 */
public class EscapeHtmlReferenceTest {

    private static final String SOME_REFERENCE = "someReference";
    private final ReferenceInsertionEventHandler insertionEventHandler = new EscapeHtmlReference();

    @Test
    public void referenceInsert_returnNormalText(){
        String normalText = "a plain statement";
        assertThat(insertionEventHandler.referenceInsert(SOME_REFERENCE, normalText)).isEqualTo(normalText);
    }

    @Test
    public void referenceInsert_shouldEscapeHtmlForAnyLabel(){
        String html = "<b>a bold statement</b>";
        assertThat(insertionEventHandler.referenceInsert(SOME_REFERENCE, html)).isEqualTo(escapeHtml(html));
    }

    @Test
    public void referenceInsert_shouldReturnNullForNull(){
        assertThat(insertionEventHandler.referenceInsert(SOME_REFERENCE, null)).isNull();
    }

}

@@ -1154,10 +1154,322 @@
 %0A    %7D%0A%0A
+    @Test%0A    public void referenceInsert_shouldSanitize()%7B%0A        String html = %22%3Ca href=%5C%22www.example.com%5C%22 rel=%5C%22nofollow noopener noreferrer%5C%22%3Ea hyper web reference%3C/a%3E%22;%0A        assertThat(insertionEventHandler.referenceInsert(%22$_sanitize_%22 + SOME_REFERENCE, html))%0A                .isEqualTo(html);%0A    %7D%0A
 %7D%0A

Add additional unit test