use of com.github.jknack.handlebars.Options in project ddf by codice.
the class TestDescriptionTemplateHelper method testNoThumbnailHasThumbnail.
@Test
public void testNoThumbnailHasThumbnail() throws IOException {
String ifOption = "if";
String elseOption = "else";
Metacard metacard = new MetacardImpl();
Options mockOptions = mock(Options.class);
when(mockOptions.fn()).thenReturn(ifOption);
when(mockOptions.inverse()).thenReturn(elseOption);
String result = helper.hasThumbnail(metacard, mockOptions).toString();
assertEquals(elseOption, result);
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class HeadingsHyperlinksFromMarkdownHelper method render.
private Options.Buffer render(final List<HeadingModel> headingModels, final Options options) {
final Options.Buffer buffer = options.buffer();
headingModels.forEach(headingModel -> {
try {
buffer.append(options.fn(headingModel));
} catch (IOException e) {
throw new UncheckedIOException(e);
}
});
return buffer;
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class BorderHelperTest method doesNotReturnParentBorder_whenElementHasNone.
@Test
public void doesNotReturnParentBorder_whenElementHasNone() {
// given
final Context context = Context.newContext(new Object());
final Schema currentModel = new Schema().properties(ImmutableMap.of("child_1", new Schema()));
final ContextModelsStack contextModelsStack = new ContextModelsStack(asList(currentModel));
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(context)).willReturn(contextModelsStack);
borderHelper = BorderHelper.with(contextStackFactory);
final Options options = OptionsStub.with(context);
// when
final CharSequence expectedBorders = getBorder(SchemaBorder.CHILD, 0);
final CharSequence actualBorders = borderHelper.apply(null, options).toString();
// then
assertThat("Helper returns HTML for child element's border and does not return any other vertical borders", actualBorders, is(expectedBorders));
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IndentationHelperTest method throwsException_onCalculationFailure.
@Test
public void throwsException_onCalculationFailure() {
// given
final RuntimeException expectedCauseException = new RuntimeException();
final ContextModelsStack.Factory contextStackFactory = mock(ContextModelsStack.Factory.class);
given(contextStackFactory.from(any())).willThrow(expectedCauseException);
indentationHelper = IndentationHelper.with(contextStackFactory);
expectedException.expect(TemplateRenderingException.class);
expectedException.expectMessage("Failed to calculate indentation level.");
expectedException.expectCause(sameInstance(expectedCauseException));
final Context irrelevantContext = Context.newContext("irrelevant model");
final Options options = OptionsStub.with(irrelevantContext);
// when
indentationHelper.apply(null, options);
// then
// expectations set in 'given' are satisfied
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IndentationHelperTest method returnsIndentationLevel_equalToNumberOfAllUniqueModelsFromTheContextStack.
@Test
public void returnsIndentationLevel_equalToNumberOfAllUniqueModelsFromTheContextStack() {
// given
final int ancestorCount = RandomUtils.nextInt();
final String expectedIndentationLevel = String.valueOf(ancestorCount);
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 Options options = OptionsStub.with(context);
// when
final String actualIndentationLevel = indentationHelper.apply(null, options);
// then
assertThat("Total number of ancestor Contexts is returned.", actualIndentationLevel, is(expectedIndentationLevel));
}
Aggregations