Simon Hunt | e982815 | 2015-05-01 17:54:25 -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. |
Simon Hunt | e982815 | 2015-05-01 17:54:25 -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 | e982815 | 2015-05-01 17:54:25 -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.CellFormatter; |
Simon Hunt | e982815 | 2015-05-01 17:54:25 -0700 | [diff] [blame] | 21 | |
| 22 | import static org.junit.Assert.assertEquals; |
| 23 | |
| 24 | /** |
| 25 | * Unit tests for {@link DefaultCellFormatter}. |
| 26 | */ |
| 27 | public class DefaultCellFormatterTest { |
| 28 | |
| 29 | private static final String UNEX = "Unexpected result"; |
| 30 | private static final String SOME_STRING = "SoMeStRiNg"; |
| 31 | |
| 32 | private static class TestClass { |
| 33 | @Override |
| 34 | public String toString() { |
| 35 | return SOME_STRING; |
| 36 | } |
| 37 | } |
| 38 | |
Simon Hunt | 3d1b065 | 2015-05-05 17:27:24 -0700 | [diff] [blame] | 39 | private CellFormatter fmt = DefaultCellFormatter.INSTANCE; |
Simon Hunt | e982815 | 2015-05-01 17:54:25 -0700 | [diff] [blame] | 40 | |
| 41 | @Test |
| 42 | public void formatNull() { |
| 43 | assertEquals(UNEX, "", fmt.format(null)); |
| 44 | } |
| 45 | |
| 46 | @Test |
| 47 | public void formatInteger() { |
| 48 | assertEquals(UNEX, "3", fmt.format(3)); |
| 49 | } |
| 50 | |
| 51 | @Test |
| 52 | public void formatTrue() { |
| 53 | assertEquals(UNEX, "true", fmt.format(true)); |
| 54 | } |
| 55 | |
| 56 | @Test |
| 57 | public void formatFalse() { |
| 58 | assertEquals(UNEX, "false", fmt.format(false)); |
| 59 | } |
| 60 | |
| 61 | @Test |
| 62 | public void formatString() { |
| 63 | assertEquals(UNEX, "FOO", fmt.format("FOO")); |
| 64 | } |
| 65 | |
| 66 | @Test |
| 67 | public void formatObject() { |
| 68 | assertEquals(UNEX, SOME_STRING, fmt.format(new TestClass())); |
| 69 | } |
| 70 | } |