--- /dev/null
+/*
+ * Copyright (c) 2017-2020. Developed by Hedgecode.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.hedgecode.snooker;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests for {@link SnookerDateUtils}.
+ *
+ * @author Dmitry Samoshin aka gotty
+ */
+@RunWith(JUnit4.class)
+public class SnookerDateUtilsTest extends Assert {
+
+ private static final String DATE_PATTERN = SnookerScoreProperties.get("snooker.date.format");
+ private static final String TIME_PATTERN = SnookerScoreProperties.get("snooker.time.format");
+ private static final String DATETIME_PATTERN = String.format("%s %s", TIME_PATTERN , DATE_PATTERN);
+
+ private static final TimeZone SNOOKER_TIMEZONE = TimeZone.getTimeZone(
+ SnookerScoreProperties.get("snooker.timezone")
+ );
+ private static final TimeZone LOCAL_TIMEZONE = TimeZone.getDefault();
+
+ @Test
+ public void testFormatDate() throws Exception {
+ Date currentDate = new Date();
+ DateFormat dateFormat = new SimpleDateFormat(DATE_PATTERN);
+ assertEquals(
+ dateFormat.format(currentDate),
+ SnookerDateUtils.formatDate(currentDate)
+ );
+ }
+
+ @Test
+ public void testFormatTime() throws Exception {
+ Date currentTime = new Date();
+ DateFormat timeFormat = new SimpleDateFormat(TIME_PATTERN);
+ timeFormat.setTimeZone(SNOOKER_TIMEZONE);
+ assertEquals(
+ timeFormat.format(currentTime),
+ SnookerDateUtils.formatTime(currentTime)
+ );
+ DateFormat datetimeFormat = new SimpleDateFormat(DATETIME_PATTERN);
+ datetimeFormat.setTimeZone(SNOOKER_TIMEZONE);
+ assertEquals(
+ datetimeFormat.format(currentTime),
+ SnookerDateUtils.formatTime(currentTime, true)
+ );
+ }
+
+ @Test
+ public void testFormatLocalTime() throws Exception {
+ Date currentTime = new Date();
+ DateFormat timeFormat = new SimpleDateFormat(TIME_PATTERN);
+ timeFormat.setTimeZone(LOCAL_TIMEZONE);
+ assertEquals(
+ timeFormat.format(currentTime),
+ SnookerDateUtils.formatLocalTime(currentTime)
+ );
+ DateFormat datetimeFormat = new SimpleDateFormat(DATETIME_PATTERN);
+ datetimeFormat.setTimeZone(LOCAL_TIMEZONE);
+ assertEquals(
+ datetimeFormat.format(currentTime),
+ SnookerDateUtils.formatLocalTime(currentTime, true)
+ );
+ }
+
+ @Test
+ public void testGetInstance() throws Exception {
+ assertNotNull(
+ SnookerDateUtils.getInstance()
+ );
+ }
+
+}