use of com.google.template.soy.tofu.SoyTofuException in project closure-templates by google.
the class TofuExceptionsTest method testExceptions_wrongTypeFuture.
@Test
public void testExceptions_wrongTypeFuture() {
SoyDict data = SoyValueConverterUtility.newDict("foo", Futures.immediateFuture("not a record"));
// This error occurs due to data of the wrong type, hidden behind a future.
try {
tofu.newRenderer("ns.callerTemplate").setData(data).render();
fail();
} catch (SoyTofuException ste) {
assertThat(ste).hasCauseThat().isNull();
assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$foo.boo\": Parameter type mismatch: attempt to bind value " + "'not a record' (a StringData) to parameter 'foo' which has a declared type " + "of '[bad: string, boo: int]'.");
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:8)");
assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.calleeTemplate(no-path:10)");
assertThat(ste.getStackTrace()[2].toString()).isEqualTo("ns.callerTemplate(no-path:5)");
}
}
use of com.google.template.soy.tofu.SoyTofuException in project closure-templates by google.
the class TofuExceptionsTest method testExceptions_failedFuture.
@Test
public void testExceptions_failedFuture() {
Exception futureFailureCause = new Exception("boom");
SoyDict data = SoyValueConverterUtility.newDict("foo", immediateFailedFuture(futureFailureCause));
// This error occurs due to a failed future.
try {
tofu.newRenderer("ns.callerTemplate").setData(data).render();
fail();
} catch (SoyTofuException ste) {
assertThat(ste).hasMessageThat().isEqualTo("When evaluating \"$foo.boo\": Error dereferencing future");
SoyFutureException sfe = (SoyFutureException) ste.getCause();
assertThat(sfe).hasMessageThat().isEqualTo("Error dereferencing future");
assertThat(sfe).hasCauseThat().isEqualTo(futureFailureCause);
assertThat(ste.getStackTrace()[0].toString()).isEqualTo("ns.calleeTemplate(no-path:10)");
assertThat(ste.getStackTrace()[1].toString()).isEqualTo("ns.callerTemplate(no-path:5)");
}
}
Aggregations