From a9a2ffcf9a34bd25fe2e05bfdd4cde74725bb17d Mon Sep 17 00:00:00 2001 From: Milos Cubrilo Date: Sun, 11 Jan 2015 13:41:29 +0100 Subject: #230 - Improve empty folder navigation. Empty folders are automatically skipped when browsing repository tree (similar to github "folder jumping" feature). --- src/test/java/com/gitblit/tests/GitBlitSuite.java | 14 ++--- src/test/java/com/gitblit/tests/JGitUtilsTest.java | 9 +++ src/test/java/com/gitblit/tests/PathUtilsTest.java | 66 ++++++++++++++++++++++ 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 src/test/java/com/gitblit/tests/PathUtilsTest.java (limited to 'src/test/java/com/gitblit') diff --git a/src/test/java/com/gitblit/tests/GitBlitSuite.java b/src/test/java/com/gitblit/tests/GitBlitSuite.java index f2dfcc0c..bf6834d3 100644 --- a/src/test/java/com/gitblit/tests/GitBlitSuite.java +++ b/src/test/java/com/gitblit/tests/GitBlitSuite.java @@ -63,9 +63,9 @@ import com.gitblit.utils.JGitUtils; GitBlitTest.class, FederationTests.class, RpcTests.class, GitServletTest.class, GitDaemonTest.class, SshDaemonTest.class, GroovyScriptTest.class, LuceneExecutorTest.class, RepositoryModelTest.class, FanoutServiceTest.class, Issue0259Test.class, Issue0271Test.class, HtpasswdAuthenticationTest.class, - ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class, + ModelUtilsTest.class, JnaUtilsTest.class, LdapSyncServiceTest.class, FileTicketServiceTest.class, BranchTicketServiceTest.class, RedisTicketServiceTest.class, AuthenticationManagerTest.class, - SshKeysDispatcherTest.class, UITicketTest.class }) + SshKeysDispatcherTest.class, UITicketTest.class, PathUtilsTest.class }) public class GitBlitSuite { public static final File BASEFOLDER = new File("data"); @@ -110,11 +110,11 @@ public class GitBlitSuite { return getRepository("test/gitective.git"); } - public static Repository getTicketsTestRepository() { - JGitUtils.createRepository(REPOSITORIES, "gb-tickets.git").close(); - return getRepository("gb-tickets.git"); - } - + public static Repository getTicketsTestRepository() { + JGitUtils.createRepository(REPOSITORIES, "gb-tickets.git").close(); + return getRepository("gb-tickets.git"); + } + private static Repository getRepository(String name) { try { File gitDir = FileKey.resolve(new File(REPOSITORIES, name), FS.DETECTED); diff --git a/src/test/java/com/gitblit/tests/JGitUtilsTest.java b/src/test/java/com/gitblit/tests/JGitUtilsTest.java index c2cfb331..2cf4a5a1 100644 --- a/src/test/java/com/gitblit/tests/JGitUtilsTest.java +++ b/src/test/java/com/gitblit/tests/JGitUtilsTest.java @@ -475,6 +475,15 @@ public class JGitUtilsTest extends GitblitUnitTest { assertTrue(files.size() > 10); } + @Test + public void testFilesInPath2() throws Exception { + assertEquals(0, JGitUtils.getFilesInPath2(null, null, null).size()); + Repository repository = GitBlitSuite.getHelloworldRepository(); + List files = JGitUtils.getFilesInPath2(repository, null, null); + repository.close(); + assertTrue(files.size() > 10); + } + @Test public void testDocuments() throws Exception { Repository repository = GitBlitSuite.getTicgitRepository(); diff --git a/src/test/java/com/gitblit/tests/PathUtilsTest.java b/src/test/java/com/gitblit/tests/PathUtilsTest.java new file mode 100644 index 00000000..209b8ee6 --- /dev/null +++ b/src/test/java/com/gitblit/tests/PathUtilsTest.java @@ -0,0 +1,66 @@ +/* + * Copyright 2011 gitblit.com. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.gitblit.tests; + +import com.gitblit.utils.PathUtils; +import org.junit.Test; + +import java.util.Arrays; + +public class PathUtilsTest extends GitblitUnitTest { + + private static final String[][][] testData = { + + { + // Folder contents + {".gitignore","src/main/java/a.java", "src/main/java/b.java", "docs/c.md"}, + // Expected after compressing + {".gitignore", "src/main/java/", "docs/"} + }, + + { + {".gitignore","src/main/java/a.java", "src/main/b.java", "docs/c.md"}, + {".gitignore", "src/main/", "docs/"} + }, + + { + {".gitignore","src/x.java","src/main/java/a.java", "src/main/java/b.java", "docs/c.md"}, + {".gitignore", "src/", "docs/"} + }, + }; + + + + + @Test + public void testCompressPaths() throws Exception { + + for (String[][] test : testData ) { + assertArrayEquals(test[1], PathUtils.compressPaths(Arrays.asList(test[0])).toArray(new String[]{})); + } + + } + + @Test + public void testGetLastPathComponent() { + assertEquals(PathUtils.getLastPathComponent("/a/b/c/d/e.out"), "e.out"); + assertEquals(PathUtils.getLastPathComponent("e.out"), "e.out"); + assertEquals(PathUtils.getLastPathComponent("/a/b/c/d/"), "d"); + assertEquals(PathUtils.getLastPathComponent("/a/b/c/d"), "d"); + assertEquals(PathUtils.getLastPathComponent("/"), "/"); + } + +} \ No newline at end of file -- cgit v1.2.3