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

📄 universalmanagertest.java

📁 基于Maven的质量保证自动化环境配置和演示程序
💻 JAVA
字号:
package com.cib.service.impl;import com.cib.dao.UniversalDao;import com.cib.model.User;import org.jmock.Expectations;import org.springframework.orm.ObjectRetrievalFailureException;import org.springframework.test.AssertThrows;import org.junit.Before;import org.junit.After;import org.junit.Test;import static org.junit.Assert.*;/** * This class tests the generic UniversalManager and UniversalManagerImpl implementation. */public class UniversalManagerTest extends BaseManagerMockTestCase {    protected UniversalManagerImpl manager = new UniversalManagerImpl();    protected UniversalDao dao;    @Before    public void setUp() throws Exception {        dao = context.mock(UniversalDao.class);        manager.setDao(dao);    }    @After    public void tearDown() throws Exception {        manager = null;        dao = null;    }    /**     * Simple test to verify BaseDao works.     */    @Test    public void testCreate() {        final User user = createUser();        context.checking(new Expectations() {{            one(dao).save(with(same(user)));            will(returnValue(user));        }});        manager.save(user);    }    @Test    public void testRetrieve() {        final User user = createUser();        context.checking(new Expectations() {{            one(dao).get(User.class, "foo");            will(returnValue(user));        }});        User user2 = (User) manager.get(User.class, user.getUsername());        assertTrue(user2.getUsername().equals("foo"));    }    @Test    public void testUpdate() {        context.checking(new Expectations() {{            one(dao).save(createUser());        }});        User user = createUser();        user.getAddress().setCountry("USA");        manager.save(user);    }    @Test    public void testDelete() {        final Exception ex = new ObjectRetrievalFailureException(User.class, "foo");        context.checking(new Expectations() {{            one(dao).remove(User.class, "foo");            one(dao).get(User.class, "foo");            will(throwException(ex));        }});        manager.remove(User.class, "foo");        new AssertThrows(ObjectRetrievalFailureException.class) {            public void test() {                manager.get(User.class, "foo");            }        }.runTest();    }        private User createUser() {        User user = new User();        // set required fields        user.setUsername("foo");        return user;    }}

⌨️ 快捷键说明

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