Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2015-present Open Networking Foundation |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 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 Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 17 | package org.onosproject.ui.table.cell; |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 18 | |
| 19 | import org.junit.Test; |
Simon Hunt | 3ee7f74 | 2015-05-05 10:18:20 -0700 | [diff] [blame] | 20 | import org.onosproject.ui.table.CellComparator; |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 21 | |
| 22 | import static org.junit.Assert.assertTrue; |
| 23 | |
| 24 | /** |
| 25 | * Unit tests for {@link DefaultCellComparator}. |
| 26 | */ |
| 27 | public class DefaultCellComparatorTest { |
| 28 | |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 29 | private static final String SOME = "SoMeStRiNg"; |
| 30 | private static final String OTHER = "OtherSTRING"; |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 31 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 32 | private CellComparator cmp = DefaultCellComparator.INSTANCE; |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 33 | |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 34 | // default comparator should detect Comparable<T> impls and use that |
| 35 | |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 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 |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 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 | |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 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 |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 118 | public void swEpisodeIi() { |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 119 | assertTrue("r2d2 c3po", |
| 120 | cmp.compare(SmallStarWars.R2D2, SmallStarWars.C3PO) > 0); |
| 121 | } |
| 122 | |
| 123 | @Test |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 124 | public void swEpisodeIii() { |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 125 | assertTrue("luke c3po", |
| 126 | cmp.compare(SmallStarWars.LUKE, SmallStarWars.C3PO) > 0); |
| 127 | } |
| 128 | |
| 129 | @Test |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 130 | public void swEpisodeIv() { |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 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 |
Jonathan Hart | d9df7bd | 2015-11-10 17:10:25 -0800 | [diff] [blame] | 142 | public void swEpisodeVi() { |
Simon Hunt | 27bf079 | 2015-05-07 10:50:29 -0700 | [diff] [blame] | 143 | assertTrue("r2d2 luke", |
| 144 | cmp.compare(SmallStarWars.R2D2, SmallStarWars.LUKE) < 0); |
| 145 | } |
Simon Hunt | 933b1a8 | 2015-05-04 19:07:24 -0700 | [diff] [blame] | 146 | } |