Search in sources :

Example 1 with DetachableSoyValueProvider

use of com.google.template.soy.jbcsrc.runtime.DetachableSoyValueProvider in project closure-templates by google.

the class SoySauceTest method testExceptionRewriting.

@Test
public void testExceptionRewriting() {
    SoySauce.Renderer tmpl = sauce.renderTemplate("strict_test.callsItself");
    SoyValueProvider intProvider = new DetachableSoyValueProvider() {

        @Override
        protected RenderResult doResolve() {
            resolvedValue = IntegerData.ZERO;
            return RenderResult.done();
        }
    };
    try {
        tmpl.setData(ImmutableMap.of("depth", 10, "p", intProvider)).render();
        fail();
    } catch (ClassCastException cce) {
        // we get an CCE because we passed an int but it expected a string
        StackTraceElement[] stackTrace = cce.getStackTrace();
        assertThat(stackTrace[0].toString()).isEqualTo("strict_test.callsItself.render(strict.soy:32)");
        for (int i = 1; i < 11; i++) {
            assertThat(stackTrace[i].toString()).isEqualTo("strict_test.callsItself.render(strict.soy:34)");
        }
    }
}
Also used : DetachableSoyValueProvider(com.google.template.soy.jbcsrc.runtime.DetachableSoyValueProvider) SoyValueProvider(com.google.template.soy.data.SoyValueProvider) DetachableSoyValueProvider(com.google.template.soy.jbcsrc.runtime.DetachableSoyValueProvider) Test(org.junit.Test)

Aggregations

SoyValueProvider (com.google.template.soy.data.SoyValueProvider)1 DetachableSoyValueProvider (com.google.template.soy.jbcsrc.runtime.DetachableSoyValueProvider)1 Test (org.junit.Test)1