2 * Copyright 2015 Open Networking Laboratory
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.onosproject.ui.table.cell;
19 import org.junit.Test;
20 import org.onosproject.ui.table.CellComparator;
22 import static org.junit.Assert.assertTrue;
25 * Unit tests for {@link DefaultCellComparator}.
27 public class DefaultCellComparatorTest {
29 private static final String SOME = "SoMeStRiNg";
30 private static final String OTHER = "OtherSTRING";
32 private CellComparator cmp = DefaultCellComparator.INSTANCE;
34 // default comparator should detect Comparable<T> impls and use that
37 public void sameString() {
38 assertTrue("same string", cmp.compare(SOME, SOME) == 0);
42 public void someVsOther() {
43 assertTrue("some vs other", cmp.compare(SOME, OTHER) > 0);
47 public void otherVsSome() {
48 assertTrue("other vs some", cmp.compare(OTHER, SOME) < 0);
52 public void someVsNull() {
53 assertTrue("some vs null", cmp.compare(SOME, null) > 0);
57 public void nullVsSome() {
58 assertTrue("null vs some", cmp.compare(null, SOME) < 0);
61 @Test(expected = ClassCastException.class)
62 public void mismatch() {
63 cmp.compare(42, SOME);
68 public void strElevenTwo() {
69 assertTrue("str 11 vs 2", cmp.compare("11", "2") < 0);
73 public void intElevenTwo() {
74 assertTrue("int 11 vs 2", cmp.compare(11, 2) > 0);
79 public void intSmallBig() {
80 assertTrue("int 2 vs 4", cmp.compare(2, 4) < 0);
84 public void intBigSmall() {
85 assertTrue("int 4 vs 2", cmp.compare(4, 2) > 0);
89 public void intEqual() {
90 assertTrue("int 4 vs 4", cmp.compare(4, 4) == 0);
94 public void longSmallBig() {
95 assertTrue("long 2 vs 4", cmp.compare(2L, 4L) < 0);
99 public void longBigSmall() {
100 assertTrue("long 4 vs 2", cmp.compare(4L, 2L) > 0);
104 public void longEqual() {
105 assertTrue("long 4 vs 4", cmp.compare(4L, 4L) == 0);
109 private enum SmallStarWars { C3PO, R2D2, LUKE }
112 public void swEpisodeI() {
113 assertTrue("c3po r2d2",
114 cmp.compare(SmallStarWars.C3PO, SmallStarWars.R2D2) < 0);
118 public void swEpisodeII() {
119 assertTrue("r2d2 c3po",
120 cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0);
124 public void swEpisodeIII() {
125 assertTrue("luke c3po",
126 cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0);
130 public void swEpisodeIV() {
131 assertTrue("c3po luke",
132 cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0);
136 public void swEpisodeV() {
137 assertTrue("luke r2d2",
138 cmp.compare(SmallStarWars.LUKE, SmallStarWars.R2D2) > 0);
142 public void swEpisodeVI() {
143 assertTrue("r2d2 luke",
144 cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0);