diff options
author | Sasa Zivkov <sasa.zivkov@sap.com> | 2011-01-03 16:03:49 +0100 |
---|---|---|
committer | Sasa Zivkov <sasa.zivkov@sap.com> | 2011-01-05 08:24:13 +0100 |
commit | 7cd812940d25a78f71467ede0b2637211b2a12a1 (patch) | |
tree | 7bf2f1f7aea387ab05f076fd46dd0dc3e590d2b5 /org.eclipse.jgit.test/tst/org/eclipse/jgit/notes | |
parent | b7f887f1204fc14e2ef698d6d4a24d13fa6de5e6 (diff) | |
download | jgit-7cd812940d25a78f71467ede0b2637211b2a12a1.tar.gz jgit-7cd812940d25a78f71467ede0b2637211b2a12a1.zip |
NoteMap implements Iterable<Note>
We will need to iterate over all notes of a NoteMap, at least this will be
needed for testing purposes. This change also implied making the Note class
public.
Change-Id: I9b0639f9843f457ee9de43504b2499a673cd0e77
Signed-off-by: Sasa Zivkov <sasa.zivkov@sap.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/notes')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java index 6c65b53644..94fdc69e80 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/notes/NoteMapTest.java @@ -52,6 +52,7 @@ import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import java.io.IOException; +import java.util.Iterator; import org.eclipse.jgit.junit.TestRepository; import org.eclipse.jgit.lib.CommitBuilder; @@ -444,6 +445,83 @@ public class NoteMapTest extends RepositoryTestCase { assertEquals("empty tree", empty, n.getTree()); } + public void testIteratorEmptyMap() { + Iterator<Note> it = NoteMap.newEmptyMap().iterator(); + assertFalse(it.hasNext()); + } + + public void testIteratorFlatTree() throws Exception { + RevBlob a = tr.blob("a"); + RevBlob b = tr.blob("b"); + RevBlob data1 = tr.blob("data1"); + RevBlob data2 = tr.blob("data2"); + RevBlob nonNote = tr.blob("non note"); + + RevCommit r = tr.commit() // + .add(a.name(), data1) // + .add(b.name(), data2) // + .add("nonNote", nonNote) // + .create(); + tr.parseBody(r); + + Iterator it = NoteMap.read(reader, r).iterator(); + assertEquals(2, count(it)); + } + + public void testIteratorFanoutTree2_38() throws Exception { + RevBlob a = tr.blob("a"); + RevBlob b = tr.blob("b"); + RevBlob data1 = tr.blob("data1"); + RevBlob data2 = tr.blob("data2"); + RevBlob nonNote = tr.blob("non note"); + + RevCommit r = tr.commit() // + .add(fanout(2, a.name()), data1) // + .add(fanout(2, b.name()), data2) // + .add("nonNote", nonNote) // + .create(); + tr.parseBody(r); + + Iterator it = NoteMap.read(reader, r).iterator(); + assertEquals(2, count(it)); + } + + public void testIteratorFanoutTree2_2_36() throws Exception { + RevBlob a = tr.blob("a"); + RevBlob b = tr.blob("b"); + RevBlob data1 = tr.blob("data1"); + RevBlob data2 = tr.blob("data2"); + RevBlob nonNote = tr.blob("non note"); + + RevCommit r = tr.commit() // + .add(fanout(4, a.name()), data1) // + .add(fanout(4, b.name()), data2) // + .add("nonNote", nonNote) // + .create(); + tr.parseBody(r); + + Iterator it = NoteMap.read(reader, r).iterator(); + assertEquals(2, count(it)); + } + + public void testIteratorFullyFannedOut() throws Exception { + RevBlob a = tr.blob("a"); + RevBlob b = tr.blob("b"); + RevBlob data1 = tr.blob("data1"); + RevBlob data2 = tr.blob("data2"); + RevBlob nonNote = tr.blob("non note"); + + RevCommit r = tr.commit() // + .add(fanout(38, a.name()), data1) // + .add(fanout(38, b.name()), data2) // + .add("nonNote", nonNote) // + .create(); + tr.parseBody(r); + + Iterator it = NoteMap.read(reader, r).iterator(); + assertEquals(2, count(it)); + } + private RevCommit commitNoteMap(NoteMap map) throws IOException { tr.tick(600); @@ -469,4 +547,13 @@ public class NoteMapTest extends RepositoryTestCase { } return r.toString(); } + + private static int count(Iterator it) { + int c = 0; + while (it.hasNext()) { + c++; + it.next(); + } + return c; + } } |