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));
}
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);
}
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));
}
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."));
}
}
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);
}
Aggregations