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

📄 testpetstoreejb2.java

📁 软件测试经典书籍<<Junit in action>>里的源代码。
💻 JAVA
字号:
package junitbook.ejb.service3;

import java.util.Date;

import javax.ejb.EJBException;
import javax.jms.JMSException;

import junit.framework.Test;
import junitbook.ejb.CommonPetstoreTestCase;
import junitbook.ejb.service.PetstoreEJB;

public class TestPetstoreEJB2 extends CommonPetstoreTestCase
{       
    private PetstoreEJB petstore;

    public static Test suite()
    {
        return suite(TestPetstoreEJB2.class);
    } 

    protected void setUp() throws Exception
    {
        super.setUp();
        
        petstore = new PetstoreEJB() {};
    }

    public void testCreateOrderOk() throws Exception
    {
        mockQueueConnectionFactory.expectAndReturn(
            "createQueueConnection", queueConnection);

        int orderId = petstore.createOrder(new Date(), "item1");
        
        assertEquals(1234, orderId);
    }

    public void testCreateThrowsOrderException() throws Exception
    {
        mockQueueConnectionFactory.expectAndThrow(
            "createQueueConnection", new JMSException("error"));

        try
        {
            petstore.createOrder(new Date(), "item1");
            fail("Should have thrown an EJBException");
        }
        catch (EJBException expected)
        {
            assertEquals("error", 
                expected.getCausedByException().getMessage());
        }
    }

}

⌨️ 快捷键说明

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