1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.kuali.common.util.metainf.model;
17
18 import java.util.Collections;
19 import java.util.List;
20
21 import org.junit.Assert;
22 import org.junit.Test;
23 import org.kuali.common.util.log.LoggerUtils;
24 import org.slf4j.Logger;
25
26 import com.google.common.collect.Lists;
27
28 public class MetainfResourcePathComparatorTest {
29
30 private static final Logger logger = LoggerUtils.make();
31
32 @Test
33 public void test() {
34 logger.info("Testing MetaInfResourcePathComparator");
35 String loc0 = "foo.txt";
36 String loc1 = "/a/foo1.txt";
37 String loc2 = "/a/foo2.txt";
38 String loc3 = "/a/b/foo.txt";
39
40 List<MetaInfResource> resources = Lists.newArrayList();
41 resources.add(new MetaInfResource(loc2));
42 resources.add(new MetaInfResource(loc0));
43 resources.add(new MetaInfResource(loc3));
44 resources.add(new MetaInfResource(loc1));
45
46 Collections.sort(resources, new MetaInfResourcePathComparator());
47 Assert.assertEquals(loc0, resources.get(0).getLocation());
48 Assert.assertEquals(loc1, resources.get(1).getLocation());
49 Assert.assertEquals(loc2, resources.get(2).getLocation());
50 Assert.assertEquals(loc3, resources.get(3).getLocation());
51 }
52
53 @Test
54 public void test2() {
55 String loc0 = "a.txt";
56 String loc1 = "/a/b.txt";
57
58 List<MetaInfResource> resources = Lists.newArrayList();
59 resources.add(new MetaInfResource(loc1));
60 resources.add(new MetaInfResource(loc0));
61
62 Collections.sort(resources, new MetaInfResourcePathComparator());
63 Assert.assertEquals(loc0, resources.get(0).getLocation());
64 Assert.assertEquals(loc1, resources.get(1).getLocation());
65 }
66
67 @Test
68 public void testEqualPaths() {
69 String loc0 = "foo.txt";
70 String loc1 = loc0;
71 String loc2 = "foo1.txt";
72 String loc3 = "foo2.txt";
73
74 List<MetaInfResource> resources = Lists.newArrayList();
75 resources.add(new MetaInfResource(loc2));
76 resources.add(new MetaInfResource(loc0));
77 resources.add(new MetaInfResource(loc3));
78 resources.add(new MetaInfResource(loc1));
79
80 Collections.sort(resources, new MetaInfResourcePathComparator());
81 Assert.assertEquals(loc0, resources.get(0).getLocation());
82 Assert.assertEquals(loc1, resources.get(1).getLocation());
83 Assert.assertEquals(loc2, resources.get(2).getLocation());
84 Assert.assertEquals(loc3, resources.get(3).getLocation());
85 }
86
87 }