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

📄 remotemachinerunnerhittertest.java

📁 sourcode about java basic
💻 JAVA
字号:
// Copyright 2005 Google Inc.
// All Rights Reserved.
package jsunit.java.tests_server.net.jsunit;

import junit.framework.TestCase;
import net.jsunit.utility.XmlUtility;
import org.jdom.Document;

import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import java.net.URLStreamHandler;

public class RemoteMachineRunnerHitterTest extends TestCase {

    String xml = "<my_document><my_node value=\"1\">my text</my_node></my_document>";

    public void testAllAtOnce() throws Exception {
        RemoteMachineServerHitter hitter = new RemoteMachineServerHitter();
        Document document = hitter.hitURL(createURL(xml, xml.length()));
        assertDocumentHasXml(xml, document);
    }

    public void testAPieceAtATime() throws Exception {
        RemoteMachineServerHitter hitter = new RemoteMachineServerHitter();
        Document document = hitter.hitURL(createURL(xml, 3));
        assertDocumentHasXml(xml, document);
    }

    private void assertDocumentHasXml(String expectedXML, Document document) {
        assertEquals(expectedXML, XmlUtility.asString(document.getRootElement()));
    }

    private URL createURL(final String xml, final int byteCount) throws MalformedURLException {
        return new URL("http", "www.example.com", 8080, "foo", new URLStreamHandler() {
            protected URLConnection openConnection(URL u) {
                return new URLConnection(u) {
                    public void connect() {
                    }

                    public InputStream getInputStream() {
                        return new InputStream() {

                            private int index = 0;

                            public int read() {
                                if (index >= xml.length())
                                    return -1;
                                return xml.codePointAt(index++);
                            }
                        };
                    }
                };
            }
        });
    }

}

⌨️ 快捷键说明

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