diff options
author | David Pursehouse <david.pursehouse@gmail.com> | 2019-06-02 11:04:59 +0900 |
---|---|---|
committer | David Pursehouse <david.pursehouse@gmail.com> | 2019-06-02 18:32:59 +0900 |
commit | 7377b8dd01b56caa85b47e5b2da32a9b784315d3 (patch) | |
tree | a291f75e9af837c68b35f612cabf54cedd70957a /org.eclipse.jgit.test/tst/org/eclipse/jgit | |
parent | 07a07a75d6c22458bb94dffc3498a6472222026f (diff) | |
download | jgit-7377b8dd01b56caa85b47e5b2da32a9b784315d3.tar.gz jgit-7377b8dd01b56caa85b47e5b2da32a9b784315d3.zip |
Replace trivial reference comparison of PacketLineIn.{DELIM,END}
Replace reference comparisons of PacketLineIn's DELIM and END strings
with usage of the helper methods isDelimiter() and isEnd().
Change-Id: I52dcfc4ee9097f1bd6970601c716701847d9eebd
Signed-off-by: David Pursehouse <david.pursehouse@gmail.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit')
5 files changed, 49 insertions, 50 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java index 28a9c03ecc..42553147fb 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV0ParserTest.java @@ -64,9 +64,9 @@ public class ProtocolV0ParserTest { ByteArrayOutputStream send = new ByteArrayOutputStream(); PacketLineOut pckOut = new PacketLineOut(send); for (String line : inputLines) { - if (line == PacketLineIn.END) { + if (PacketLineIn.isEnd(line)) { pckOut.end(); - } else if (line == PacketLineIn.DELIM) { + } else if (PacketLineIn.isDelimiter(line)) { pckOut.writeDelim(); } else { pckOut.writeString(line); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java index 7d6e300fd3..43da170b69 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ProtocolV2ParserTest.java @@ -123,9 +123,9 @@ public class ProtocolV2ParserTest { ByteArrayOutputStream send = new ByteArrayOutputStream(); PacketLineOut pckOut = new PacketLineOut(send); for (String line : inputLines) { - if (line == PacketLineIn.END) { + if (PacketLineIn.isEnd(line)) { pckOut.end(); - } else if (line == PacketLineIn.DELIM) { + } else if (PacketLineIn.isDelimiter(line)) { pckOut.writeDelim(); } else { pckOut.writeString(line); diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java index 50c8a29543..5d208eea73 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/ReceivePackAdvertiseRefsHookTest.java @@ -306,11 +306,11 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); assertEquals("unpack error Missing commit " + P.name(), r.readString()); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } private static void receive(final ReceivePack rp, @@ -366,13 +366,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); assertEquals("unpack error Missing blob " + b.name(), r.readString()); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } } @@ -419,13 +419,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); assertEquals("unpack error Missing blob " + b.name(), r.readString()); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } } @@ -473,13 +473,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); assertEquals("unpack error Missing blob " + n.name(), r.readString()); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } } @@ -504,13 +504,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); String errorLine = r.readString(); assertTrue(errorLine.startsWith("unpack error")); assertTrue(errorLine.contains("Invalid submodule URL '-")); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } private TemporaryBuffer.Heap setupSourceRepoInvalidGitmodules() @@ -589,13 +589,13 @@ public class ReceivePackAdvertiseRefsHookTest extends LocalDiskRepositoryTestCas int nul = master.indexOf('\0'); assertTrue("has capability list", nul > 0); assertEquals(B.name() + ' ' + R_MASTER, master.substring(0, nul)); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); assertEquals("unpack error Missing tree " + t.name(), r.readString()); assertEquals("ng refs/heads/s n/a (unpacker error)", r.readString()); - assertSame(PacketLineIn.END, r.readString()); + assertTrue(PacketLineIn.isEnd(r.readString())); } } diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java index ce69adf9c1..ccb548d919 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/RefAdvertiserTest.java @@ -45,7 +45,7 @@ package org.eclipse.jgit.transport; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertSame; +import static org.junit.Assert.assertTrue; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; @@ -95,7 +95,7 @@ public class RefAdvertiserTest { assertEquals(id(3).name() + " refs/Iñtërnâtiônàlizætiøn☃💩\n", s); s = pckIn.readStringRaw(); - assertSame(PacketLineIn.END, s); + assertTrue(PacketLineIn.isEnd(s)); } private static ObjectId id(int i) { diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java index 3ead31dbd7..0ad1e2152c 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/UploadPackTest.java @@ -4,7 +4,6 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasItems; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.theInstance; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -428,9 +427,9 @@ public class UploadPackTest { try (ByteArrayOutputStream send = new ByteArrayOutputStream()) { PacketLineOut pckOut = new PacketLineOut(send); for (String line : inputLines) { - if (line == PacketLineIn.END) { + if (PacketLineIn.isEnd(line)) { pckOut.end(); - } else if (line == PacketLineIn.DELIM) { + } else if (PacketLineIn.isDelimiter(line)) { pckOut.writeDelim(); } else { pckOut.writeString(line); @@ -453,7 +452,7 @@ public class UploadPackTest { PacketLineIn pckIn = new PacketLineIn(recvStream); // drain capabilities - while (pckIn.readString() != PacketLineIn.END) { + while (!PacketLineIn.isEnd(pckIn.readString())) { // do nothing } return recvStream; @@ -504,7 +503,7 @@ public class UploadPackTest { // and additional capabilities to be added to existing // commands without requiring test changes. hasItems("ls-refs", "fetch=shallow", "server-option")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -521,7 +520,7 @@ public class UploadPackTest { // TODO(jonathantanmy) This check overspecifies the // order of the capabilities of "fetch". hasItems("ls-refs", "fetch=filter shallow", "server-option")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -539,7 +538,7 @@ public class UploadPackTest { // order of the capabilities of "fetch". hasItems("ls-refs", "fetch=ref-in-want shallow", "server-option")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -554,7 +553,7 @@ public class UploadPackTest { Arrays.asList(pckIn.readString(), pckIn.readString(), pckIn.readString()), hasItems("ls-refs", "fetch=shallow", "server-option")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -570,7 +569,7 @@ public class UploadPackTest { Arrays.asList(pckIn.readString(), pckIn.readString(), pckIn.readString()), hasItems("ls-refs", "fetch=shallow", "server-option")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -598,7 +597,7 @@ public class UploadPackTest { assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD")); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master")); assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -615,7 +614,7 @@ public class UploadPackTest { assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD symref-target:refs/heads/master")); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master")); assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -635,7 +634,7 @@ public class UploadPackTest { pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag peeled:" + tip.toObjectId().getName())); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -657,11 +656,11 @@ public class UploadPackTest { pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag peeled:" + tip.toObjectId().getName())); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " HEAD")); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master")); assertThat(pckIn.readString(), is(tag.toObjectId().getName() + " refs/tags/tag")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -681,7 +680,7 @@ public class UploadPackTest { assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master")); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -700,7 +699,7 @@ public class UploadPackTest { assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/master")); assertThat(pckIn.readString(), is(tip.toObjectId().getName() + " refs/heads/other")); - assertTrue(pckIn.readString() == PacketLineIn.END); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -908,7 +907,7 @@ public class UploadPackTest { assertThat(pckIn.readString(), is("acknowledgments")); assertThat(pckIn.readString(), is("ACK " + fooParent.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.END)); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -937,7 +936,7 @@ public class UploadPackTest { "ACK " + fooParent.toObjectId().getName(), "ACK " + barParent.toObjectId().getName())); assertThat(pckIn.readString(), is("ready")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); assertFalse(client.getObjectDatabase().has(fooParent.toObjectId())); @@ -1160,7 +1159,7 @@ public class UploadPackTest { PacketLineIn pckIn = new PacketLineIn(recvStream); assertThat(pckIn.readString(), is("shallow-info")); assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); assertTrue(client.getObjectDatabase().has(child.toObjectId())); @@ -1198,7 +1197,7 @@ public class UploadPackTest { // sent only if a packfile is sent. assertThat(pckIn.readString(), is("acknowledgments")); assertThat(pckIn.readString(), is("NAK")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.END)); + assertTrue(PacketLineIn.isEnd(pckIn.readString())); } @Test @@ -1237,7 +1236,7 @@ public class UploadPackTest { // later than the given deepen-since time. assertThat(pckIn.readString(), is("unshallow " + boundary.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1286,7 +1285,7 @@ public class UploadPackTest { "shallow " + child1.toObjectId().getName(), "shallow " + child2.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1353,7 +1352,7 @@ public class UploadPackTest { // "three" is unshallow because its parent "two" is now available. assertThat(pckIn.readString(), is("unshallow " + three.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1413,7 +1412,7 @@ public class UploadPackTest { PacketLineIn pckIn = new PacketLineIn(recvStream); assertThat(pckIn.readString(), is("shallow-info")); assertThat(pckIn.readString(), is("shallow " + three.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); assertFalse(client.getObjectDatabase().has(one.toObjectId())); @@ -1455,7 +1454,7 @@ public class UploadPackTest { "shallow " + child1.toObjectId().getName(), "shallow " + child2.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1899,7 +1898,7 @@ public class UploadPackTest { hasItems( one.toObjectId().getName() + " refs/heads/one", two.toObjectId().getName() + " refs/heads/two")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1955,7 +1954,7 @@ public class UploadPackTest { assertThat( pckIn.readString(), is(one.toObjectId().getName() + " refs/heads/one")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); @@ -1987,7 +1986,7 @@ public class UploadPackTest { assertThat( pckIn.readString(), is(one.toObjectId().getName() + " refs/heads/one")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); // ... but the client does not need the object itself. assertThat(pckIn.readString(), is("packfile")); @@ -2015,10 +2014,10 @@ public class UploadPackTest { // shallow-info appears first, then wanted-refs. assertThat(pckIn.readString(), is("shallow-info")); assertThat(pckIn.readString(), is("shallow " + child.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("wanted-refs")); assertThat(pckIn.readString(), is(child.toObjectId().getName() + " refs/heads/branch1")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); assertTrue(client.getObjectDatabase().has(child.toObjectId())); @@ -2050,11 +2049,11 @@ public class UploadPackTest { is("shallow " + one.toObjectId().getName())); assertThat(pckIn.readString(), is("unshallow " + two.toObjectId().getName())); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("wanted-refs")); assertThat(pckIn.readString(), is(three.toObjectId().getName() + " refs/heads/three")); - assertThat(pckIn.readString(), theInstance(PacketLineIn.DELIM)); + assertTrue(PacketLineIn.isDelimiter(pckIn.readString())); assertThat(pckIn.readString(), is("packfile")); parsePack(recvStream); |