Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -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 | 9ffbd8d | 2015-05-06 12:02:32 -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 | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | package org.onosproject.ui.table.cell; |
| 18 | |
| 19 | import org.joda.time.DateTime; |
Simon Hunt | 5939e65 | 2015-05-06 16:20:23 -0700 | [diff] [blame] | 20 | import org.joda.time.DateTimeZone; |
Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 21 | import org.junit.Test; |
| 22 | import org.onosproject.ui.table.CellFormatter; |
| 23 | |
Simon Hunt | 5939e65 | 2015-05-06 16:20:23 -0700 | [diff] [blame] | 24 | import java.util.Locale; |
| 25 | |
Jon Hall | df6a6e4 | 2015-08-25 16:22:41 -0700 | [diff] [blame] | 26 | import static org.junit.Assert.assertTrue; |
Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 27 | |
| 28 | /** |
| 29 | * Unit tests for {@link TimeFormatter}. |
| 30 | */ |
| 31 | public class TimeFormatterTest { |
| 32 | |
Simon Hunt | 5939e65 | 2015-05-06 16:20:23 -0700 | [diff] [blame] | 33 | private static final Locale LOCALE = Locale.ENGLISH; |
| 34 | private static final DateTimeZone ZONE = DateTimeZone.UTC; |
Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 35 | |
Simon Hunt | 5939e65 | 2015-05-06 16:20:23 -0700 | [diff] [blame] | 36 | private static final DateTime TIME = new DateTime(2015, 5, 4, 15, 30, ZONE); |
Jon Hall | df6a6e4 | 2015-08-25 16:22:41 -0700 | [diff] [blame] | 37 | private static final String EXP_ZONE_NAME = "3:30:00 PM UTC"; |
| 38 | private static final String EXP_ZONE_OFFSET = "3:30:00 PM +00:00"; |
Simon Hunt | 5939e65 | 2015-05-06 16:20:23 -0700 | [diff] [blame] | 39 | |
| 40 | // Have to use explicit Locale and TimeZone for the unit test, so that |
| 41 | // irrespective of which locale and time zone the test is run in, it |
| 42 | // always produces the same result... |
| 43 | private CellFormatter fmt = |
| 44 | new TimeFormatter().withLocale(LOCALE).withZone(ZONE); |
Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 45 | |
| 46 | @Test |
| 47 | public void basic() { |
Jon Hall | df6a6e4 | 2015-08-25 16:22:41 -0700 | [diff] [blame] | 48 | assertTrue("wrong format", (EXP_ZONE_NAME.equals(fmt.format(TIME)) || |
| 49 | EXP_ZONE_OFFSET.equals(fmt.format(TIME)))); |
Simon Hunt | 9ffbd8d | 2015-05-06 12:02:32 -0700 | [diff] [blame] | 50 | } |
| 51 | } |