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