testhomework.java

来自「软件设计课做的一个类似Hibernate的O/R Mapping的框架」· Java 代码 · 共 42 行

JAVA
42
字号
package cn.edu.nju.software.sd.torm.test;

import java.util.Calendar;

import cn.edu.nju.software.sd.torm.test.beans.Homework;

public class TestHomework extends SimpleTestCase {
    public void testLoadHomework() {
        try {
            Homework h = (Homework) manager.load(Homework.class, 1);
            assertTrue("Null value 'finished' expeced to be false", h
                    .getFinished() == false);
            System.out.println("You treat the null value as false");
        } catch (Exception e) {
            assertTrue(true);
            System.out.println("We cannot say you are right yet. "
                    + "Did you handle the null value for primitive types? "
                    + "We catch an exception here: " + e);
            e.printStackTrace();
        }

    }

    public void testInsertHomework() {
        Homework work = new Homework();
        // We do not set the dueDate property here!
        // So null is the default.
        work.setDueDate(Calendar.getInstance().getTime());
        work.setFinished(true);
        try {
            System.out.println(manager);
            manager.insert(work);
        } catch (Exception e) {
            assertTrue(true);
            System.out
                    .println("Did you handle the null object values when a not-null contraint "
                            + "exists? We catch an exception here: " + e);
            e.printStackTrace();
        }
    }

}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?