2 * Copyright (c) 2017-2020. Developed by Hedgecode.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package org.hedgecode.snooker;
19 import java.text.DateFormat;
20 import java.text.SimpleDateFormat;
21 import java.util.Date;
22 import java.util.TimeZone;
24 import org.junit.Assert;
25 import org.junit.Test;
26 import org.junit.runner.RunWith;
27 import org.junit.runners.JUnit4;
30 * Tests for {@link SnookerDateUtils}.
32 * @author Dmitry Samoshin aka gotty
34 @RunWith(JUnit4.class)
35 public class SnookerDateUtilsTest extends Assert {
37 private static final String DATE_PATTERN = SnookerScoreProperties.get("snooker.date.format");
38 private static final String TIME_PATTERN = SnookerScoreProperties.get("snooker.time.format");
39 private static final String DATETIME_PATTERN = String.format("%s %s", TIME_PATTERN , DATE_PATTERN);
41 private static final TimeZone SNOOKER_TIMEZONE = TimeZone.getTimeZone(
42 SnookerScoreProperties.get("snooker.timezone")
44 private static final TimeZone LOCAL_TIMEZONE = TimeZone.getDefault();
47 public void testFormatDate() throws Exception {
48 Date currentDate = new Date();
49 DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
51 dateFormat.format(currentDate),
52 SnookerDateUtils.formatDate(currentDate)
57 public void testFormatTime() throws Exception {
58 Date currentTime = new Date();
59 DateFormat timeFormat = new SimpleDateFormat(TIME_PATTERN);
60 timeFormat.setTimeZone(SNOOKER_TIMEZONE);
62 timeFormat.format(currentTime),
63 SnookerDateUtils.formatTime(currentTime)
65 DateFormat datetimeFormat = new SimpleDateFormat(DATETIME_PATTERN);
66 datetimeFormat.setTimeZone(SNOOKER_TIMEZONE);
68 datetimeFormat.format(currentTime),
69 SnookerDateUtils.formatTime(currentTime, true)
74 public void testFormatLocalTime() throws Exception {
75 Date currentTime = new Date();
76 DateFormat timeFormat = new SimpleDateFormat(TIME_PATTERN);
77 timeFormat.setTimeZone(LOCAL_TIMEZONE);
79 timeFormat.format(currentTime),
80 SnookerDateUtils.formatLocalTime(currentTime)
82 DateFormat datetimeFormat = new SimpleDateFormat(DATETIME_PATTERN);
83 datetimeFormat.setTimeZone(LOCAL_TIMEZONE);
85 datetimeFormat.format(currentTime),
86 SnookerDateUtils.formatLocalTime(currentTime, true)
91 public void testGetInstance() throws Exception {
93 SnookerDateUtils.getInstance()