Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 1 | /* |
Brian O'Connor | 5ab426f | 2016-04-09 01:19:45 -0700 | [diff] [blame] | 2 | * Copyright 2016-present Open Networking Laboratory |
Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [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. |
| 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.table.cell; |
| 18 | |
Szymon Furman | d2a9dd3 | 2017-06-20 15:35:27 +0200 | [diff] [blame] | 19 | import org.junit.AfterClass; |
| 20 | import org.junit.BeforeClass; |
Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.onosproject.ui.table.CellFormatter; |
| 23 | |
Szymon Furman | d2a9dd3 | 2017-06-20 15:35:27 +0200 | [diff] [blame] | 24 | import java.util.Locale; |
| 25 | |
Simon Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 26 | import static org.junit.Assert.assertEquals; |
| 27 | |
| 28 | /** |
| 29 | * Unit tests for {@link NumberFormatter}. |
| 30 | */ |
| 31 | public class NumberFormatterTest { |
| 32 | |
| 33 | |
| 34 | private CellFormatter f5dp = NumberFormatter.TO_5DP; |
| 35 | private CellFormatter fInt = NumberFormatter.INTEGER; |
| 36 | |
Szymon Furman | d2a9dd3 | 2017-06-20 15:35:27 +0200 | [diff] [blame] | 37 | 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 Hunt | be60dde | 2016-01-13 12:26:56 -0800 | [diff] [blame] | 50 | @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 | } |