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.
18 package org.onosproject.ui.table.cell;
20 import org.junit.Test;
21 import org.onosproject.ui.table.CellComparator;
23 import static org.junit.Assert.assertTrue;
26 * Unit tests for {@link DefaultCellComparator}.
28 public class DefaultCellComparatorTest {
30 private static final String SOME = "SoMeStRiNg";
31 private static final String OTHER = "OtherSTRING";
33 private CellComparator cmp = DefaultCellComparator.INSTANCE;
35 // default comparator should detect Comparable<T> impls and use that
38 public void sameString() {
39 assertTrue("same string", cmp.compare(SOME, SOME) == 0);
43 public void someVsOther() {
44 assertTrue("some vs other", cmp.compare(SOME, OTHER) > 0);
48 public void otherVsSome() {
49 assertTrue("other vs some", cmp.compare(OTHER, SOME) < 0);
53 public void someVsNull() {
54 assertTrue("some vs null", cmp.compare(SOME, null) > 0);
58 public void nullVsSome() {
59 assertTrue("null vs some", cmp.compare(null, SOME) < 0);
62 @Test(expected = ClassCastException.class)
63 public void mismatch() {
64 cmp.compare(42, SOME);
69 public void strElevenTwo() {
70 assertTrue("str 11 vs 2", cmp.compare("11", "2") < 0);
74 public void intElevenTwo() {
75 assertTrue("int 11 vs 2", cmp.compare(11, 2) > 0);
80 public void intSmallBig() {
81 assertTrue("int 2 vs 4", cmp.compare(2, 4) < 0);
85 public void intBigSmall() {
86 assertTrue("int 4 vs 2", cmp.compare(4, 2) > 0);
90 public void intEqual() {
91 assertTrue("int 4 vs 4", cmp.compare(4, 4) == 0);
95 public void longSmallBig() {
96 assertTrue("long 2 vs 4", cmp.compare(2L, 4L) < 0);
100 public void longBigSmall() {
101 assertTrue("long 4 vs 2", cmp.compare(4L, 2L) > 0);
105 public void longEqual() {
106 assertTrue("long 4 vs 4", cmp.compare(4L, 4L) == 0);
110 private enum SmallStarWars { C3PO, R2D2, LUKE }
113 public void swEpisodeI() {
114 assertTrue("c3po r2d2",
115 cmp.compare(SmallStarWars.C3PO, SmallStarWars.R2D2) < 0);
119 public void swEpisodeII() {
120 assertTrue("r2d2 c3po",
121 cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0);
125 public void swEpisodeIII() {
126 assertTrue("luke c3po",
127 cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0);
131 public void swEpisodeIV() {
132 assertTrue("c3po luke",
133 cmp.compare(SmallStarWars.C3PO, SmallStarWars.LUKE) < 0);
137 public void swEpisodeV() {
138 assertTrue("luke r2d2",
139 cmp.compare(SmallStarWars.LUKE, SmallStarWars.R2D2) > 0);
143 public void swEpisodeVI() {
144 assertTrue("r2d2 luke",
145 cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0);