use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IndentationHelperTest method returnsWeightedIndentationLevel_whenWeightingSet.
@Test
public void returnsWeightedIndentationLevel_whenWeightingSet() {
// given
final int ancestorCount = RandomUtils.nextInt();
final double weighting = 1.5;
final String expectedIndentationLevel = String.format("%.1f", ancestorCount * weighting);
final Context context = Context.newContext(new Object());
final ContextModelsStack contextModelsStack = mock(ContextModelsStack.class);
given(contextModelsStack.ancestorModelsCount()).willReturn(ancestorCount);
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
final IndentationHelper indentationHelper = IndentationHelper.with(contextStackFactory);
final Hash hash = Hash.of("weighting", weighting);
final Options options = OptionsStub.with(context, hash);
// when
final String actualIndentationLevel = indentationHelper.apply(null, options);
// then
assertThat("Total number of ancestor Contexts is returned.", actualIndentationLevel, is(expectedIndentationLevel));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class MarkdownHelperTest method throwsException_onMarkdownRenderingFailure.
@Test
public void throwsException_onMarkdownRenderingFailure() {
// given
final RuntimeException expectedCause = new RuntimeException();
given(commonmarkMarkdownConverter.toHtml(any(), any(), any(Integer.class))).willThrow(expectedCause);
final Options options = OptionsStub.empty();
final String markdown = "some markdown";
// when
final ThrowingRunnable action = () -> markdownHelper.apply(markdown, options);
// then
final RuntimeException actualException = assertThrows(RuntimeException.class, action);
assertThat("Exception message provides failure's details.", actualException.getMessage(), is("Failed to render Markdown: " + markdown));
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 StringBooleanVariableHelperTest method rendersMainBlock_whenStringVariableOfGivenNameIsFalse.
@Test
public void rendersMainBlock_whenStringVariableOfGivenNameIsFalse() throws IOException {
// given
final Options options = OptionsStub.with(buffer, Data.of(variableName, "false"));
// when
final Options.Buffer actualBuffer = helper.apply(variableName, options);
// then
then(buffer).should().append(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 hippo by NHS-digital-website.
the class StringBooleanVariableHelperTest method rendersMainBlock_whenStringVariableOfGivenNameIsEmptyString.
@Test
public void rendersMainBlock_whenStringVariableOfGivenNameIsEmptyString() throws IOException {
// given
final Options options = OptionsStub.with(buffer, Data.of(variableName, ""));
// when
final Options.Buffer actualBuffer = helper.apply(variableName, options);
// then
then(buffer).should().append(TEMPLATE_CONTENT_FROM_MAIN_BLOCK);
assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class StringBooleanVariableHelperTest method throwsException_onSchemaRenderingFailure.
@Test
public void throwsException_onSchemaRenderingFailure() throws IOException {
// given
final RuntimeException expectedCauseException = new RuntimeException();
given(buffer.append(any())).willThrow(expectedCauseException);
final Options options = OptionsStub.with(buffer, Data.of(variableName, "irrelevant value"));
expectedException.expectMessage("Failed to interpret value of variable " + variableName + ".");
expectedException.expect(TemplateRenderingException.class);
expectedException.expectCause(sameInstance(expectedCauseException));
// when
helper.apply(variableName, options);
// then
// expectations set up in 'given' are satisfied
}
Aggregations