import java.io.File;
import java.io.FileInputStream;
-import java.io.FileNotFoundException;
+import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import net.pterodactylus.util.template.TemplateException;
import net.pterodactylus.util.template.TemplateParser;
-import freenet.support.io.Closer;
-
import com.google.common.base.Charsets;
/**
private void loadTemplate() {
File templateFile = new File(filename);
- if (!templateFile.exists()) {
- throw new TemplateFileNotFoundException(filename);
- }
if (templateWasLoaded() && !templateFileHasBeenModifiedAfterLoading(templateFile)) {
return;
}
- InputStream templateInputStream = null;
- Reader templateReader = null;
- try {
- templateInputStream = new FileInputStream(templateFile);
- templateReader = new InputStreamReader(templateInputStream, Charsets.UTF_8);
+ try (InputStream templateInputStream = new FileInputStream(templateFile);
+ Reader templateReader = new InputStreamReader(templateInputStream, Charsets.UTF_8)) {
Template template = TemplateParser.parse(templateReader);
lastTemplate.set(new LastLoadedTemplate(template));
template.getInitialContext().mergeContext(initialContext);
for (Part part : parts) {
template.add(part);
}
- } catch (FileNotFoundException e) {
+ } catch (IOException e) {
throw new TemplateFileNotFoundException(filename);
- } finally {
- Closer.close(templateReader);
- Closer.close(templateInputStream);
}
}
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
+import static org.hamcrest.Matchers.notNullValue;
import java.io.File;
import java.io.IOException;
assertThat(getRenderedString(), is("New.a1.Test"));
}
+ @Test
+ public void columnOfReturnedTemplateIsReturnedAsZero() {
+ assertThat(filesystemTemplate.getColumn(), is(0));
+ }
+
+ @Test
+ public void lineOfReturnedTemplateIsReturnedAsZero() {
+ assertThat(filesystemTemplate.getLine(), is(0));
+ }
+
+ @Test
+ public void templateCanBeIteratedOver() {
+ assertThat(filesystemTemplate.iterator(), notNullValue());
+ }
+
}