blob: 7517aac0e33c3ecf4d6186e2c04e79ca3d46bc28 [file] [log] [blame]
Simon Hunt9ffbd8d2015-05-06 12:02:32 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2015-present Open Networking Foundation
Simon Hunt9ffbd8d2015-05-06 12:02:32 -07003 *
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 Hunt9ffbd8d2015-05-06 12:02:32 -070015 */
16
17package org.onosproject.ui.table.cell;
18
Simon Hunt9ffbd8d2015-05-06 12:02:32 -070019import org.junit.Test;
20import org.onosproject.ui.table.CellFormatter;
21
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070022import java.time.OffsetDateTime;
23import java.time.ZoneOffset;
Simon Hunt5939e652015-05-06 16:20:23 -070024import java.util.Locale;
25
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070026import static org.hamcrest.Matchers.isOneOf;
27import static org.junit.Assert.assertThat;
Simon Hunt9ffbd8d2015-05-06 12:02:32 -070028
29/**
30 * Unit tests for {@link TimeFormatter}.
31 */
32public class TimeFormatterTest {
33
Simon Hunt5939e652015-05-06 16:20:23 -070034 private static final Locale LOCALE = Locale.ENGLISH;
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070035 private static final ZoneOffset ZONE = ZoneOffset.UTC;
Simon Hunt9ffbd8d2015-05-06 12:02:32 -070036
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070037 private static final OffsetDateTime TIME = OffsetDateTime.of(2015, 5, 4, 15, 30, 0, 0, ZONE);
Jon Halldf6a6e42015-08-25 16:22:41 -070038 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 Hunt5939e652015-05-06 16:20:23 -070040
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 Hunt9ffbd8d2015-05-06 12:02:32 -070046
47 @Test
48 public void basic() {
Yuta HIGUCHI0c47d532017-08-18 23:16:35 -070049 assertThat(fmt.format(TIME), isOneOf(EXP_ZONE_OFFSET, EXP_ZONE_NAME));
Simon Hunt9ffbd8d2015-05-06 12:02:32 -070050 }
51}