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

📄 binaryidtest.java

📁 JXTA&#8482 is a set of open, generalized peer-to-peer (P2P) protocols that allow any networked devi
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            // 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));                        PeerBinaryID 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());                        // Check that the parent == parent in the new group.            net.jxta.impl.id.UUID.PeerGroupID base2 = (net.jxta.impl.id.UUID.PeerGroupID) one.getPeerGroupID();            assertTrue("comparison of base == base2", base.equals(base2));                        URI asURI = one.toURI();            String asString = one.toString();                        assertTrue("comparison of ID string and string of URI was not the same", one.toString().equals(asURI.toString()));                        PeerBinaryID six = (PeerBinaryID) IDFactory.fromURI(asURI);                        assertTrue("result of conversion to URI 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 testPipeID() {        try {            // Create a uuid parent            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID();            PipeBinaryID one = new PipeBinaryID(base, data1, false);            PipeBinaryID two = new PipeBinaryID(base, data2, true);            PipeBinaryID three = new PipeBinaryID(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));                        PipeBinaryID 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());                        // Check that the parent == parent in the new group.            net.jxta.impl.id.UUID.PeerGroupID base2 = (net.jxta.impl.id.UUID.PeerGroupID) one.getPeerGroupID();            assertTrue("comparison of base == base2", base.equals(base2));                        URI asURI = one.toURI();            String asString = one.toString();                        assertTrue("comparison of ID string and string of URI was not the same", one.toString().equals(asURI.toString()));                        PipeBinaryID six = (PipeBinaryID) IDFactory.fromURI(asURI);                        assertTrue("result of conversion to URI 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 testPeerGroupBinaryIDDigestID() {        String clearTextID = "turbogeek";        String function = "test";        String function2 = "test-test";                try {            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID();            DigestTool digestTool = new DigestTool();            PeerGroupBinaryID one = digestTool.createPeerGroupID(base, clearTextID, function);            PeerGroupBinaryID two = digestTool.createPeerGroupID(base, clearTextID, function);            PeerGroupBinaryID three = digestTool.createPeerGroupID(base, clearTextID, function2);                        // 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 = 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());                    } catch (Exception everything) {            everything.printStackTrace();            fail("caught an unexpected exception - " + everything.toString());        }    }    public void testPipeBinaryIDDigestID() {        String clearTextID = "turbogeek";        String function = "test";        String function2 = "test-test";                try {            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID();            DigestTool digestTool = new DigestTool();            PipeBinaryID one = digestTool.createPipeID(base, clearTextID, function);             PipeBinaryID oneOne = digestTool.createPipeID(base, clearTextID, function);             PipeBinaryID two = digestTool.createPipeID(base, clearTextID, function);            PipeBinaryID three = digestTool.createPipeID(base, clearTextID, function2);                        // Common ID tests            // System.out.println("\n\nVisual URI check:\n   one.toURI: '"+one.toURI()+"'");            // System.out.println("oneOne.toURI: '"+oneOne.toURI()+"'");            // System.out.println("   two.gettoURIURI: '"+toURI.toURI()+"'\n");            assertTrue("comparison of one == oneOne", one.equals(oneOne));            assertTrue("comparison of one == two", one.equals(two));            assertTrue("comparison of two != three", !two.equals(three));            assertTrue("comparison of one != three", !one.equals(three));                        PipeBinaryID 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());                    } catch (Exception everything) {            everything.printStackTrace();            fail("caught an unexpected exception - " + everything.toString());        }    }    public void testPeerBinaryIDDigestID() {        String clearTextID = "turbogeek";        String function = "test";        String function2 = "test-test";                try {            net.jxta.impl.id.UUID.PeerGroupID base = new net.jxta.impl.id.UUID.PeerGroupID();            DigestTool digestTool = new DigestTool();            PeerBinaryID one = digestTool.createPeerID(base, clearTextID, function);            PeerBinaryID two = digestTool.createPeerID(base, clearTextID, function);            PeerBinaryID three = digestTool.createPeerID(base, clearTextID, function2);                        // 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));                        PeerBinaryID 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());                    } catch (Exception everything) {            everything.printStackTrace();            fail("caught an unexpected exception - " + everything.toString());        }    }    public void testCodatID() {        try {            CodatID first = IDFactory.newCodatID(IDFactory.newPeerGroupID());            CodatID second = IDFactory.newCodatID(IDFactory.newPeerGroupID());            CodatID third;            ID interloper = IDFactory.newPeerID(IDFactory.newPeerGroupID());            String  asString;            URI     asURI;            ID myPeerGroup;            boolean isStatic;                 assertTrue("comparison of a CodatID against itself failed", first.equals(first));                 assertTrue("comparison of two different CodatIDs should have failed", !first.equals(second));                 assertTrue("comparison of different types should have failed", !first.equals(interloper));                 assertTrue("comparison of different types should have failed", !interloper.equals(first));                 assertTrue("zero hashcodereturned", 0 != first.hashCode());                 asURI = first.toURI();            asString = first.toString();                 assertTrue("comparison of ID string and string of URI was not the same", asString.equals(asURI.toString()));                 third = (CodatID) IDFactory.fromURI(asURI);                 assertTrue("result of conversion to URI and back to ID was not equal to original", first.equals(third));                 myPeerGroup = first.getPeerGroupID();                 assertTrue("clone of ID is not of same peergroup.", first.getPeerGroupID().equals(third.getPeerGroupID()));                 assertTrue("dynamic CodatID did not test as such.", !first.isStatic());        } catch (Exception everything) {            everything.printStackTrace();            fail("caught an unexpected exception - " + everything.toString());             }    }}

⌨️ 快捷键说明

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