use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateToDefaultValueWithInstanceUpdate.
public void testUpdateToDefaultValueWithInstanceUpdate() {
Student s = new Student();
s.setToDefault("age");
s.setToDefault("name");
s.setToDefault("birthday");
int affectedStudent = s.update(student.getId());
assertEquals(1, affectedStudent);
Student newStudent = DataSupport.find(Student.class, student.getId());
assertNull(newStudent.getBirthday());
assertEquals(null, newStudent.getName());
assertEquals(0, newStudent.getAge());
Teacher t = new Teacher();
t.setAge(45);
t.setTeachYears(5);
t.setTeacherName("John");
t.setToDefault("teacherName");
t.setToDefault("age");
int affectedTeacher = t.update(teacher.getId());
assertEquals(1, affectedTeacher);
Teacher newTeacher = getTeacher(teacher.getId());
assertEquals(22, newTeacher.getAge());
assertEquals("", newTeacher.getTeacherName());
assertEquals(5, newTeacher.getTeachYears());
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingSaveMethodTest method init.
private void init() {
Calendar calendar = Calendar.getInstance();
c1 = new Classroom();
c1.setName("Working room");
c2 = new Classroom();
c2.setName("Resting room");
s1 = new Student();
s1.setName("Parker");
s1.setAge(18);
s2 = new Student();
s2.setName("Peter");
calendar.clear();
calendar.set(1990, 9, 16, 0, 0, 0);
s2.setBirthday(calendar.getTime());
s2.setAge(19);
s3 = new Student();
s3.setName("Miley");
s3.setAge(16);
id1 = new IdCard();
id1.setNumber("999777123");
id1.setAddress("Zhushan road");
t1 = new Teacher();
t1.setTeacherName("Jackson");
t1.setTeachYears(3);
t1.setAge(28);
t2 = new Teacher();
t2.setTeacherName("Rose");
t2.setTeachYears(12);
t2.setAge(34);
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateAllToDefaultValueWithInstanceUpdateButWrongField.
public void testUpdateAllToDefaultValueWithInstanceUpdateButWrongField() {
try {
Teacher t = new Teacher();
t.setToDefault("name");
t.updateAll("");
fail();
} catch (DataSupportException e) {
assertEquals("The name field in com.litepaltest.model.Teacher class is necessary which does not exist.", e.getMessage());
}
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method testUpdateWithInstanceUpdateButNotExistsRecord.
public void testUpdateWithInstanceUpdateButNotExistsRecord() {
Teacher t = new Teacher();
t.setTeacherName("Johnny");
int rowsAffected = t.update(189876465);
assertEquals(0, rowsAffected);
}
use of com.litepaltest.model.Teacher in project LitePal by LitePalFramework.
the class UpdateUsingUpdateMethodTest method init.
private void init() {
classroom = new Classroom();
classroom.setName("English room");
classroom.getNews().add("hello");
classroom.getNews().add("world");
classroom.getNumbers().add(123);
classroom.getNumbers().add(456);
teacher = new Teacher();
teacher.setTeacherName("Tony");
teacher.setTeachYears(3);
teacher.setAge(23);
teacher.setSex(false);
student = new Student();
student.setName("Jonny");
student.setAge(13);
student.setClassroom(classroom);
student.setBirthday(new Date());
student.getTeachers().add(teacher);
teacher.getStudents().add(student);
student.save();
teacher.save();
classroom.save();
}
Aggregations