Permalink
Browse files

Test persistence of updated metafile fields.

Also serve as a test case for the report in #8.
1 parent 01d9264 commit 123684d37f4373292f819ec865dccb403552f957 @abahgat abahgat committed Jun 24, 2015
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/test/java/org/bitlet/wetorrent/MetafileTest.java
@@ -20,6 +20,8 @@
import org.junit.Test;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.util.Collections;
import java.util.LinkedList;
@@ -38,7 +40,6 @@ public void readMetafile() throws Exception {
InputStream stream = MetafileTest.class.getResourceAsStream(TEST_TORRENT_PATH);
Metafile metafile = new Metafile(stream);
assertEquals("http://torrent.ubuntu.com:6969/announce", metafile.getAnnounce());
-
List announceList = new LinkedList();
List firstList = new LinkedList();
firstList.add(toByteBuffer("http://torrent.ubuntu.com:6969/announce"));
@@ -57,4 +58,16 @@ public void readMetafile() throws Exception {
assertEquals(524288L, metafile.getPieceLength().longValue());
assertEquals(2196, metafile.getPieces().size());
}
+
+ @Test
+ public void updateManifestComment() throws Exception {
+ InputStream stream = MetafileTest.class.getResourceAsStream(TEST_TORRENT_PATH);
+ Metafile metafile = new Metafile(stream);
+ metafile.setComment("foo");
+ ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
+ metafile.print(outputStream);
+ ByteArrayInputStream inputStream = new ByteArrayInputStream(outputStream.toByteArray());
+ Metafile metafileWithUpdatedFields = new Metafile(inputStream);
+ assertEquals("foo", metafile.getComment());
+ }
}

0 comments on commit 123684d

Please sign in to comment.