forked from FAForever/downlords-faf-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into bugfix/#3156_mods_map_saving_create_game
- Loading branch information
Showing
5 changed files
with
212 additions
and
13 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
version=unspecified | ||
javafxPlatform=unspecified | ||
iceAdapterVersion=v3.3.8 | ||
iceAdapterVersion=v2.4.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/test/java/com/faforever/client/util/TimeServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.faforever.client.util; | ||
|
||
import com.faforever.client.i18n.I18n; | ||
import com.faforever.client.preferences.ChatPrefs; | ||
import com.faforever.client.preferences.DateInfo; | ||
import com.faforever.client.preferences.LocalizationPrefs; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.jupiter.api.parallel.Execution; | ||
import org.junit.jupiter.api.parallel.ExecutionMode; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.time.OffsetDateTime; | ||
import java.time.ZoneOffset; | ||
import java.time.format.FormatStyle; | ||
import java.util.Locale; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.mockito.Mockito.when; | ||
|
||
@Execution(ExecutionMode.CONCURRENT) | ||
@ExtendWith({MockitoExtension.class}) | ||
class TimeServiceTest { | ||
|
||
@Mock | ||
I18n i18n; | ||
@Mock | ||
ChatPrefs chatPrefs; | ||
@Mock | ||
LocalizationPrefs localizationPrefs; | ||
|
||
@InjectMocks | ||
TimeService service; | ||
|
||
private final Locale localeUS = Locale.of("en", "US"); | ||
private final Locale localeFR = Locale.of("fr", "FR"); | ||
private final FormatStyle formatStyleMedium = FormatStyle.MEDIUM; | ||
|
||
@Test | ||
void asDateAutoUS() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.AUTO; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeUS); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("May 9, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateMonthDayYearUS() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.MONTH_DAY_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeUS); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("May 9, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateDayMonthYearUS() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.DAY_MONTH_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeUS); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("9 May, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateAutoFR() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.AUTO; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeFR); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("9 mai 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateMonthDayYearFR() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.MONTH_DAY_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeFR); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("mai 9, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateDayMonthYearFR() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.DAY_MONTH_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeFR); | ||
|
||
var result = service.asDate(date, formatStyleMedium); | ||
|
||
assertEquals("9 mai, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateAutoFullUS() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.AUTO; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeUS); | ||
|
||
var result = service.asDate(date, FormatStyle.FULL); | ||
|
||
assertEquals("Monday, May 9, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateDMYFullUS() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.DAY_MONTH_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeUS); | ||
|
||
var result = service.asDate(date, FormatStyle.FULL); | ||
|
||
assertEquals("Monday, 9 May, 2022", result); | ||
} | ||
|
||
@Test | ||
void asDateDMYFullFR() { | ||
var date = generateDate(); | ||
var dateInfo = DateInfo.DAY_MONTH_YEAR; | ||
|
||
when(localizationPrefs.getDateFormat()).thenReturn(dateInfo); | ||
when(i18n.getUserSpecificLocale()).thenReturn(localeFR); | ||
|
||
var result = service.asDate(date, FormatStyle.FULL); | ||
|
||
assertEquals("lundi, 9 mai, 2022", result); | ||
} | ||
|
||
|
||
private OffsetDateTime generateDate() { | ||
return OffsetDateTime.of(2022, 5, 9, 9, 9, 9, 9, ZoneOffset.UTC); | ||
} | ||
} |