⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 accountservicetest.java

📁 JPetStore简单应用
💻 JAVA
字号:
package test.com.ibatis.jpetstore.service;

import com.ibatis.jpetstore.domain.Account;
import com.ibatis.jpetstore.persistence.iface.AccountDao;
import com.ibatis.jpetstore.service.AccountService;

import org.jmock.Mock;
import org.jmock.MockObjectTestCase;

import test.com.ibatis.jpetstore.domain.DomainFixture;

public class AccountServiceTest extends MockObjectTestCase {

  public void testShouldVerifyGetAccountIsCalledByUsername() {
    Mock mock = mock(AccountDao.class);

    mock.expects(once())
        .method("getAccount")
        .with(NOT_NULL)
        .will(returnValue(new Account()));

    AccountService accountService = new AccountService((AccountDao) mock.proxy());
    accountService.getAccount("cbegin");
  }

  public void testShouldVerifyGetAccountIsCalledByUsernameAndPassword() {
    Mock mock = mock(AccountDao.class);

    mock.expects(once())
        .method("getAccount")
        .with(NOT_NULL, NOT_NULL)
        .will(returnValue(new Account()));

    AccountService accountService = new AccountService((AccountDao) mock.proxy());
    accountService.getAccount("cbegin","PASSWORD");
  }

  public void testShouldVerifyInsertAccountIsCalled() {
    Mock mock = mock(AccountDao.class);

    mock.expects(once())
        .method("insertAccount")
        .with(NOT_NULL);

    AccountService accountService = new AccountService((AccountDao) mock.proxy());
    accountService.insertAccount(DomainFixture.newTestAccount());
  }

  public void testShouldVerifyUpdateAccountIsCalled() {
    Mock mock = mock(AccountDao.class);

    mock.expects(once())
        .method("updateAccount")
        .with(NOT_NULL);

    AccountService accountService = new AccountService((AccountDao) mock.proxy());
    accountService.updateAccount(DomainFixture.newTestAccount());
  }

}

⌨️ 快捷键说明

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