]> source.dussan.org Git - jgit.git/commitdiff
URIish: add a test for equals and hashcode methods 15/114715/3
authorMatthias Sohn <matthias.sohn@sap.com>
Sat, 23 Dec 2017 21:09:43 +0000 (22:09 +0100)
committerDavid Pursehouse <david.pursehouse@gmail.com>
Wed, 14 Feb 2018 00:00:40 +0000 (19:00 -0500)
Change-Id: I5727ac1757dca0d63631401bcb074ee8f58ce082
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java

index 1eb218c86565e089c679d884ae725ea71b941ac9..39cd71947d732102dcf6b56eeaca132d97fbdc41 100644 (file)
@@ -1052,4 +1052,32 @@ public class URIishTest {
                assertEquals("", u.getPath());
                assertEquals(str, u.toString());
        }
+
+       @Test
+       public void testEqualsHashcode() throws Exception
+       {
+               String[] urls = { "http://user:pass@example.com:8081/path", "../x",
+                               "ssh://x.y:23/z", "ssh://example.com:/path", "D:\\m y",
+                               "\\\\some\\place", "http://localhost:1234",
+                               "user@example.com:some/p ath", "a",
+                               "http://user:pwd@example.com:8081/path",
+                               "http://user:pass@another.com:8081/path",
+                               "http://user:pass@example.com:8083/path" };
+               URIish w = new URIish("http://user:pass@example.com:8081/path/x");
+               for (String s : urls) {
+                       URIish u = new URIish(s);
+                       URIish v = new URIish(s);
+                       assertTrue(u.equals(v));
+                       assertTrue(v.equals(u));
+
+                       assertFalse(u.equals(null));
+                       assertFalse(u.equals(new Object()));
+                       assertFalse(new Object().equals(u));
+                       assertFalse(u.equals(w));
+                       assertFalse(w.equals(u));
+
+                       assertTrue(u.hashCode() == v.hashCode());
+                       assertFalse(u.hashCode() == new Object().hashCode());
+               }
+       }
 }