Let's Testing
取得の正常系のテストは通ったようなので異常系も書く。
public final void testGetBelongToEntityNoNumber() { //Entityの取得 BelongToEntity belongToEntity = BELONGTO_DAO.getBelongToEntity(-1); //答え合わせ assertNull(belongToEntity); }
無事にクリア。どうやら取得は問題なく行なえているようなので次はinsertのテストを書く。
insertのテストを書くにあたりBelongToEntityのequalsメソッドをオーバーライドしておく。
public boolean equals(Object obj) { BelongToEntity target = (BelongToEntity) obj; if (getBelongToCode() != target.getBelongToCode()) {return false;} if (!getBelongToName().equalsIgnoreCase(target.getBelongToName())) {return false;} return true; }
して、insertのテストはこんな感じ(コンテナとDAOはクラス変数にしました)
public final void testInsert() { BelongToEntity belongToEntity = new BelongToEntity(); belongToEntity.setBelongToCode(3); belongToEntity.setBelongToName("デラーズフリート"); //実行 BELONGTO_DAO.insert(belongToEntity); //答え合わせ BelongToEntity answerEntity = BELONGTO_DAO.getBelongToEntity(3); assertTrue("値が違います", belongToEntity.equals(answerEntity)); }
これもクリア。