From: Matthias Sohn <matthias.sohn@xxxxxxx> Fixing bug 75 (http://code.google.com/p/egit/issues/detail?id=75). If all concrete test classes follow class name pattern **/*Test.java and all abstract test classes **/*TestCase.java it is easier to run tests with ant. Signed-off-by: Matthias Sohn <matthias.sohn@xxxxxxx> --- .../tst/org/spearce/jgit/lib/PackIndexTest.java | 162 ------------ .../org/spearce/jgit/lib/PackIndexTestCase.java | 162 ++++++++++++ .../tst/org/spearce/jgit/lib/PackIndexV1Test.java | 2 +- .../tst/org/spearce/jgit/lib/PackIndexV2Test.java | 2 +- .../org/spearce/jgit/transport/RefSpecTest.java | 269 ++++++++++++++++++++ .../spearce/jgit/transport/RefSpecTestCase.java | 269 -------------------- 6 files changed, 433 insertions(+), 433 deletions(-) delete mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTestCase.java create mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTest.java delete mode 100644 org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java deleted file mode 100644 index 7163718..0000000 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTest.java +++ /dev/null @@ -1,162 +0,0 @@ -/* - * Copyright (C) 2008, Marek Zawirski <marek.zawirski@xxxxxxxxx> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Git Development Community nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.spearce.jgit.lib; - -import java.io.File; -import java.util.Iterator; -import java.util.NoSuchElementException; - -import org.spearce.jgit.errors.MissingObjectException; -import org.spearce.jgit.lib.PackIndex.MutableEntry; - -public abstract class PackIndexTest extends RepositoryTestCase { - - PackIndex smallIdx; - - PackIndex denseIdx; - - public void setUp() throws Exception { - super.setUp(); - smallIdx = PackIndex.open(getFileForPack34be9032()); - denseIdx = PackIndex.open(getFileForPackdf2982f28()); - } - - /** - * Return file with appropriate index version for prepared pack. - * - * @return file with index - */ - public abstract File getFileForPack34be9032(); - - /** - * Return file with appropriate index version for prepared pack. - * - * @return file with index - */ - public abstract File getFileForPackdf2982f28(); - - /** - * Verify CRC32 support. - * - * @throws MissingObjectException - * @throws UnsupportedOperationException - */ - public abstract void testCRC32() throws MissingObjectException, - UnsupportedOperationException; - - /** - * Test contracts of Iterator methods and this implementation remove() - * limitations. - */ - public void testIteratorMethodsContract() { - Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator(); - while (iter.hasNext()) { - iter.next(); - } - - try { - iter.next(); - fail("next() unexpectedly returned element"); - } catch (NoSuchElementException x) { - // expected - } - - try { - iter.remove(); - fail("remove() shouldn't be implemented"); - } catch (UnsupportedOperationException x) { - // expected - } - } - - /** - * Test results of iterator comparing to content of well-known (prepared) - * small index. - */ - public void testIteratorReturnedValues1() { - Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator(); - assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next() - .name()); - assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next() - .name()); - assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next() - .name()); - assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next() - .name()); - assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next() - .name()); - assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next() - .name()); - assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next() - .name()); - assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next() - .name()); - assertFalse(iter.hasNext()); - } - - /** - * Compare offset from iterator entries with output of findOffset() method. - */ - public void testCompareEntriesOffsetsWithFindOffsets() { - for (MutableEntry me : smallIdx) { - assertEquals(smallIdx.findOffset(me.toObjectId()), me.getOffset()); - } - for (MutableEntry me : denseIdx) { - assertEquals(denseIdx.findOffset(me.toObjectId()), me.getOffset()); - } - } - - /** - * Test partial results of iterator comparing to content of well-known - * (prepared) dense index, that may need multi-level indexing. - */ - public void testIteratorReturnedValues2() { - Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator(); - while (!iter.next().name().equals( - "0a3d7772488b6b106fb62813c4d6d627918d9181")) { - // just iterating - } - assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next() - .name()); // same level-1 - assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next() - .name()); // same level-1 - assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next() - .name()); - } - -} diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTestCase.java new file mode 100644 index 0000000..cd69375 --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexTestCase.java @@ -0,0 +1,162 @@ +/* + * Copyright (C) 2008, Marek Zawirski <marek.zawirski@xxxxxxxxx> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Git Development Community nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.spearce.jgit.lib; + +import java.io.File; +import java.util.Iterator; +import java.util.NoSuchElementException; + +import org.spearce.jgit.errors.MissingObjectException; +import org.spearce.jgit.lib.PackIndex.MutableEntry; + +public abstract class PackIndexTestCase extends RepositoryTestCase { + + PackIndex smallIdx; + + PackIndex denseIdx; + + public void setUp() throws Exception { + super.setUp(); + smallIdx = PackIndex.open(getFileForPack34be9032()); + denseIdx = PackIndex.open(getFileForPackdf2982f28()); + } + + /** + * Return file with appropriate index version for prepared pack. + * + * @return file with index + */ + public abstract File getFileForPack34be9032(); + + /** + * Return file with appropriate index version for prepared pack. + * + * @return file with index + */ + public abstract File getFileForPackdf2982f28(); + + /** + * Verify CRC32 support. + * + * @throws MissingObjectException + * @throws UnsupportedOperationException + */ + public abstract void testCRC32() throws MissingObjectException, + UnsupportedOperationException; + + /** + * Test contracts of Iterator methods and this implementation remove() + * limitations. + */ + public void testIteratorMethodsContract() { + Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator(); + while (iter.hasNext()) { + iter.next(); + } + + try { + iter.next(); + fail("next() unexpectedly returned element"); + } catch (NoSuchElementException x) { + // expected + } + + try { + iter.remove(); + fail("remove() shouldn't be implemented"); + } catch (UnsupportedOperationException x) { + // expected + } + } + + /** + * Test results of iterator comparing to content of well-known (prepared) + * small index. + */ + public void testIteratorReturnedValues1() { + Iterator<PackIndex.MutableEntry> iter = smallIdx.iterator(); + assertEquals("4b825dc642cb6eb9a060e54bf8d69288fbee4904", iter.next() + .name()); + assertEquals("540a36d136cf413e4b064c2b0e0a4db60f77feab", iter.next() + .name()); + assertEquals("5b6e7c66c276e7610d4a73c70ec1a1f7c1003259", iter.next() + .name()); + assertEquals("6ff87c4664981e4397625791c8ea3bbb5f2279a3", iter.next() + .name()); + assertEquals("82c6b885ff600be425b4ea96dee75dca255b69e7", iter.next() + .name()); + assertEquals("902d5476fa249b7abc9d84c611577a81381f0327", iter.next() + .name()); + assertEquals("aabf2ffaec9b497f0950352b3e582d73035c2035", iter.next() + .name()); + assertEquals("c59759f143fb1fe21c197981df75a7ee00290799", iter.next() + .name()); + assertFalse(iter.hasNext()); + } + + /** + * Compare offset from iterator entries with output of findOffset() method. + */ + public void testCompareEntriesOffsetsWithFindOffsets() { + for (MutableEntry me : smallIdx) { + assertEquals(smallIdx.findOffset(me.toObjectId()), me.getOffset()); + } + for (MutableEntry me : denseIdx) { + assertEquals(denseIdx.findOffset(me.toObjectId()), me.getOffset()); + } + } + + /** + * Test partial results of iterator comparing to content of well-known + * (prepared) dense index, that may need multi-level indexing. + */ + public void testIteratorReturnedValues2() { + Iterator<PackIndex.MutableEntry> iter = denseIdx.iterator(); + while (!iter.next().name().equals( + "0a3d7772488b6b106fb62813c4d6d627918d9181")) { + // just iterating + } + assertEquals("1004d0d7ac26fbf63050a234c9b88a46075719d3", iter.next() + .name()); // same level-1 + assertEquals("10da5895682013006950e7da534b705252b03be6", iter.next() + .name()); // same level-1 + assertEquals("1203b03dc816ccbb67773f28b3c19318654b0bc8", iter.next() + .name()); + } + +} diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java index 645e054..20290aa 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV1Test.java @@ -42,7 +42,7 @@ import org.spearce.jgit.errors.MissingObjectException; import org.spearce.jgit.util.JGitTestUtil; -public class PackIndexV1Test extends PackIndexTest { +public class PackIndexV1Test extends PackIndexTestCase { @Override public File getFileForPack34be9032() { return JGitTestUtil.getTestResourceFile( diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java index d95937c..beed522 100644 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/lib/PackIndexV2Test.java @@ -42,7 +42,7 @@ import org.spearce.jgit.errors.MissingObjectException; import org.spearce.jgit.util.JGitTestUtil; -public class PackIndexV2Test extends PackIndexTest { +public class PackIndexV2Test extends PackIndexTestCase { @Override public File getFileForPack34be9032() { return JGitTestUtil.getTestResourceFile( diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTest.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTest.java new file mode 100644 index 0000000..e8b54fa --- /dev/null +++ b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTest.java @@ -0,0 +1,269 @@ +/* + * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> + * Copyright (C) 2008, Shawn O. Pearce <spearce@xxxxxxxxxxx> + * + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or + * without modification, are permitted provided that the following + * conditions are met: + * + * - Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * + * - Redistributions in binary form must reproduce the above + * copyright notice, this list of conditions and the following + * disclaimer in the documentation and/or other materials provided + * with the distribution. + * + * - Neither the name of the Git Development Community nor the + * names of its contributors may be used to endorse or promote + * products derived from this software without specific prior + * written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND + * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, + * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR + * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, + * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF + * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +package org.spearce.jgit.transport; + +import junit.framework.TestCase; + +import org.spearce.jgit.lib.Ref; + +public class RefSpecTest extends TestCase { + public void testMasterMaster() { + final String sn = "refs/heads/master"; + final RefSpec rs = new RefSpec(sn + ":" + sn); + assertFalse(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals(sn, rs.getSource()); + assertEquals(sn, rs.getDestination()); + assertEquals(sn + ":" + sn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r = new Ref(Ref.Storage.LOOSE, sn, null); + assertTrue(rs.matchSource(r)); + assertTrue(rs.matchDestination(r)); + assertSame(rs, rs.expandFromSource(r)); + + r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testSplitLastColon() { + final String lhs = ":m:a:i:n:t"; + final String rhs = "refs/heads/maint"; + final RefSpec rs = new RefSpec(lhs + ":" + rhs); + assertFalse(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals(lhs, rs.getSource()); + assertEquals(rhs, rs.getDestination()); + assertEquals(lhs + ":" + rhs, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + } + + public void testForceMasterMaster() { + final String sn = "refs/heads/master"; + final RefSpec rs = new RefSpec("+" + sn + ":" + sn); + assertTrue(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals(sn, rs.getSource()); + assertEquals(sn, rs.getDestination()); + assertEquals("+" + sn + ":" + sn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r = new Ref(Ref.Storage.LOOSE, sn, null); + assertTrue(rs.matchSource(r)); + assertTrue(rs.matchDestination(r)); + assertSame(rs, rs.expandFromSource(r)); + + r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testMaster() { + final String sn = "refs/heads/master"; + final RefSpec rs = new RefSpec(sn); + assertFalse(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals(sn, rs.getSource()); + assertNull(rs.getDestination()); + assertEquals(sn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r = new Ref(Ref.Storage.LOOSE, sn, null); + assertTrue(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + assertSame(rs, rs.expandFromSource(r)); + + r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testForceMaster() { + final String sn = "refs/heads/master"; + final RefSpec rs = new RefSpec("+" + sn); + assertTrue(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals(sn, rs.getSource()); + assertNull(rs.getDestination()); + assertEquals("+" + sn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r = new Ref(Ref.Storage.LOOSE, sn, null); + assertTrue(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + assertSame(rs, rs.expandFromSource(r)); + + r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testDeleteMaster() { + final String sn = "refs/heads/master"; + final RefSpec rs = new RefSpec(":" + sn); + assertFalse(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertNull(rs.getSource()); + assertEquals(sn, rs.getDestination()); + assertEquals(":" + sn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r = new Ref(Ref.Storage.LOOSE, sn, null); + assertFalse(rs.matchSource(r)); + assertTrue(rs.matchDestination(r)); + assertSame(rs, rs.expandFromSource(r)); + + r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testForceRemotesOrigin() { + final String srcn = "refs/heads/*"; + final String dstn = "refs/remotes/origin/*"; + final RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); + assertTrue(rs.isForceUpdate()); + assertTrue(rs.isWildcard()); + assertEquals(srcn, rs.getSource()); + assertEquals(dstn, rs.getDestination()); + assertEquals("+" + srcn + ":" + dstn, rs.toString()); + assertEquals(rs, new RefSpec(rs.toString())); + + Ref r; + RefSpec expanded; + + r = new Ref(Ref.Storage.LOOSE, "refs/heads/master", null); + assertTrue(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + expanded = rs.expandFromSource(r); + assertNotSame(rs, expanded); + assertTrue(expanded.isForceUpdate()); + assertFalse(expanded.isWildcard()); + assertEquals(r.getName(), expanded.getSource()); + assertEquals("refs/remotes/origin/master", expanded.getDestination()); + + r = new Ref(Ref.Storage.LOOSE, "refs/remotes/origin/next", null); + assertFalse(rs.matchSource(r)); + assertTrue(rs.matchDestination(r)); + + r = new Ref(Ref.Storage.LOOSE, "refs/tags/v1.0", null); + assertFalse(rs.matchSource(r)); + assertFalse(rs.matchDestination(r)); + } + + public void testCreateEmpty() { + final RefSpec rs = new RefSpec(); + assertFalse(rs.isForceUpdate()); + assertFalse(rs.isWildcard()); + assertEquals("HEAD", rs.getSource()); + assertNull(rs.getDestination()); + assertEquals("HEAD", rs.toString()); + } + + public void testSetForceUpdate() { + final String s = "refs/heads/*:refs/remotes/origin/*"; + final RefSpec a = new RefSpec(s); + assertFalse(a.isForceUpdate()); + RefSpec b = a.setForceUpdate(true); + assertNotSame(a, b); + assertFalse(a.isForceUpdate()); + assertTrue(b.isForceUpdate()); + assertEquals(s, a.toString()); + assertEquals("+" + s, b.toString()); + } + + public void testSetSource() { + final RefSpec a = new RefSpec(); + final RefSpec b = a.setSource("refs/heads/master"); + assertNotSame(a, b); + assertEquals("HEAD", a.toString()); + assertEquals("refs/heads/master", b.toString()); + } + + public void testSetDestination() { + final RefSpec a = new RefSpec(); + final RefSpec b = a.setDestination("refs/heads/master"); + assertNotSame(a, b); + assertEquals("HEAD", a.toString()); + assertEquals("HEAD:refs/heads/master", b.toString()); + } + + public void testSetDestination_SourceNull() { + final RefSpec a = new RefSpec(); + RefSpec b; + + b = a.setDestination("refs/heads/master"); + b = b.setSource(null); + assertNotSame(a, b); + assertEquals("HEAD", a.toString()); + assertEquals(":refs/heads/master", b.toString()); + } + + public void testSetSourceDestination() { + final RefSpec a = new RefSpec(); + final RefSpec b; + b = a.setSourceDestination("refs/heads/*", "refs/remotes/origin/*"); + assertNotSame(a, b); + assertEquals("HEAD", a.toString()); + assertEquals("refs/heads/*:refs/remotes/origin/*", b.toString()); + } + + public void testExpandFromDestination_NonWildcard() { + final String src = "refs/heads/master"; + final String dst = "refs/remotes/origin/master"; + final RefSpec a = new RefSpec(src + ":" + dst); + final RefSpec r = a.expandFromDestination(dst); + assertSame(a, r); + assertFalse(r.isWildcard()); + assertEquals(src, r.getSource()); + assertEquals(dst, r.getDestination()); + } + + public void testExpandFromDestination_Wildcard() { + final String src = "refs/heads/master"; + final String dst = "refs/remotes/origin/master"; + final RefSpec a = new RefSpec("refs/heads/*:refs/remotes/origin/*"); + final RefSpec r = a.expandFromDestination(dst); + assertNotSame(a, r); + assertFalse(r.isWildcard()); + assertEquals(src, r.getSource()); + assertEquals(dst, r.getDestination()); + } +} diff --git a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java b/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java deleted file mode 100644 index 2f7214c..0000000 --- a/org.spearce.jgit.test/tst/org/spearce/jgit/transport/RefSpecTestCase.java +++ /dev/null @@ -1,269 +0,0 @@ -/* - * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@xxxxxxxxxx> - * Copyright (C) 2008, Shawn O. Pearce <spearce@xxxxxxxxxxx> - * - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or - * without modification, are permitted provided that the following - * conditions are met: - * - * - Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * - * - Redistributions in binary form must reproduce the above - * copyright notice, this list of conditions and the following - * disclaimer in the documentation and/or other materials provided - * with the distribution. - * - * - Neither the name of the Git Development Community nor the - * names of its contributors may be used to endorse or promote - * products derived from this software without specific prior - * written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND - * CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, - * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT - * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER - * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, - * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) - * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF - * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -package org.spearce.jgit.transport; - -import junit.framework.TestCase; - -import org.spearce.jgit.lib.Ref; - -public class RefSpecTestCase extends TestCase { - public void testMasterMaster() { - final String sn = "refs/heads/master"; - final RefSpec rs = new RefSpec(sn + ":" + sn); - assertFalse(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals(sn, rs.getSource()); - assertEquals(sn, rs.getDestination()); - assertEquals(sn + ":" + sn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r = new Ref(Ref.Storage.LOOSE, sn, null); - assertTrue(rs.matchSource(r)); - assertTrue(rs.matchDestination(r)); - assertSame(rs, rs.expandFromSource(r)); - - r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testSplitLastColon() { - final String lhs = ":m:a:i:n:t"; - final String rhs = "refs/heads/maint"; - final RefSpec rs = new RefSpec(lhs + ":" + rhs); - assertFalse(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals(lhs, rs.getSource()); - assertEquals(rhs, rs.getDestination()); - assertEquals(lhs + ":" + rhs, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - } - - public void testForceMasterMaster() { - final String sn = "refs/heads/master"; - final RefSpec rs = new RefSpec("+" + sn + ":" + sn); - assertTrue(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals(sn, rs.getSource()); - assertEquals(sn, rs.getDestination()); - assertEquals("+" + sn + ":" + sn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r = new Ref(Ref.Storage.LOOSE, sn, null); - assertTrue(rs.matchSource(r)); - assertTrue(rs.matchDestination(r)); - assertSame(rs, rs.expandFromSource(r)); - - r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testMaster() { - final String sn = "refs/heads/master"; - final RefSpec rs = new RefSpec(sn); - assertFalse(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals(sn, rs.getSource()); - assertNull(rs.getDestination()); - assertEquals(sn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r = new Ref(Ref.Storage.LOOSE, sn, null); - assertTrue(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - assertSame(rs, rs.expandFromSource(r)); - - r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testForceMaster() { - final String sn = "refs/heads/master"; - final RefSpec rs = new RefSpec("+" + sn); - assertTrue(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals(sn, rs.getSource()); - assertNull(rs.getDestination()); - assertEquals("+" + sn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r = new Ref(Ref.Storage.LOOSE, sn, null); - assertTrue(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - assertSame(rs, rs.expandFromSource(r)); - - r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testDeleteMaster() { - final String sn = "refs/heads/master"; - final RefSpec rs = new RefSpec(":" + sn); - assertFalse(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertNull(rs.getSource()); - assertEquals(sn, rs.getDestination()); - assertEquals(":" + sn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r = new Ref(Ref.Storage.LOOSE, sn, null); - assertFalse(rs.matchSource(r)); - assertTrue(rs.matchDestination(r)); - assertSame(rs, rs.expandFromSource(r)); - - r = new Ref(Ref.Storage.LOOSE, sn + "-and-more", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testForceRemotesOrigin() { - final String srcn = "refs/heads/*"; - final String dstn = "refs/remotes/origin/*"; - final RefSpec rs = new RefSpec("+" + srcn + ":" + dstn); - assertTrue(rs.isForceUpdate()); - assertTrue(rs.isWildcard()); - assertEquals(srcn, rs.getSource()); - assertEquals(dstn, rs.getDestination()); - assertEquals("+" + srcn + ":" + dstn, rs.toString()); - assertEquals(rs, new RefSpec(rs.toString())); - - Ref r; - RefSpec expanded; - - r = new Ref(Ref.Storage.LOOSE, "refs/heads/master", null); - assertTrue(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - expanded = rs.expandFromSource(r); - assertNotSame(rs, expanded); - assertTrue(expanded.isForceUpdate()); - assertFalse(expanded.isWildcard()); - assertEquals(r.getName(), expanded.getSource()); - assertEquals("refs/remotes/origin/master", expanded.getDestination()); - - r = new Ref(Ref.Storage.LOOSE, "refs/remotes/origin/next", null); - assertFalse(rs.matchSource(r)); - assertTrue(rs.matchDestination(r)); - - r = new Ref(Ref.Storage.LOOSE, "refs/tags/v1.0", null); - assertFalse(rs.matchSource(r)); - assertFalse(rs.matchDestination(r)); - } - - public void testCreateEmpty() { - final RefSpec rs = new RefSpec(); - assertFalse(rs.isForceUpdate()); - assertFalse(rs.isWildcard()); - assertEquals("HEAD", rs.getSource()); - assertNull(rs.getDestination()); - assertEquals("HEAD", rs.toString()); - } - - public void testSetForceUpdate() { - final String s = "refs/heads/*:refs/remotes/origin/*"; - final RefSpec a = new RefSpec(s); - assertFalse(a.isForceUpdate()); - RefSpec b = a.setForceUpdate(true); - assertNotSame(a, b); - assertFalse(a.isForceUpdate()); - assertTrue(b.isForceUpdate()); - assertEquals(s, a.toString()); - assertEquals("+" + s, b.toString()); - } - - public void testSetSource() { - final RefSpec a = new RefSpec(); - final RefSpec b = a.setSource("refs/heads/master"); - assertNotSame(a, b); - assertEquals("HEAD", a.toString()); - assertEquals("refs/heads/master", b.toString()); - } - - public void testSetDestination() { - final RefSpec a = new RefSpec(); - final RefSpec b = a.setDestination("refs/heads/master"); - assertNotSame(a, b); - assertEquals("HEAD", a.toString()); - assertEquals("HEAD:refs/heads/master", b.toString()); - } - - public void testSetDestination_SourceNull() { - final RefSpec a = new RefSpec(); - RefSpec b; - - b = a.setDestination("refs/heads/master"); - b = b.setSource(null); - assertNotSame(a, b); - assertEquals("HEAD", a.toString()); - assertEquals(":refs/heads/master", b.toString()); - } - - public void testSetSourceDestination() { - final RefSpec a = new RefSpec(); - final RefSpec b; - b = a.setSourceDestination("refs/heads/*", "refs/remotes/origin/*"); - assertNotSame(a, b); - assertEquals("HEAD", a.toString()); - assertEquals("refs/heads/*:refs/remotes/origin/*", b.toString()); - } - - public void testExpandFromDestination_NonWildcard() { - final String src = "refs/heads/master"; - final String dst = "refs/remotes/origin/master"; - final RefSpec a = new RefSpec(src + ":" + dst); - final RefSpec r = a.expandFromDestination(dst); - assertSame(a, r); - assertFalse(r.isWildcard()); - assertEquals(src, r.getSource()); - assertEquals(dst, r.getDestination()); - } - - public void testExpandFromDestination_Wildcard() { - final String src = "refs/heads/master"; - final String dst = "refs/remotes/origin/master"; - final RefSpec a = new RefSpec("refs/heads/*:refs/remotes/origin/*"); - final RefSpec r = a.expandFromDestination(dst); - assertNotSame(a, r); - assertFalse(r.isWildcard()); - assertEquals(src, r.getSource()); - assertEquals(dst, r.getDestination()); - } -} -- 1.6.3.msysgit.0 ��.n��������+%������w��{.n��������n�r������&��z�ޗ�zf���h���~����������_��+v���)ߣ�m