Search in sources :

Example 16 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class TypeAnyHelperTest method rendersMainBlock_forArrayOfJsonObjects.

@Test
public void rendersMainBlock_forArrayOfJsonObjects() throws IOException {
    // given
    final ArrayNode arrayWithJsonObject = new ArrayNode(jsonFactory).add(new ObjectNode(jsonFactory));
    // when
    final Options.Buffer actualBuffer = helper.apply(arrayWithJsonObject, options);
    // then
    then(actualBuffer).should().append(OptionsStub.TEMPLATE_CONTENT_FROM_MAIN_BLOCK);
    assertThat("Returns buffer provided by Handlebars through Options.", buffer, sameInstance(actualBuffer));
}
Also used : Options(com.github.jknack.handlebars.Options) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) ArrayNode(com.fasterxml.jackson.databind.node.ArrayNode) Test(org.junit.Test)

Example 17 with Options

use of com.github.jknack.handlebars.Options in project ddf by codice.

the class TestDescriptionTemplateHelper method testThumbnailHasThumbnail.

@Test
public void testThumbnailHasThumbnail() throws IOException {
    String ifOption = "if";
    String elseOption = "else";
    MetacardImpl metacard = new MetacardImpl();
    metacard.setThumbnail(new byte[] { 1, 2, 3 });
    Options mockOptions = mock(Options.class);
    when(mockOptions.fn()).thenReturn(ifOption);
    when(mockOptions.inverse()).thenReturn(elseOption);
    String result = helper.hasThumbnail(metacard, mockOptions).toString();
    assertEquals(ifOption, result);
}
Also used : Options(com.github.jknack.handlebars.Options) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 18 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class HeadingsHyperlinksFromMarkdownHelperTest method throwsException_onRenderingFailure.

@Test
public void throwsException_onRenderingFailure() {
    // given
    final Options options = mock(Options.class);
    final RuntimeException expectedCause = new RuntimeException();
    given(options.buffer()).willThrow(expectedCause);
    final String irrelevantMarkdown = "Irrelevant `Markdown`.";
    // when
    final ThrowingRunnable action = () -> helper.apply(irrelevantMarkdown, options);
    // then
    final TemplateRenderingException actualException = assertThrows(TemplateRenderingException.class, action);
    assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to render hyperlinks for headings from Markdown " + irrelevantMarkdown + "."));
    assertThat("Cause exception is included.", actualException.getCause(), sameInstance(expectedCause));
}
Also used : Options(com.github.jknack.handlebars.Options) ThrowingRunnable(org.junit.function.ThrowingRunnable) Test(org.junit.Test)

Example 19 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class IsAnyTrueHelperTest method throwExceptionWhenAtLeastOneIsNonBoolean.

@Test
public void throwExceptionWhenAtLeastOneIsNonBoolean() {
    final Object[] params = { false, "test" };
    final Options options = OptionsStub.with(params, buffer);
    try {
        // when
        isAnyTrueHelper.apply(item, options);
        fail("An exception was expected but none was thrown.");
    } catch (Exception e) {
        // then
        assertThat("Exception in execution", e.getMessage(), containsString("All parameters are required to be boolean but at least one provided value was not."));
    }
}
Also used : Options(com.github.jknack.handlebars.Options) IOException(java.io.IOException) Test(org.junit.Test)

Example 20 with Options

use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.

the class IsAnyTrueHelperTest method rendersBlockWhenCollectionHasNoTrueItem.

@Test
public void rendersBlockWhenCollectionHasNoTrueItem() throws IOException {
    final Boolean[] params = { false, false, false, false, false };
    final Options options = OptionsStub.with(params, buffer);
    // when
    final Options.Buffer actualBuffer = (Options.Buffer) isAnyTrueHelper.apply(item, options);
    // then
    assertThat("Returns Options.Buffer", buffer, sameInstance(actualBuffer));
    then(actualBuffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
}
Also used : Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Aggregations

Options (com.github.jknack.handlebars.Options)36 Test (org.junit.Test)35 Context (com.github.jknack.handlebars.Context)8 ObjectSchema (io.swagger.v3.oas.models.media.ObjectSchema)5 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)4 IOException (java.io.IOException)4 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)3 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)3 ArraySchema (io.swagger.v3.oas.models.media.ArraySchema)3 ComposedSchema (io.swagger.v3.oas.models.media.ComposedSchema)3 Schema (io.swagger.v3.oas.models.media.Schema)3 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)2 Metacard (ddf.catalog.data.Metacard)2 ThrowingRunnable (org.junit.function.ThrowingRunnable)2 UncheckedIOException (java.io.UncheckedIOException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 Hash (uk.nhs.digital.common.components.apispecification.handlebars.OptionsStub.Hash)1 RandomTestUtils.randomString (uk.nhs.digital.test.util.RandomTestUtils.randomString)1