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

📄 jidtest.java

📁 openfire 服务器源码下载
💻 JAVA
字号:
/**
 * Copyright (C) 2004-2007 Jive Software. All rights reserved.
 *
 * This software is published under the terms of the GNU Public License (GPL),
 * a copy of which is included in this distribution, or a commercial license
 * agreement with Jive.
 */

package org.jivesoftware.util;

import junit.framework.TestCase;
import org.xmpp.packet.JID;

/**
 * Test cases for the JID class.
 *
 * @author Gaston Dombiak
 */
public class JIDTest extends TestCase {

    public void testDomain() {
        new JID("mycomapny.com");
        new JID("wfink-adm");

        boolean failed = false;
        try {
            new JID("wfink adm");
        } catch (Exception e) {
            failed = true;
        }
        assertTrue("A domain with spaces was accepted", failed);

        failed = false;
        try {
            new JID("wfink_adm");
        } catch (Exception e) {
            failed = true;
        }
        assertTrue("A domain with _ was accepted", failed);
    }

    public void testUsernames() {
        new JID("john@mycomapny.com");
        new JID("john_paul@mycomapny.com");
        new JID("john-paul@mycomapny.com");
        boolean failed = false;
        try {
            new JID("john paul@mycomapny.com");
        } catch (Exception e) {
            failed = true;
        }
        assertTrue("A username with spaces was accepted", failed);
    }

    public void testCompare() {
        JID jid1 = new JID("john@mycomapny.com");
        JID jid2 = new JID("john@mycomapny.com");
        assertEquals("Failed to compare 2 similar JIDs", 0 , jid1.compareTo(jid2));
        assertEquals("Failed to recognize equal JIDs", jid1 , jid2);

        jid1 = new JID("john@mycomapny.com");
        jid2 = new JID("mycomapny.com");
        assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) > 0);
        assertFalse("Failed to recognize different JIDs", jid1.equals(jid2));

        jid1 = new JID("john@mycomapny.com");
        jid2 = new JID("mycomapny.com/resource");
        assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) > 0);
        assertFalse("Failed to recognize different JIDs", jid1.equals(jid2));

        jid1 = new JID("john@mycomapny.com");
        jid2 = new JID("john@mycomapny.com/resource");
        assertTrue("Failed to recognized bigger JID", jid1.compareTo(jid2) < 0);
        assertFalse("Failed to recognize different JIDs", jid1.equals(jid2));

    }
}

⌨️ 快捷键说明

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