@Test public void serializingStringShouldCorrespondSpecification() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(100); BencodeString bencodeString = new BencodeString("Hello"); bencodeString.serialize(byteArrayOutputStream); String s = byteArrayOutputStream.toString(); Assert.assertEquals("5:Hello", s); }
@Test public void serializingEmptyStringShouldBeCorrect() throws IOException { ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(100); BencodeString bencodeString = new BencodeString(""); bencodeString.serialize(byteArrayOutputStream); String s = byteArrayOutputStream.toString(); Assert.assertEquals("0:", s); }
@Test public void parsingEmptyStringShouldBeCorrect() throws IOException, BadBencodingException { byte[] buffer; buffer = "0:".getBytes(); ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(buffer); BencodeParser parser = new BencodeParser(byteArrayInputStream); BencodeString str = (BencodeString) parser.parse(); Assert.assertEquals("", str.getString()); }