JUnit test for EmptyTreeIterator
[egit.git] / org.spearce.jgit.test / tst / org / spearce / jgit / treewalk / EmptyTreeIteratorTest.java
blob2cf5eca87b481b82a3306e1da2a542052023278d
1 /*
2 * Copyright (C) 2008, Google Inc.
4 * All rights reserved.
6 * Redistribution and use in source and binary forms, with or
7 * without modification, are permitted provided that the following
8 * conditions are met:
10 * - Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above
14 * copyright notice, this list of conditions and the following
15 * disclaimer in the documentation and/or other materials provided
16 * with the distribution.
18 * - Neither the name of the Git Development Community nor the
19 * names of its contributors may be used to endorse or promote
20 * products derived from this software without specific prior
21 * written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
24 * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
25 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
26 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
28 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
30 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
33 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
35 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 package org.spearce.jgit.treewalk;
40 import org.spearce.jgit.lib.ObjectId;
41 import org.spearce.jgit.lib.RepositoryTestCase;
43 public class EmptyTreeIteratorTest extends RepositoryTestCase {
44 public void testAtEOF() throws Exception {
45 final EmptyTreeIterator etp = new EmptyTreeIterator();
46 assertTrue(etp.first());
47 assertTrue(etp.eof());
50 public void testCreateSubtreeIterator() throws Exception {
51 final EmptyTreeIterator etp = new EmptyTreeIterator();
52 final AbstractTreeIterator sub = etp.createSubtreeIterator(db);
53 assertNotNull(sub);
54 assertTrue(sub.first());
55 assertTrue(sub.eof());
56 assertTrue(sub instanceof EmptyTreeIterator);
59 public void testEntryObjectId() throws Exception {
60 final EmptyTreeIterator etp = new EmptyTreeIterator();
61 assertSame(ObjectId.zeroId(), etp.getEntryObjectId());
62 assertNotNull(etp.idBuffer());
63 assertEquals(0, etp.idOffset());
64 assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));
67 public void testNextDoesNothing() throws Exception {
68 final EmptyTreeIterator etp = new EmptyTreeIterator();
69 etp.next(1);
70 assertTrue(etp.first());
71 assertTrue(etp.eof());
72 assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));
74 etp.next(1);
75 assertTrue(etp.first());
76 assertTrue(etp.eof());
77 assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));
80 public void testBackDoesNothing() throws Exception {
81 final EmptyTreeIterator etp = new EmptyTreeIterator();
82 etp.back(1);
83 assertTrue(etp.first());
84 assertTrue(etp.eof());
85 assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));
87 etp.back(1);
88 assertTrue(etp.first());
89 assertTrue(etp.eof());
90 assertEquals(ObjectId.zeroId(), ObjectId.fromRaw(etp.idBuffer()));
93 public void testStopWalkCallsParent() throws Exception {
94 final boolean called[] = new boolean[1];
95 assertFalse(called[0]);
97 final EmptyTreeIterator parent = new EmptyTreeIterator() {
98 @Override
99 public void stopWalk() {
100 called[0] = true;
103 parent.createSubtreeIterator(db).stopWalk();
104 assertTrue(called[0]);