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