blob: b870d4835a3e8c32ed3f67e0745a7b51d2f77d08 [file] [log] [blame]
Simon Hunt933b1a82015-05-04 19:07:24 -07001/*
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.
Simon Hunt933b1a82015-05-04 19:07:24 -070015 */
16
Simon Hunt3ee7f742015-05-05 10:18:20 -070017package org.onosproject.ui.table.cell;
Simon Hunt933b1a82015-05-04 19:07:24 -070018
19import org.junit.Test;
Simon Hunt3ee7f742015-05-05 10:18:20 -070020import org.onosproject.ui.table.CellComparator;
Simon Hunt933b1a82015-05-04 19:07:24 -070021
22import static org.junit.Assert.assertTrue;
23
24/**
25 * Unit tests for {@link DefaultCellComparator}.
26 */
27public class DefaultCellComparatorTest {
28
Simon Hunt933b1a82015-05-04 19:07:24 -070029 private static final String SOME = "SoMeStRiNg";
30 private static final String OTHER = "OtherSTRING";
Simon Hunt933b1a82015-05-04 19:07:24 -070031
Simon Hunt3d1b0652015-05-05 17:27:24 -070032 private CellComparator cmp = DefaultCellComparator.INSTANCE;
Simon Hunt933b1a82015-05-04 19:07:24 -070033
Simon Hunt27bf0792015-05-07 10:50:29 -070034 // default comparator should detect Comparable<T> impls and use that
35
Simon Hunt933b1a82015-05-04 19:07:24 -070036 @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
Simon Hunt933b1a82015-05-04 19:07:24 -070052 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
Simon Hunt27bf0792015-05-07 10:50:29 -070061 @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
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800118 public void swEpisodeIi() {
Simon Hunt27bf0792015-05-07 10:50:29 -0700119 assertTrue("r2d2 c3po",
120 cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0);
121 }
122
123 @Test
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800124 public void swEpisodeIii() {
Simon Hunt27bf0792015-05-07 10:50:29 -0700125 assertTrue("luke c3po",
126 cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0);
127 }
128
129 @Test
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800130 public void swEpisodeIv() {
Simon Hunt27bf0792015-05-07 10:50:29 -0700131 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
Jonathan Hartd9df7bd2015-11-10 17:10:25 -0800142 public void swEpisodeVi() {
Simon Hunt27bf0792015-05-07 10:50:29 -0700143 assertTrue("r2d2 luke",
144 cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0);
145 }
Simon Hunt933b1a82015-05-04 19:07:24 -0700146}