use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class StringBooleanVariableHelperTest method rendersInverseBlock_whenStringVariableOfGivenNameIsTrue.
@Test
public void rendersInverseBlock_whenStringVariableOfGivenNameIsTrue() throws IOException {
// given
final Options options = OptionsStub.with(buffer, Data.of(variableName, "true"));
// when
final Options.Buffer actualBuffer = helper.apply(variableName, options);
// then
then(buffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_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 IfRequiredHelperTest method rendersInverseBlock_whenParentObjectDoesNotRequireCurrentOne.
@Test
public void rendersInverseBlock_whenParentObjectDoesNotRequireCurrentOne() throws IOException {
// given
final Schema<?> schemaWithPropertyRequired = new ObjectSchema();
schemaWithPropertyRequired.required(singletonList("required-object"));
final Schema<?> notRequiredSchema = new ObjectSchema();
schemaWithPropertyRequired.addProperties("not-required-object", notRequiredSchema);
final Options options = OptionsStub.with(buffer, notRequiredSchema, schemaWithPropertyRequired);
// when
final Options.Buffer actualBuffer = ifRequiredHelper.apply(notRequiredSchema, options);
// then
assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
then(actualBuffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IfRequiredHelperTest method rendersInverseBlock_whenNoParentModel.
@Test
public void rendersInverseBlock_whenNoParentModel() throws IOException {
// given
final Schema<?> currentSchemaModel = new ObjectSchema();
final Options options = OptionsStub.with(buffer, currentSchemaModel);
// when
final Options.Buffer actualBuffer = ifRequiredHelper.apply(currentSchemaModel, options);
// then
assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
then(actualBuffer).should().append(TEMPLATE_CONTENT_FROM_INVERSE_BLOCK);
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IfRequiredHelperTest method rendersMainBlock_whenParentObjectRequiresCurrentOne.
@Test
public void rendersMainBlock_whenParentObjectRequiresCurrentOne() throws IOException {
// given
final Schema<?> schemaWithPropertyRequired = new ObjectSchema();
schemaWithPropertyRequired.required(singletonList("required-object"));
final Schema<?> requiredSchema = new ObjectSchema();
schemaWithPropertyRequired.addProperties("required-object", requiredSchema);
final Options options = OptionsStub.with(buffer, requiredSchema, schemaWithPropertyRequired);
// when
final Options.Buffer actualBuffer = ifRequiredHelper.apply(requiredSchema, options);
// then
assertThat("Returns buffer provided by Handlebars through Options.", actualBuffer, sameInstance(actualBuffer));
then(actualBuffer).should().append(TEMPLATE_CONTENT_FROM_MAIN_BLOCK);
}
use of com.github.jknack.handlebars.Options in project hippo by NHS-digital-website.
the class IfRequiredHelperTest method throwsException_onAnyFailure.
@Test
public void throwsException_onAnyFailure() throws IOException {
// given
final RuntimeException expectedCause = new RuntimeException();
given(buffer.append(any())).willThrow(expectedCause);
expectedException.expect(RuntimeException.class);
expectedException.expectMessage("Failed to render 'required' status.");
expectedException.expectCause(sameInstance(expectedCause));
final Schema<?> irrelevantModel = new ObjectSchema();
final Options options = OptionsStub.with(buffer, irrelevantModel);
// when
ifRequiredHelper.apply(irrelevantModel, options);
// then
// expectations in 'given' are satisfied
}
Aggregations