View Javadoc
1   /**
2    * Copyright 2010-2014 The Kuali Foundation
3    *
4    * Licensed under the Educational Community License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    * http://www.opensource.org/licenses/ecl2.php
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
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  }