0

シナリオ:

final CatalogRuleExample example = new CatalogRuleExample();
example.createCriteria().andCatalogIdEqualTo(catalogId);
example.setOrderByClause("position ASC");

final List<CatalogRuleRecord> records = new ArrayList<CatalogRuleRecord>();
final CatalogRuleRecord firstRecord = new CatalogRuleRecord();
final CatalogRuleRecord secondRecord = new CatalogRuleRecord();
records.add(firstRecord);
records.add(secondRecord);
mockery.checking(new Expectations() {
  {
    oneOf(catalogRuleDAO).selectByExample(example);
    will(returnValue(records));

...

問題:

CatalogRuleExample の最後の例は、selectByExample による私の mockery.checking とは異なります。equals() をオーバーライドすると機能します。しかし、この場合のより良い解決策があるかどうかを知りたかったのです。PS: この同じコードは、Ibatis から Mybtis に移行する前に機能しました

final CatalogRuleExample example = new CatalogRuleExample() {
  @Override
  public boolean equals(Object that) {
    if (that instanceof CatalogRuleExample) {
      CatalogRuleExample other = (CatalogRuleExample) that;
      if (other.getOredCriteria().size() != 1) {
        return false;
      }
      if (other.getOredCriteria().get(0).getCriteria().size() != 1) {
        return false;
      }
      if (!other.getOredCriteria().get(0).getCriteria().get(0).getValue().equals(catalogId)) {
        return false;
      }
      if (!other.getOrderByClause().equals("position ASC")) {
        return false;
      }
      return true;
    }
    return false;
  }
};

エラー: 予期しない呼び出し: catalogRuleDAO.selectByExample(<com.protogo.persistence.dao.CatalogRuleExample@a6ca0ea9>) 期待値: 一度期待され、呼び出されたことはありません: catalogRuleDAO.selectByExample(<com.protogo.persistence.dao.CatalogRuleExample@66e1beb1>); <[com.protogo.persistence.data.CatalogRuleRecord@4f7d02c2, com.protogo.persistence.data.CatalogRuleRecord@4f7d02c2]> を返します

4

0 に答える 0