Search in sources :

Example 11 with Options

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

the class IsAnyTrueHelperTest method throwExceptionWhenAtLeastOneIsNull.

@Test
public void throwExceptionWhenAtLeastOneIsNull() {
    final Boolean[] params = { false, null };
    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 12 with Options

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

the class IsAnyTrueHelperTest method rendersBlockWhenCollectionHasAtLeastOneTrueItem.

@Test
public void rendersBlockWhenCollectionHasAtLeastOneTrueItem() throws IOException {
    final Boolean[] params = { false, false, true, 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_MAIN_BLOCK);
}
Also used : Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Example 13 with Options

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

the class IsAnyTrueHelperTest method throwExceptionWhenCollectionIsEmpty.

@Test
public void throwExceptionWhenCollectionIsEmpty() throws IOException {
    final Boolean[] params = {};
    final Options options = OptionsStub.with(params, buffer);
    try {
        // when
        isAnyTrueHelper.apply(item, options);
        fail("An exception was expected but none was thrown.");
    } catch (IllegalArgumentException e) {
        // then
        assertThat("Exception in execution", e.getMessage(), containsString("At least one parameter is required but none was provided."));
    }
}
Also used : Options(com.github.jknack.handlebars.Options) Test(org.junit.Test)

Example 14 with Options

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

the class TypeAnyHelperTest method rendersInverseBlock_forArrayOfSimpleValues.

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

Example 15 with Options

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

the class TypeAnyHelperTest method rendersEmptyString_whenModelIsNull.

@Test
public void rendersEmptyString_whenModelIsNull() throws IOException {
    // given
    final ObjectNode nullObject = null;
    // when
    final Options.Buffer actualBuffer = helper.apply(nullObject, options);
    // then
    then(actualBuffer).should().append(EMPTY_STRING);
    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) 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