Skip to content

Commit 5a2f976

Browse files
committed
Improved Templates test
1 parent 2d73ab2 commit 5a2f976

File tree

3 files changed

+11
-5
lines changed

3 files changed

+11
-5
lines changed

src/com/googlecode/totallylazy/template/Templates.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ public Templates logger(Appendable logger) {
9090
try {
9191
return missing.apply(s, r);
9292
} catch (Exception e) {
93-
logger.append(format("Unable to load template '%s' because: %s", s, e.getMessage()));
93+
logger.append(format("Unable to load template '%s' because: %s%n", s, e.getMessage()));
9494
return (instance, appendable) -> appendable;
9595
}
9696
});

test/com/googlecode/totallylazy/template/TemplatesTest.java

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
11
package com.googlecode.totallylazy.template;
22

33
import com.googlecode.totallylazy.Strings;
4+
import com.googlecode.totallylazy.predicates.Predicates;
45
import org.junit.Test;
56

67
import java.io.PrintWriter;
78

89
import static com.googlecode.totallylazy.Assert.assertThat;
910
import static com.googlecode.totallylazy.Maps.map;
11+
import static com.googlecode.totallylazy.Strings.contains;
1012
import static com.googlecode.totallylazy.Strings.startsWith;
1113
import static com.googlecode.totallylazy.predicates.Predicates.contains;
1214
import static com.googlecode.totallylazy.predicates.Predicates.instanceOf;
1315
import static com.googlecode.totallylazy.predicates.Predicates.is;
16+
import static com.googlecode.totallylazy.predicates.Predicates.not;
1417
import static com.googlecode.totallylazy.template.Templates.templates;
1518

1619
public class TemplatesTest {
@@ -57,10 +60,12 @@ public void canUseTemplatesFromClassPathAndDefaultTemplates() throws Exception {
5760

5861
@Test
5962
public void doesNotThrowWhenASubTemplateIsNotFoundButReturnsEmptyStringAndLogs() throws Exception {
60-
StringBuilder log = new StringBuilder();
61-
Templates templates = templates(getClass()).logger(log).extension("st");
63+
StringBuilder builder = new StringBuilder();
64+
Templates templates = templates(getClass()).logger(builder).extension("st").add("works", ignore -> "Other templates still work");
6265
String result = templates.get("error").render(map());
63-
assertThat(result, is("Sub template returned ''"));
64-
assertThat(log.toString(), startsWith("Unable to load template 'foo.st' because: "));
66+
assertThat(result, is("Other templates still work\nSub template returned ''"));
67+
String log = builder.toString();
68+
assertThat(log, startsWith("Unable to load template 'foo.st' because: "));
69+
assertThat(log, not(contains("Unable to load template 'works' because: ")));
6570
}
6671
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1+
$works()$
12
Sub template returned '$foo()$'

0 commit comments

Comments
 (0)