From de1056ef057c61d79e4b256f91d94d392c1bac2f Mon Sep 17 00:00:00 2001 From: gotty Date: Sat, 23 Nov 2019 04:14:36 +0000 Subject: [PATCH] [LIB-10] Tests for SnookerDateUtils git-svn-id: https://svn.hedgecode.org/lib/snooker-score-api/trunk@194 fb0bcced-7025-49ed-a12f-f98bce993226 --- .../hedgecode/snooker/SnookerDateUtilsTest.java | 97 ++++++++++++++++++++++ 1 file changed, 97 insertions(+) create mode 100644 src/test/java/org/hedgecode/snooker/SnookerDateUtilsTest.java diff --git a/src/test/java/org/hedgecode/snooker/SnookerDateUtilsTest.java b/src/test/java/org/hedgecode/snooker/SnookerDateUtilsTest.java new file mode 100644 index 0000000..bfb866a --- /dev/null +++ b/src/test/java/org/hedgecode/snooker/SnookerDateUtilsTest.java @@ -0,0 +1,97 @@ +/* + * 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() + ); + } + +} -- 2.10.0