use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class QueryEagerTest method testEagerFind.
public void testEagerFind() {
Student s1 = DataSupport.find(Student.class, student1.getId(), true);
Classroom c = s1.getClassroom();
IdCard ic = s1.getIdcard();
List<Teacher> tList = s1.getTeachers();
assertNotNull(c);
assertNotNull(ic);
assertEquals(classroom.get_id(), c.get_id());
assertEquals("Classroom 11", c.getName());
assertEquals(idcard1.getId(), ic.getId());
assertEquals("320311", ic.getNumber());
assertEquals(student1.getTeachers().size(), tList.size());
Calendar calendar = Calendar.getInstance();
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s1.getBirthday().getTime());
for (Teacher t : tList) {
if (t.getId() == teacher1.getId()) {
assertEquals("Teacher 1", t.getTeacherName());
assertEquals(teacher1.getTeachYears(), t.getTeachYears());
assertTrue(t.isSex());
continue;
}
if (t.getId() == teacher2.getId()) {
assertEquals("Teacher 2", t.getTeacherName());
assertFalse(t.isSex());
continue;
}
fail();
}
s1 = DataSupport.find(Student.class, student1.getId());
c = s1.getClassroom();
assertNull(c);
assertNull(s1.getIdcard());
assertEquals(0, s1.getTeachers().size());
c = DataSupport.find(Classroom.class, classroom.get_id(), true);
assertEquals(2, c.getStudentCollection().size());
assertEquals(1, c.getTeachers().size());
for (Student s : c.getStudentCollection()) {
if (s.getId() == student1.getId()) {
assertEquals("Student 1", s.getName());
continue;
}
if (s.getId() == student2.getId()) {
assertEquals("Student 2", s.getName());
calendar.clear();
calendar.set(1989, 7, 7, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s.getBirthday().getTime());
continue;
}
fail();
}
Teacher t1 = DataSupport.find(Teacher.class, teacher2.getId(), true);
List<Student> sList = t1.getStudents();
assertEquals(teacher2.getStudents().size(), sList.size());
for (Student s : sList) {
if (s.getId() == student1.getId()) {
assertEquals("Student 1", s.getName());
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
assertEquals(calendar.getTime().getTime(), s.getBirthday().getTime());
continue;
}
if (s.getId() == student2.getId()) {
assertEquals("Student 2", s.getName());
continue;
}
fail();
}
Student s3 = DataSupport.find(Student.class, student3.getId());
assertNull(s3.getBirthday());
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class Many2OneUniSaveTest method init.
public void init() {
c1 = new Classroom();
c1.setName("Music room");
t1 = new Teacher();
t1.setTeacherName("John");
t1.setAge(25);
t2 = new Teacher();
t2.setTeacherName("Sean");
t2.setAge(35);
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateToDefaultValueWithInstanceUpdateButWrongField.
public void testUpdateToDefaultValueWithInstanceUpdateButWrongField() {
try {
Teacher t = new Teacher();
t.setToDefault("name");
t.update(t.getId());
fail();
} catch (DataSupportException e) {
assertEquals("The name field in com.litepaltest.model.Teacher class is necessary which does not exist.", e.getMessage());
}
}
Aggregations