|
17 | 17 | import static com.google.common.truth.Truth.assertThat; |
18 | 18 | import static com.google.gitiles.TreeSoyData.getTargetDisplayName; |
19 | 19 | import static com.google.gitiles.TreeSoyData.resolveTargetUrl; |
| 20 | +import static com.google.gitiles.TreeSoyData.sortByType; |
20 | 21 |
|
21 | 22 | import com.google.common.base.Strings; |
| 23 | +import java.util.Map; |
| 24 | +import java.util.HashMap; |
22 | 25 | import org.eclipse.jgit.lib.ObjectId; |
23 | 26 | import org.junit.Test; |
24 | 27 | import org.junit.runner.RunWith; |
@@ -64,4 +67,25 @@ public void resolveTargetUrlReturnsUrl() throws Exception { |
64 | 67 | assertThat(resolveTargetUrl(view, "../../../../")).isNull(); |
65 | 68 | assertThat(resolveTargetUrl(view, "../../a/../../..")).isNull(); |
66 | 69 | } |
| 70 | + |
| 71 | + @Test |
| 72 | + public void sortByTypeSortsCorrect() throws Exception { |
| 73 | + Map<String, String> m1 = new HashMap<String, String>(); |
| 74 | + Map<String, String> m2 = new HashMap<String, String>(); |
| 75 | + Map<String, String> m3 = new HashMap<String, String>(); |
| 76 | + Map<String, String> m4 = new HashMap<String, String>(); |
| 77 | + Map<String, String> m5 = new HashMap<String, String>(); |
| 78 | + m1.put("type", "TREE"); |
| 79 | + m2.put("type", "TREE"); |
| 80 | + m3.put("type", "SYMLINK"); |
| 81 | + m4.put("type", "REGULAR_FILE"); |
| 82 | + m5.put("type", "GITLINK"); |
| 83 | + assertThat(sortByType(m1, m2)).isEqualTo(0); |
| 84 | + assertThat(sortByType(m2, m3)).isEqualTo(-1); |
| 85 | + assertThat(sortByType(m3, m4)).isEqualTo(-1); |
| 86 | + assertThat(sortByType(m4, m1)).isEqualTo(1); |
| 87 | + assertThat(sortByType(m1, m4)).isEqualTo(-1); |
| 88 | + assertThat(sortByType(m5, m2)).isEqualTo(1); |
| 89 | + assertThat(sortByType(m2, m5)).isEqualTo(-1); |
| 90 | + } |
67 | 91 | } |
0 commit comments