diff options
Diffstat (limited to 'src/test/java/com/gitblit/tests/ModelUtilsTest.java')
-rw-r--r-- | src/test/java/com/gitblit/tests/ModelUtilsTest.java | 82 |
1 files changed, 23 insertions, 59 deletions
diff --git a/src/test/java/com/gitblit/tests/ModelUtilsTest.java b/src/test/java/com/gitblit/tests/ModelUtilsTest.java index 988f681c..95743bba 100644 --- a/src/test/java/com/gitblit/tests/ModelUtilsTest.java +++ b/src/test/java/com/gitblit/tests/ModelUtilsTest.java @@ -4,48 +4,25 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; -import java.util.HashMap; -import java.util.Map; - import org.junit.After; import org.junit.Test; -import com.gitblit.Keys; -import com.gitblit.tests.mock.MemorySettings; +import com.gitblit.Constants; import com.gitblit.utils.ModelUtils; public class ModelUtilsTest { - private static final String DEFAULT_USER_REPO_PREFIX = "~"; - - private static final Map<String, Object> backingMap = new HashMap<String, Object>(); - private static final MemorySettings ms = new MemorySettings(backingMap); - - - private static void setPrefix(String prefix) - { - backingMap.put(Keys.git.userRepositoryPrefix, prefix); - } - - - private static void setRepoPrefix(String prefix) - { - backingMap.put(Keys.git.userRepositoryPrefix, prefix); - ModelUtils.setUserRepoPrefix(ms); - } - - @After public void resetPrefix() { - setRepoPrefix(DEFAULT_USER_REPO_PREFIX); + ModelUtils.setUserRepoPrefix(null); } @Test public void testGetUserRepoPrefix() { - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix()); } @@ -53,38 +30,25 @@ public class ModelUtilsTest { public void testSetUserRepoPrefix() { - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix()); - setPrefix("@"); - ModelUtils.setUserRepoPrefix(ms); + ModelUtils.setUserRepoPrefix("@"); assertEquals("@", ModelUtils.getUserRepoPrefix()); - backingMap.remove(Keys.git.userRepositoryPrefix); - ModelUtils.setUserRepoPrefix(ms); - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); + ModelUtils.setUserRepoPrefix(""); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix()); - setPrefix("user/"); - ModelUtils.setUserRepoPrefix(ms); + ModelUtils.setUserRepoPrefix("user/"); assertEquals("user/", ModelUtils.getUserRepoPrefix()); - setPrefix(""); - ModelUtils.setUserRepoPrefix(ms); - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); - - setPrefix("u_"); - ModelUtils.setUserRepoPrefix(ms); + ModelUtils.setUserRepoPrefix("u_"); assertEquals("u_", ModelUtils.getUserRepoPrefix()); ModelUtils.setUserRepoPrefix(null); - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX, ModelUtils.getUserRepoPrefix()); - setPrefix("/somedir/otherdir/"); - ModelUtils.setUserRepoPrefix(ms); + ModelUtils.setUserRepoPrefix("/somedir/otherdir/"); assertEquals("somedir/otherdir/", ModelUtils.getUserRepoPrefix()); - - setPrefix(DEFAULT_USER_REPO_PREFIX); - ModelUtils.setUserRepoPrefix(ms); - assertEquals(DEFAULT_USER_REPO_PREFIX, ModelUtils.getUserRepoPrefix()); } @@ -92,12 +56,12 @@ public class ModelUtilsTest { public void testGetPersonalPath() { String username = "rob"; - assertEquals(DEFAULT_USER_REPO_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username)); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username)); username = "James"; - assertEquals(DEFAULT_USER_REPO_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username)); + assertEquals(Constants.DEFAULT_USER_REPOSITORY_PREFIX+username.toLowerCase(), ModelUtils.getPersonalPath(username)); - setRepoPrefix("usr/"); + ModelUtils.setUserRepoPrefix("usr/"); username = "noMan"; assertEquals("usr/"+username.toLowerCase(), ModelUtils.getPersonalPath(username)); } @@ -106,17 +70,17 @@ public class ModelUtilsTest { @Test public void testIsPersonalRepository() { - String reponame = DEFAULT_USER_REPO_PREFIX + "one"; + String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "one"; assertTrue(ModelUtils.isPersonalRepository(reponame)); reponame = "none"; assertFalse(ModelUtils.isPersonalRepository(reponame)); - setRepoPrefix("@@"); + ModelUtils.setUserRepoPrefix("@@"); reponame = "@@two"; assertTrue(ModelUtils.isPersonalRepository(reponame)); - setRepoPrefix("users/"); + ModelUtils.setUserRepoPrefix("users/"); reponame = "users/three"; assertTrue(ModelUtils.isPersonalRepository(reponame)); @@ -128,18 +92,18 @@ public class ModelUtilsTest { @Test public void testIsUsersPersonalRepository() { - String reponame = DEFAULT_USER_REPO_PREFIX + "lynn"; + String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "lynn"; assertTrue(ModelUtils.isUsersPersonalRepository("lynn", reponame)); reponame = "prjB"; assertFalse(ModelUtils.isUsersPersonalRepository("lynn", reponame)); - setRepoPrefix("@@"); + ModelUtils.setUserRepoPrefix("@@"); reponame = "@@newton"; assertTrue(ModelUtils.isUsersPersonalRepository("newton", reponame)); assertFalse(ModelUtils.isUsersPersonalRepository("hertz", reponame)); - setRepoPrefix("users/"); + ModelUtils.setUserRepoPrefix("users/"); reponame = "users/fee"; assertTrue(ModelUtils.isUsersPersonalRepository("fee", reponame)); assertFalse(ModelUtils.isUsersPersonalRepository("gnome", reponame)); @@ -152,14 +116,14 @@ public class ModelUtilsTest { @Test public void testGetUserNameFromRepoPath() { - String reponame = DEFAULT_USER_REPO_PREFIX + "lynn"; + String reponame = Constants.DEFAULT_USER_REPOSITORY_PREFIX + "lynn"; assertEquals("lynn", ModelUtils.getUserNameFromRepoPath(reponame)); - setRepoPrefix("@@"); + ModelUtils.setUserRepoPrefix("@@"); reponame = "@@newton"; assertEquals("newton", ModelUtils.getUserNameFromRepoPath(reponame)); - setRepoPrefix("users/"); + ModelUtils.setUserRepoPrefix("users/"); reponame = "users/fee"; assertEquals("fee", ModelUtils.getUserNameFromRepoPath(reponame)); } |