Skip to content

Commit 1edc486

Browse files
committed
#756 FreemarkerSpec's test fix attempt
1 parent c0a67a5 commit 1edc486

File tree

2 files changed

+21
-18
lines changed

2 files changed

+21
-18
lines changed

activejdbc/src/test/java/org/javalite/activejdbc/FreemarkerSpec.java

Lines changed: 14 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import freemarker.template.TemplateException;
77
import org.javalite.activejdbc.test.ActiveJDBCTest;
88
import org.javalite.activejdbc.test_models.Person;
9+
import org.javalite.activejdbc.test_models.Student;
910
import org.junit.Before;
1011
import org.junit.Test;
1112

@@ -33,7 +34,7 @@ public void beforeTest(){
3334

3435

3536
@Test
36-
public void shouldRenderSingleIntance() throws IOException, TemplateException {
37+
public void shouldRenderSingleInstance() throws IOException, TemplateException {
3738
deleteAndPopulateTable("people");
3839

3940
Person smith = Person.findFirst("last_name = ?", "Smith");
@@ -75,39 +76,34 @@ public void shouldRenderList() throws IOException, TemplateException {
7576

7677
@Test
7778
public void shouldRenderRowProcessor() throws IOException, TemplateException {
78-
deleteAndPopulateTable("people");
79+
deleteAndPopulateTable("students");
7980

80-
Person smith = Person.findFirst("last_name = ?", "Smith");
81-
smith.set("graduation_date", null).saveIt();
81+
Student cary = Student.findFirst("last_name = ?", "Cary");
82+
cary.set("enrollment_date", null).saveIt();
8283

83-
List<Map> people = new ArrayList<>();
84-
Base.find("select * from people order by id").with(new RowListenerAdapter() {
84+
List<Map> students = new ArrayList<>();
85+
Base.find("select * from students order by id").with(new RowListenerAdapter() {
8586
@Override
8687
public void onNext(Map<String, Object> row) {
87-
people.add(row);
88+
students.add(row);
8889
}
8990
});
9091

91-
92-
Template template = config.getTemplate("src/test/resources/list.ftl");
92+
Template template = config.getTemplate("src/test/resources/list_row.ftl");
9393

9494
StringWriter writer = new StringWriter();
95-
template.process(map("people", people), writer);
95+
template.process(map("students", students), writer);
9696
String processedTemplate = writer.toString().trim();
9797
if(System.getProperty("os.name").contains("indows")) {
9898
processedTemplate = processedTemplate.replaceAll("\r\n", "\n");
9999
}
100100

101101
if(driver().equals("org.sqlite.JDBC")){
102-
the(processedTemplate).shouldBeEqual("Person: John Smith, graduation date: \n" +
103-
"Person: Leylah Jonston, graduation date: 1974-04-03\n" +
104-
"Person: Muhammad Ali, graduation date: 1963-01-04\n" +
105-
"Person: Joe Pesci, graduation date: 1964-02-23");
102+
the(processedTemplate).shouldBeEqual("Student: Jim Cary, enrollment date:\n" +
103+
"Student: John Carpenter, enrollment date: 1987-01-29 13:00:00");
106104
}else {
107-
the(processedTemplate).shouldBeEqual("Person: John Smith, graduation date: \n" +
108-
"Person: Leylah Jonston, graduation date: Apr 3, 1974\n" +
109-
"Person: Muhammad Ali, graduation date: Jan 4, 1963\n" +
110-
"Person: Joe Pesci, graduation date: Feb 23, 1964");
105+
the(processedTemplate).shouldBeEqual("Student: Jim Cary, enrollment date:\n" +
106+
"Student: John Carpenter, enrollment date: Jan 29, 1987 1:00:00 PM");
111107
}
112108
}
113109
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<#list students as student>
2+
<#if student.enrollment_date??>
3+
Student: ${student.first_name} ${student.last_name}, enrollment date: ${student.enrollment_date}
4+
<#else>
5+
Student: ${student.first_name} ${student.last_name}, enrollment date:
6+
</#if>
7+
</#list>

0 commit comments

Comments
 (0)