d77c1b2b0bda4b2ee45a077ca2f90cae2236c66e
[onosfw.git] /
1 /*
2  * Copyright 2015 Open Networking Laboratory
3  *
4  * Licensed under the Apache 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.apache.org/licenses/LICENSE-2.0
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
17 package org.onosproject.ui.table.cell;
18
19 import org.junit.Test;
20 import org.onosproject.ui.table.CellComparator;
21
22 import static org.junit.Assert.assertTrue;
23
24 /**
25  * Unit tests for {@link DefaultCellComparator}.
26  */
27 public class DefaultCellComparatorTest {
28
29     private static final String SOME = "SoMeStRiNg";
30     private static final String OTHER = "OtherSTRING";
31
32     private CellComparator cmp = DefaultCellComparator.INSTANCE;
33
34     // default comparator should detect Comparable<T> impls and use that
35
36     @Test
37     public void sameString() {
38         assertTrue("same string", cmp.compare(SOME, SOME) == 0);
39     }
40
41     @Test
42     public void someVsOther() {
43         assertTrue("some vs other", cmp.compare(SOME, OTHER) > 0);
44     }
45
46     @Test
47     public void otherVsSome() {
48         assertTrue("other vs some", cmp.compare(OTHER, SOME) < 0);
49     }
50
51     @Test
52     public void someVsNull() {
53         assertTrue("some vs null", cmp.compare(SOME, null) > 0);
54     }
55
56     @Test
57     public void nullVsSome() {
58         assertTrue("null vs some", cmp.compare(null, SOME) < 0);
59     }
60
61     @Test(expected = ClassCastException.class)
62     public void mismatch() {
63         cmp.compare(42, SOME);
64     }
65
66
67     @Test
68     public void strElevenTwo() {
69         assertTrue("str 11 vs 2", cmp.compare("11", "2") < 0);
70     }
71
72     @Test
73     public void intElevenTwo() {
74         assertTrue("int 11 vs 2", cmp.compare(11, 2) > 0);
75     }
76
77
78     @Test
79     public void intSmallBig() {
80         assertTrue("int 2 vs 4", cmp.compare(2, 4) < 0);
81     }
82
83     @Test
84     public void intBigSmall() {
85         assertTrue("int 4 vs 2", cmp.compare(4, 2) > 0);
86     }
87
88     @Test
89     public void intEqual() {
90         assertTrue("int 4 vs 4", cmp.compare(4, 4) == 0);
91     }
92
93     @Test
94     public void longSmallBig() {
95         assertTrue("long 2 vs 4", cmp.compare(2L, 4L) < 0);
96     }
97
98     @Test
99     public void longBigSmall() {
100         assertTrue("long 4 vs 2", cmp.compare(4L, 2L) > 0);
101     }
102
103     @Test
104     public void longEqual() {
105         assertTrue("long 4 vs 4", cmp.compare(4L, 4L) == 0);
106     }
107
108
109     private enum SmallStarWars { C3PO, R2D2, LUKE }
110
111     @Test
112     public void swEpisodeI() {
113         assertTrue("c3po r2d2",
114                    cmp.compare(SmallStarWars.C3PO, SmallStarWars.R2D2) < 0);
115     }
116
117     @Test
118     public void swEpisodeII() {
119         assertTrue("r2d2 c3po",
120                    cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0);
121     }
122
123     @Test
124     public void swEpisodeIII() {
125         assertTrue("luke c3po",
126                    cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0);
127     }
128
129     @Test
130     public void swEpisodeIV() {
131         assertTrue("c3po luke",
132                    cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0);
133     }
134
135     @Test
136     public void swEpisodeV() {
137         assertTrue("luke r2d2",
138                    cmp.compare(SmallStarWars.LUKE, SmallStarWars.R2D2) > 0);
139     }
140
141     @Test
142     public void swEpisodeVI() {
143         assertTrue("r2d2 luke",
144                    cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0);
145     }
146 }