📄 binaryidtest.java
字号:
PeerBinaryID four = (PeerBinaryID) 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) ); URL asURL = one.getURL( ); String asString = one.toString( ); assertTrue( "comparison of ID string and string of URL was not the same", one.equals( one.toString() ) ); PeerBinaryID six = (PeerBinaryID) 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 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 = (PipeBinaryID) 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) ); URL asURL = one.getURL( ); String asString = one.toString( ); assertTrue( "comparison of ID string and string of URL was not the same", one.equals( one.toString() ) ); PipeBinaryID six = (PipeBinaryID) 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 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 = (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() ); }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 URL check:\n one.getURL: '"+one.getURL()+"'"); //System.out.println("oneOne.getURL: '"+oneOne.getURL()+"'"); //System.out.println(" two.getURL: '"+two.getURL()+"'\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 = (PipeBinaryID) 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 = (PeerBinaryID) 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 = (ID) IDFactory.newPeerID( IDFactory.newPeerGroupID( ) ); String asString; URL asURL; 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() ); asURL = first.getURL( ); asString = first.toString( ); assertTrue( "comparison of ID string and string of URL was not the same", asString.equals( asURL.toString() ) ); third = (CodatID) IDFactory.fromURL( asURL ); assertTrue( "result of conversion to URL 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 + -