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

📄 resultdisplayeractiontest.java

📁 sourcode about java basic
💻 JAVA
字号:
package jsunit.java.tests_server.net.jsunit.action;

import junit.framework.TestCase;
import net.jsunit.InvalidBrowserIdException;
import net.jsunit.MockBrowserTestRunner;
import net.jsunit.model.BrowserResult;
import net.jsunit.utility.XmlUtility;

public class ResultDisplayerActionTest extends TestCase {

    private ResultDisplayerAction action;
    private MockBrowserTestRunner mockRunner;

    public void setUp() throws Exception {
        super.setUp();
        action = new ResultDisplayerAction();
        mockRunner = new MockBrowserTestRunner();
        action.setBrowserTestRunner(mockRunner);
        action.setId("12345");
        action.setBrowserId(8);
    }

    public void testResultFound() throws Exception {
        mockRunner.resultToReturn = new BrowserResult();
        assertEquals(ResultDisplayerAction.SUCCESS, action.execute());
        assertEquals("12345", mockRunner.idPassed);
        assertEquals(8, mockRunner.browserIdPassed.intValue());
        assertEquals(mockRunner.resultToReturn, action.getXmlRenderable());
    }

    public void testResultNotFound() throws Exception {
        assertEquals(ResultDisplayerAction.SUCCESS, action.execute());
        assertEquals("12345", mockRunner.idPassed);
        assertEquals(8, mockRunner.browserIdPassed.intValue());
        assertEquals("<error>No Test Result has been submitted with ID '12345' for browser ID '8'</error>", XmlUtility.asString(action.getXmlRenderable().asXml()));
    }

    public void testIdNotGiven() throws Exception {
        action.setId(null);
        action.setBrowserId(null);
        assertEquals(ResultDisplayerAction.ERROR, action.execute());
        assertNull(mockRunner.idPassed);
        assertNull(mockRunner.browserIdPassed);
        assertEquals("<error>A Test Result ID and a browser ID must both be given</error>", XmlUtility.asString(action.getXmlRenderable().asXml()));
    }

    public void testInvalidBrowserId() throws Exception {
        action.setId("54321");
        action.setBrowserId(12345);
        mockRunner = new MockBrowserTestRunner() {
            public BrowserResult findResultWithId(String id, int browserId) throws InvalidBrowserIdException {
                super.findResultWithId(id, browserId);
                throw new InvalidBrowserIdException(browserId);
            }
        };
        action.setBrowserTestRunner(mockRunner);
        assertEquals(ResultDisplayerAction.ERROR, action.execute());
        assertEquals("54321", this.mockRunner.idPassed);
        assertEquals(12345, this.mockRunner.browserIdPassed.intValue());
        assertEquals("<error>Invalid Browser ID '12345'</error>", XmlUtility.asString(action.getXmlRenderable().asXml()));
    }
}

⌨️ 快捷键说明

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