public void testInvalidDelimiters() { try { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{=toolong}}"), "testInvalidDelimiters"); fail("Not invalid"); } catch (MustacheException e) { // Success } }
public void testLimitedDepthRecursion() { try { StringWriter sw = execute("infiniteparent.html", new Context()); fail("Should have failed"); } catch (StackOverflowError soe) { fail("Should not have overflowed the stack"); } catch (MustacheException e) { assertEquals("Maximum partial recursion limit reached: 100 @[infiniteparent.html:1]", e.getMessage()); } }
public void testRelativePathFail() throws IOException { MustacheFactory mf = createMustacheFactory(); try { Mustache compile = mf.compile("relative/pathfail.html"); fail("Should have failed to compile"); } catch (MustacheException e) { // Success } }
public void testMismatch() { try { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#value}}"), "testMismatch"); fail("Not mismatched"); } catch (MustacheException e) { // Success try { MustacheFactory mf = createMustacheFactory(); Mustache m = mf.compile(new StringReader("{{#value}}{{/values}}"), "testMismatch"); fail("Not mismatched"); } catch (MustacheException e2) { // Success } } }
public void testRootCheck() throws MustacheException, IOException, ExecutionException, InterruptedException { MustacheFactory c = createMustacheFactory(); try { Mustache m = c.compile("../../../pom.xml"); fail("Should have failed to compile"); } catch (MustacheException e) { // Success } }
public void testEmptyMustache() { try { new DefaultMustacheFactory().compile(new StringReader("{{}}"), "test"); fail("Didn't throw an exception"); } catch (MustacheException e) { assertTrue(e.getMessage().startsWith("Empty mustache")); } }
public void testBrokenSimple() throws MustacheException, IOException, ExecutionException, InterruptedException { try { MustacheFactory c = createMustacheFactory(); Mustache m = c.compile("brokensimple.html"); StringWriter sw = new StringWriter(); m.execute(sw, new Object() { String name = "Chris"; int value = 10000; int taxed_value() { return (int) (this.value - (this.value * 0.4)); } boolean in_ca = true; }); fail("Should have failed: " + sw.toString()); } catch (Exception e) { // success } }
public void testClosingReader() { final AtomicBoolean closed = new AtomicBoolean(); StringReader reader = new StringReader("{{test") { @Override public void close() { closed.set(true); } }; MustacheFactory mf = new DefaultMustacheFactory(); try { mf.compile(reader, "test"); fail("Should have thrown an exception"); } catch (MustacheException me) { // The reader should be closed now assertEquals(true, closed.get()); } }
public void testImproperlyClosedVariable() throws IOException { try { new DefaultMustacheFactory().compile(new StringReader("{{{#containers}} {{/containers}}"), "example"); fail("Should have throw MustacheException"); } catch (MustacheException actual) { assertEquals("Improperly closed variable in example:1 @[example:1]", actual.getMessage()); } }
public void testMalformedTag() { try { String template = "\n{{$value}}\n{/value}}"; Mustache mustache = new DefaultMustacheFactory().compile(new StringReader(template), "test"); StringWriter sw = new StringWriter(); mustache.execute(sw, new Object[0]); fail("Should have failed to compile"); } catch (MustacheException e) { assertEquals("Failed to close 'value' tag @[test:2]", e.getMessage()); } }
public void testMustacheNotFoundException() { String nonExistingMustache = "404"; try { new DefaultMustacheFactory().compile(nonExistingMustache); fail("Didn't throw an exception"); } catch (MustacheNotFoundException e) { assertEquals(nonExistingMustache, e.getName()); } }
m.execute(sw, new Object() { }); fail("Should throw an exception"); } catch (MustacheException e) {
public void testAccessTracker() throws IOException { { Map<String, String> accessTrackingMap = createBaseMap(); DefaultMustacheFactory mf = createMustacheFactory(); Mustache test = mf.compile(new StringReader("{{first}} {{last}}"), "test"); StringWriter sw = new StringWriter(); test.execute(sw, accessTrackingMap).close(); assertEquals("Sam Pullara", sw.toString()); } { AccessTrackingMap accessTrackingMap = createBaseMap(); accessTrackingMap.put("notused", "shouldcauseanerror"); DefaultMustacheFactory mf = createMustacheFactory(); Mustache test = mf.compile(new StringReader("{{first}} {{last}}"), "test"); StringWriter sw = new StringWriter(); test.execute(sw, accessTrackingMap).close(); assertEquals("Sam Pullara", sw.toString()); try { accessTrackingMap.check(); fail("Should have thrown an exception"); } catch (MustacheException me) { // Succcess } } }