blob: f65f7e18fc034ce0d3c73a2d3bc2e970e2b582a1 [file] [log] [blame]
Simon Huntbe60dde2016-01-13 12:26:56 -08001/*
Brian O'Connor5ab426f2016-04-09 01:19:45 -07002 * Copyright 2016-present Open Networking Laboratory
Simon Huntbe60dde2016-01-13 12:26:56 -08003 *
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
17package org.onosproject.ui.table.cell;
18
Szymon Furmand2a9dd32017-06-20 15:35:27 +020019import org.junit.AfterClass;
20import org.junit.BeforeClass;
Simon Huntbe60dde2016-01-13 12:26:56 -080021import org.junit.Test;
22import org.onosproject.ui.table.CellFormatter;
23
Szymon Furmand2a9dd32017-06-20 15:35:27 +020024import java.util.Locale;
25
Simon Huntbe60dde2016-01-13 12:26:56 -080026import static org.junit.Assert.assertEquals;
27
28/**
29 * Unit tests for {@link NumberFormatter}.
30 */
31public class NumberFormatterTest {
32
33
34 private CellFormatter f5dp = NumberFormatter.TO_5DP;
35 private CellFormatter fInt = NumberFormatter.INTEGER;
36
Szymon Furmand2a9dd32017-06-20 15:35:27 +020037 private static Locale systemLocale;
38
39 @BeforeClass
40 public static void classSetup() {
41 systemLocale = Locale.getDefault();
42 Locale.setDefault(Locale.US);
43 }
44
45 @AfterClass
46 public static void classTeardown() {
47 Locale.setDefault(systemLocale);
48 }
49
Simon Huntbe60dde2016-01-13 12:26:56 -080050 @Test
51 public void defaultNullValue() {
52 assertEquals("default null value", "", f5dp.format(null));
53 }
54
55 @Test
56 public void defaultZero() {
57 assertEquals("default zero", "0.00000", f5dp.format(0));
58 }
59
60 @Test
61 public void defaultFifty() {
62 assertEquals("default fifty", "50.00000", f5dp.format(50));
63 }
64
65 @Test
66 public void default2G() {
67 assertEquals("default 2G", "2,000.00000", f5dp.format(2000));
68 }
69
70 @Test
71 public void integerNullValue() {
72 assertEquals("integer null value", "", fInt.format(null));
73 }
74
75 @Test
76 public void integerZero() {
77 assertEquals("integer zero", "0", fInt.format(0));
78 }
79
80 @Test
81 public void integerFifty() {
82 assertEquals("integer fifty", "50", fInt.format(50));
83 }
84
85 @Test
86 public void integer2G() {
87 assertEquals("integer 2G", "2,000", fInt.format(2000));
88 }
89
90 @Test
91 public void integer5M() {
92 assertEquals("integer 5M", "5,000,042", fInt.format(5000042));
93 }
94
95}