diff options
author | Mykola Nikishov <mn@mn.com.ua> | 2009-12-18 01:03:51 +0200 |
---|---|---|
committer | Robin Rosenberg <robin.rosenberg@dewire.com> | 2009-12-19 00:47:06 +0100 |
commit | 21b6f3434ebc84f493405d890a3768d55375a721 (patch) | |
tree | 053f332f953824628686addd90b415d9a9650395 /org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java | |
parent | f8f75f8a52a30cf2a7d793ba15cd74410ba64534 (diff) | |
download | jgit-21b6f3434ebc84f493405d890a3768d55375a721.tar.gz jgit-21b6f3434ebc84f493405d890a3768d55375a721.zip |
Method to get a 'humanish' name from a path
Change-Id: Iec0688232bd59d4626111d77633109918e8e1df3
Signed-off-by: Mykola Nikishov <mn@mn.com.ua>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
Diffstat (limited to 'org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java')
-rw-r--r-- | org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java | 122 |
1 files changed, 122 insertions, 0 deletions
diff --git a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java index 2598fdc1f5..d2d37a7edc 100644 --- a/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java +++ b/org.eclipse.jgit.test/tst/org/eclipse/jgit/transport/URIishTest.java @@ -1,4 +1,5 @@ /* + * Copyright (C) 2009, Mykola Nikishov <mn@mn.com.ua> * Copyright (C) 2008, Robin Rosenberg <robin.rosenberg@dewire.com> * Copyright (C) 2008, Shawn O. Pearce <spearce@spearce.org> * and other copyright owners as documented in the project's IP log. @@ -44,10 +45,14 @@ package org.eclipse.jgit.transport; +import java.net.URISyntaxException; + import junit.framework.TestCase; public class URIishTest extends TestCase { + private static final String GIT_SCHEME = "git://"; + public void testUnixFile() throws Exception { final String str = "/home/m y"; URIish u = new URIish(str); @@ -244,4 +249,121 @@ public class URIishTest extends TestCase { assertEquals(u.setPass(null).toPrivateString(), u.toString()); assertEquals(u, new URIish(str)); } + + public void testGetNullHumanishName() { + try { + new URIish().getHumanishName(); + fail("path must be not null"); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testGetEmptyHumanishName() throws URISyntaxException { + try { + new URIish(GIT_SCHEME).getHumanishName(); + fail("empty path is useless"); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testGetAbsEmptyHumanishName() { + try { + new URIish().getHumanishName(); + fail("empty path is useless"); + } catch (IllegalArgumentException e) { + // expected + } + } + + public void testGetValidWithEmptySlashDotGitHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/a/b/.git").getHumanishName(); + assertEquals("b", humanishName); + } + + public void testGetWithSlashDotGitHumanishName() throws URISyntaxException { + assertEquals("", new URIish("/.git").getHumanishName()); + } + + public void testGetTwoSlashesDotGitHumanishName() throws URISyntaxException { + assertEquals("", new URIish("/.git").getHumanishName()); + } + + public void testGetValidHumanishName() throws IllegalArgumentException, + URISyntaxException { + String humanishName = new URIish(GIT_SCHEME + "abc").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetValidSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish(GIT_SCHEME + "abc/").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetSlashValidSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/abc/").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetSlashValidSlashDotGitSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/abc/.git").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetSlashSlashDotGitSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + final String humanishName = new URIish(GIT_SCHEME + "/abc//.git") + .getHumanishName(); + assertEquals("may return an empty humanish name", "", humanishName); + } + + public void testGetSlashesValidSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/a/b/c/").getHumanishName(); + assertEquals("c", humanishName); + } + + public void testGetValidDotGitHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish(GIT_SCHEME + "abc.git") + .getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetValidDotGitSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish(GIT_SCHEME + "abc.git/") + .getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetValidWithSlashDotGitHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/abc.git").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetValidWithSlashDotGitSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/abc.git/").getHumanishName(); + assertEquals("abc", humanishName); + } + + public void testGetValidWithSlashesDotGitHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/a/b/c.git").getHumanishName(); + assertEquals("c", humanishName); + } + + public void testGetValidWithSlashesDotGitSlashHumanishName() + throws IllegalArgumentException, URISyntaxException { + String humanishName = new URIish("/a/b/c.git/").getHumanishName(); + assertEquals("c", humanishName); + } + } |