View Javadoc

1   /**
2    * 
3    */
4   package org.kuali.maven.mojo.s3;
5   
6   import java.util.ArrayList;
7   import java.util.Collections;
8   import java.util.Comparator;
9   import java.util.List;
10  
11  import junit.framework.Assert;
12  
13  import org.junit.Test;
14  
15  /**
16   * 
17   */
18  public class DisplayRowComparatorTest {
19  
20  	@Test
21  	public void gettersAndSetters() {
22  		DisplayRowComparator c = new DisplayRowComparator();
23  		c.setSeparators(DisplayRowComparator.DEFAULT_SEPARATORS);
24  		Assert.assertEquals(DisplayRowComparator.DEFAULT_SEPARATORS, c.getSeparators());
25  	}
26  
27  	@Test
28  	public void bothNull() {
29  		DisplayRow dr1 = new DisplayRow();
30  		DisplayRow dr2 = new DisplayRow();
31  		List<DisplayRow> drs = new ArrayList<DisplayRow>();
32  		Comparator<DisplayRow> c = new DisplayRowComparator();
33  		drs.add(dr1);
34  		drs.add(dr2);
35  
36  		Collections.sort(drs, c);
37  	}
38  
39  	@Test
40  	public void oneNull() {
41  		DisplayRow dr1 = new DisplayRow();
42  		dr1.setShow("1.1");
43  		DisplayRow dr2 = new DisplayRow();
44  		List<DisplayRow> drs = new ArrayList<DisplayRow>();
45  		Comparator<DisplayRow> c = new DisplayRowComparator();
46  		drs.add(dr1);
47  		drs.add(dr2);
48  
49  		Collections.sort(drs, c);
50  		Assert.assertEquals(null, drs.get(0).getShow());
51  	}
52  
53  	@Test
54  	public void twoNull() {
55  		DisplayRow dr1 = new DisplayRow();
56  		DisplayRow dr2 = new DisplayRow();
57  		dr2.setShow("1.1");
58  		DisplayRow dr3 = new DisplayRow();
59  		List<DisplayRow> drs = new ArrayList<DisplayRow>();
60  		Comparator<DisplayRow> c = new DisplayRowComparator();
61  		drs.add(dr1);
62  		drs.add(dr2);
63  		drs.add(dr3);
64  
65  		Collections.sort(drs, c);
66  		Assert.assertEquals(null, drs.get(0).getShow());
67  		Assert.assertEquals("1.1", drs.get(2).getShow());
68  	}
69  
70  	@Test
71  	public void basicVersionCompareTo() {
72  		String show1 = "1.1.1";
73  		String show2 = "1.1.0";
74  		DisplayRow dr1 = new DisplayRow();
75  		dr1.setShow(show1);
76  		DisplayRow dr2 = new DisplayRow();
77  		dr2.setShow(show2);
78  		List<DisplayRow> drs = new ArrayList<DisplayRow>();
79  		Comparator<DisplayRow> c = new DisplayRowComparator();
80  		drs.add(dr1);
81  		drs.add(dr2);
82  
83  		Collections.sort(drs, c);
84  
85  		Assert.assertEquals("1.1.0", drs.get(0).getShow());
86  	}
87  
88  	@Test
89  	public void nonAlphaVersionCompareTo() {
90  		String show1 = "1.1.17";
91  		String show2 = "1.1.2";
92  		DisplayRow dr1 = new DisplayRow();
93  		dr1.setShow(show1);
94  		DisplayRow dr2 = new DisplayRow();
95  		dr2.setShow(show2);
96  		List<DisplayRow> drs = new ArrayList<DisplayRow>();
97  		Comparator<DisplayRow> c = new DisplayRowComparator();
98  		drs.add(dr1);
99  		drs.add(dr2);
100 
101 		Collections.sort(drs, c);
102 
103 		Assert.assertEquals("1.1.2", drs.get(0).getShow());
104 	}
105 
106 	@Test
107 	public void snapshotCompareTo() {
108 		String show1 = "1.1.17-SNAPSHOT";
109 		String show2 = "1.1.17";
110 		DisplayRow dr1 = new DisplayRow();
111 		dr1.setShow(show1);
112 		DisplayRow dr2 = new DisplayRow();
113 		dr2.setShow(show2);
114 		List<DisplayRow> drs = new ArrayList<DisplayRow>();
115 		Comparator<DisplayRow> c = new DisplayRowComparator();
116 		drs.add(dr1);
117 		drs.add(dr2);
118 
119 		Collections.sort(drs, c);
120 
121 		Assert.assertEquals("1.1.17-SNAPSHOT", drs.get(0).getShow());
122 	}
123 
124 	@Test
125 	public void milestoneCompareTo() {
126 		String show1 = "1.1.17-M2";
127 		String show2 = "1.1.17-M2-SNAPSHOT";
128 		DisplayRow dr1 = new DisplayRow();
129 		dr1.setShow(show1);
130 		DisplayRow dr2 = new DisplayRow();
131 		dr2.setShow(show2);
132 		List<DisplayRow> drs = new ArrayList<DisplayRow>();
133 		Comparator<DisplayRow> c = new DisplayRowComparator();
134 		drs.add(dr1);
135 		drs.add(dr2);
136 
137 		Collections.sort(drs, c);
138 
139 		Assert.assertEquals("1.1.17-M2-SNAPSHOT", drs.get(0).getShow());
140 	}
141 
142 	@Test
143 	public void sameCompareTo() {
144 		String show1 = "1.1.17-M2";
145 		String show2 = "1.1.17-M2";
146 		DisplayRow dr1 = new DisplayRow();
147 		dr1.setShow(show1);
148 		DisplayRow dr2 = new DisplayRow();
149 		dr2.setShow(show2);
150 		List<DisplayRow> drs = new ArrayList<DisplayRow>();
151 		Comparator<DisplayRow> c = new DisplayRowComparator();
152 		drs.add(dr1);
153 		drs.add(dr2);
154 
155 		Collections.sort(drs, c);
156 
157 		Assert.assertEquals("1.1.17-M2", drs.get(0).getShow());
158 	}
159 }