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