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

📄 genericmanagertest.java

📁 基于java的组号查询模块
💻 JAVA
字号:
package com.lily.dap.service;

import com.lily.dap.dao.Dao;
import com.lily.dap.model.right.User;
import com.lily.dap.service.core.BaseManager;
import org.jmock.Mock;

/**
 * This class tests the generic Manager and BaseManager implementation.
 */
public class GenericManagerTest extends BaseManagerTestCase {
    protected Manager manager = new BaseManager();
    protected Mock dao;
    
    protected void setUp() throws Exception {
        super.setUp();
        dao = new Mock(Dao.class);
        ((BaseManager)manager).setDao((Dao) dao.proxy());
    }
    
    protected void tearDown() throws Exception {
        manager = null;
        dao = null;
    }

    /**
     * Simple test to verify BaseDao works.
     */
    public void testCRUD() {
        User user = new User();
        // set required fields
        user.setUsername("foo");

        // create
        // set expectations
        dao.expects(once()).method("save").isVoid();
        
        user = (User)manager.add(user);
        dao.verify();
        
        // retrieve
        dao.reset();
        // expectations
        dao.expects(once()).method("get").will(returnValue(user));
        
        user = (User) manager.get(User.class, user.getUsername());
        dao.verify();
        
        // update
        dao.reset();
        dao.expects(once()).method("save").isVoid();
        user.setPasswordHint("Password Hint");
        manager.modify(user);
        dao.verify();
        
        // delete
        dao.reset();
//        // expectations
//        Exception ex = new ObjectRetrievalFailureException(User.class, "foo");
//        dao.expects(once()).method("remove").isVoid();            
//        dao.expects(once()).method("get").will(throwException(ex));
//        manager.remove(User.class, "foo");
//        try {
//            manager.get(User.class, "foo");
//            fail("User 'foo' found in database");
//        } catch (ObjectRetrievalFailureException e) {
//            assertNotNull(e.getMessage());
//        }
//        dao.verify();
    }
}

⌨️ 快捷键说明

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