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

📄 binaryidtest.java

📁 jxta_src_2.41b jxta 2.41b 最新版源码 from www.jxta.org
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * $Id: BinaryIDTest.java,v 1.2 2005/11/29 20:21:21 bondolo Exp $ ******************** * * Copyright (c) 2001 Sun Microsystems, Inc.  All rights reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright *    notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright *    notice, this list of conditions and the following disclaimer in *    the documentation and/or other materials provided with the *    distribution. * * 3. The end-user documentation included with the redistribution, *    if any, must include the following acknowledgment: *       "This product includes software developed by the *       Sun Microsystems, Inc. for Project JXTA." *    Alternately, this acknowledgment may appear in the software itself, *    if and wherever such third-party acknowledgments normally appear. * * 4. The names "Sun", "Sun Microsystems, Inc.", "JXTA" and "Project JXTA" must *    not be used to endorse or promote products derived from this *    software without prior written permission. For written *    permission, please contact Project JXTA at http://www.jxta.org. * * 5. Products derived from this software may not be called "JXTA", *    nor may "JXTA" appear in their name, without prior written *    permission of Sun. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED.  IN NO EVENT SHALL SUN MICROSYSTEMS OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of Project JXTA.  For more * information on Project JXTA, please see * <http://www.jxta.org/>. * * This license is based on the BSD license adopted by the Apache Foundation. ******************** */package net.jxta.impl.id.binaryID;import java.net.URL;import junit.framework.Test;import junit.framework.TestCase;import junit.framework.TestSuite;import net.jxta.codat.CodatID;import net.jxta.id.ID;import net.jxta.id.IDFactory;/** * Tests for BinaryID and DigestID * net.jxta.id.BinaryIDTest * @author Daniel Brookshier <a HREF="mailto:turbogeek@cluck.com">turbogeek@cluck.com</a> */public final class BinaryIDTest extends TestCase {	public static void main(String args[]) {		junit.textui.TestRunner.run(suite());		System.err.flush();		System.out.flush();	}    	public static Test suite() {		TestSuite suite = new TestSuite(BinaryIDTest.class);		return suite;	}  	    /** Creates new DocTest */    public BinaryIDTest(String name) {        super(name);    }    byte [] data1 = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };    byte [] data2 = { 16,1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 };    byte [] data3 = { 11, 22, 33, 44, 55, 66, 77, 88, 99, 99, 99, 99, 99, 99, 99, 99 };        public void testBinaryID() {        try {            //System.out.println("");            byte type = BinaryID.flagGenericID;            BinaryID one = BinaryIDFactory.newBinaryID( type, data1,false );            //System.out.println("one:"+one);            BinaryID two = BinaryIDFactory.newBinaryID( type, data2,true );            //System.out.println("two:"+two);            BinaryID three = BinaryIDFactory.newBinaryID( type, data3,false );            //System.out.println("three:"+three);            // Common ID tests                        assertTrue( "comparison of one == two", one.equals(two) );            assertTrue( "comparison of two != three", !two.equals(three) );            assertTrue( "comparison of one != three", !one.equals(three) );                        BinaryID four = one;                        assertTrue( "comparison of clone", one.equals(four) );                        assertTrue( "hashcode match one == two", one.hashCode() == two.hashCode() );            assertTrue( "hashcode match one == four", one.hashCode() == four.hashCode() );            assertTrue( "hashcode match one != three", one.hashCode() != three.hashCode() );                        // Tests specific to BinaryID            assertTrue( "type match one == two", one.type() == two.type() );            assertTrue( "type match one == four", one.type() == four.type() );            assertTrue( "type match one == three", one.type() == three.type() );                        BinaryID ten = BinaryIDFactory.newBinaryID( BinaryID.flagPeerGroupID, data3,false );            //System.out.println("ten:"+ten);            assertTrue( "type match one != ten", one.type() != ten.type() );            assertTrue( "objec match one != ten", !one.equals(ten) );                        assertTrue( "id match one == two", one.getID().equals(two.getID() ));            assertTrue( "id match one == four", one.getID().equals(four.getID() ));            assertTrue( "id match one != three", !one.getID().equals(three.getID() ));                    }        catch( Exception everything ) {            everything.printStackTrace();            fail( "caught an unexpected exception - " + everything.toString() );        }            }    public void testPeerGroupID() {        try {            byte type = BinaryID.flagGenericID;            PeerGroupBinaryID one = new PeerGroupBinaryID(  data1,false );            PeerGroupBinaryID two = new PeerGroupBinaryID(  data2,true );            PeerGroupBinaryID three = new PeerGroupBinaryID(data3,false );            // Common ID tests            assertTrue( "comparison of one == two", one.equals(two) );            assertTrue( "comparison of two != three", !two.equals(three) );            assertTrue( "comparison of one != three", !one.equals(three) );                        PeerGroupBinaryID four = (PeerGroupBinaryID) one;                        assertTrue( "comparison of clone", one.equals(four) );                        assertTrue( "hashcode match one == two", one.hashCode() == two.hashCode() );            assertTrue( "hashcode match one == four", one.hashCode() == four.hashCode() );            assertTrue( "hashcode match one != three", one.hashCode() != three.hashCode() );                        // Create a uuid parent            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID( ) ;                        one = new PeerGroupBinaryID(base,  data1,false );            two = new PeerGroupBinaryID(base, data2,true );            three = new PeerGroupBinaryID(base,data3,false );                        // Common ID tests (with a base peer group            assertTrue( "comparison of one == two", one.equals(two) );            assertTrue( "comparison of two != three", !two.equals(three) );            assertTrue( "comparison of one != three", !one.equals(three) );                        four = (PeerGroupBinaryID) one;                        assertTrue( "comparison of clone", one.equals(four) );                        assertTrue( "hashcode match one == two", one.hashCode() == two.hashCode() );            assertTrue( "hashcode match one == four", one.hashCode() == four.hashCode() );            assertTrue( "hashcode match one != three", one.hashCode() != three.hashCode() );                        // Try comparing a group without a base.            PeerGroupBinaryID five = new PeerGroupBinaryID(  data1,false );                        assertTrue( "simple group shouldnt have had a parent", null == five.getParentPeerGroupID() );                        assertTrue( "comparison of one != five", !one.equals(five) );                        // Check that the parent == parent in the new group.            net.jxta.impl.id.UUID.PeerGroupID base2 = (net.jxta.impl.id.UUID.PeerGroupID)one.getParentPeerGroupID() ;            assertTrue( "comparison of base == base2", base.equals(base2) );                        URL asURL = one.getURL( );            String asString = one.toString( );            //System.out.println("");            //System.out.println("one:"+one);            //System.out.println("asURL:"+asURL);            //System.out.println("asString:"+asString);            assertTrue( "comparison of ID string and string of URL was not the same", one.equals( one.toString() ) );                        PeerGroupBinaryID six = (PeerGroupBinaryID) IDFactory.fromURL( asURL );                        assertTrue( "result of conversion to URL and back to ID was not equal to original", one.equals( six ) );                        Object fromOne =  one.getUniqueValue();            Object fromTwo =  two.getUniqueValue();            Object fromThree =  three.getUniqueValue();                        assertTrue( "comparison of getUniqueValue ", fromOne.equals( fromTwo) );                        assertTrue( "comparison of getUniqueValue", !fromOne.equals( fromThree) );        }        catch( Exception everything ) {            everything.printStackTrace();            fail( "caught an unexpected exception - " + everything.toString() );        }            }        public void testPeerID() {        try {            // Create a uuid parent            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID( ) ;            PeerBinaryID one = new PeerBinaryID(base,  data1,false );            PeerBinaryID two = new PeerBinaryID(base,  data2,true );            PeerBinaryID three = new PeerBinaryID(base, data3,false );            // Common ID tests            assertTrue( "comparison of one == two", one.equals(two) );            assertTrue( "comparison of two != three", !two.equals(three) );            assertTrue( "comparison of one != three", !one.equals(three) );

⌨️ 快捷键说明

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