Ejemplo n.º 1
0
 @Test
 public void serializingDictionaryShouldBeCorrect() throws IOException {
   ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(100);
   BencodeDictionary bencodeDictionary = new BencodeDictionary();
   bencodeDictionary.addItem("key1", new BencodeInteger(5));
   bencodeDictionary.addItem("key2", new BencodeString("hello"));
   bencodeDictionary.serialize(byteArrayOutputStream);
   String s = byteArrayOutputStream.toString();
   Assert.assertEquals("d4:key1i5e4:key25:helloe", s);
 }
Ejemplo n.º 2
0
 @Test
 public void serializingNestedListInDictionaryShouldBeCorrect() throws IOException {
   ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(100);
   BencodeDictionary bencodeDictionary = new BencodeDictionary();
   BencodeList bencodeList = new BencodeList();
   bencodeList.addItem(new BencodeInteger(5));
   bencodeList.addItem(new BencodeInteger(2));
   bencodeDictionary.addItem("key", bencodeList);
   bencodeDictionary.serialize(byteArrayOutputStream);
   String s = byteArrayOutputStream.toString();
   Assert.assertEquals("d3:keyli5ei2eee", s);
 }