Search in sources :

Example 11 with Teacher

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());
}
Also used : Teacher(com.litepaltest.model.Teacher) Student(com.litepaltest.model.Student)

Example 12 with Teacher

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);
}
Also used : Calendar(java.util.Calendar) Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher) IdCard(com.litepaltest.model.IdCard) Student(com.litepaltest.model.Student)

Example 13 with Teacher

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());
    }
}
Also used : DataSupportException(org.litepal.exceptions.DataSupportException) Teacher(com.litepaltest.model.Teacher)

Example 14 with Teacher

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);
}
Also used : Teacher(com.litepaltest.model.Teacher)

Example 15 with Teacher

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();
}
Also used : Classroom(com.litepaltest.model.Classroom) Teacher(com.litepaltest.model.Teacher) Student(com.litepaltest.model.Student) Date(java.util.Date)

Aggregations

Teacher (com.litepaltest.model.Teacher)23 Student (com.litepaltest.model.Student)11 Classroom (com.litepaltest.model.Classroom)7 IdCard (com.litepaltest.model.IdCard)7 Cursor (android.database.Cursor)3 Calendar (java.util.Calendar)3 ArrayList (java.util.ArrayList)2 DataSupportException (org.litepal.exceptions.DataSupportException)2 Cellphone (com.litepaltest.model.Cellphone)1 Date (java.util.Date)1 Random (java.util.Random)1