forked from eclipse-hawkbit/hawkbit
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added localization to String.format (eclipse-hawkbit#857)
Signed-off-by: Ahmed Sayed <[email protected]>
- Loading branch information
Showing
4 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
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
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
80 changes: 80 additions & 0 deletions
80
hawkbit-ui/src/test/java/org/eclipse/hawkbit/ui/utils/HawkbitCommonUtilTest.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,80 @@ | ||
/** | ||
* Copyright (c) 2019 Bosch Software Innovations GmbH and others. | ||
* | ||
* All rights reserved. This program and the accompanying materials | ||
* are made available under the terms of the Eclipse Public License v1.0 | ||
* which accompanies this distribution, and is available at | ||
* http://www.eclipse.org/legal/epl-v10.html | ||
*/ | ||
package org.eclipse.hawkbit.ui.utils; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.mockito.Mockito.doReturn; | ||
|
||
import java.util.Arrays; | ||
import java.util.Locale; | ||
|
||
import org.eclipse.hawkbit.ui.UiProperties; | ||
import org.junit.Test; | ||
import org.mockito.Mockito; | ||
|
||
import com.vaadin.ui.UI; | ||
|
||
import io.qameta.allure.Description; | ||
import io.qameta.allure.Feature; | ||
import io.qameta.allure.Story; | ||
|
||
@Feature("Unit Tests - Localization helper") | ||
@Story("Test the locale configuration and prioritization") | ||
public class HawkbitCommonUtilTest { | ||
|
||
@Test | ||
@Description("getCurrentLocale should return the set Locale in the UI if found, otherwise the default System Locale") | ||
public void getCurrentLocaleShouldReturnSetUILocaleOrDefaultSystemLocale() { | ||
final UI ui = Mockito.mock(UI.class); | ||
|
||
// GIVEN | ||
UI.setCurrent(null); | ||
// WHEN | ||
final Locale currentLocale = HawkbitCommonUtil.getCurrentLocale(); | ||
// THEN | ||
assertEquals(Locale.getDefault(), currentLocale); | ||
|
||
// GIVEN | ||
UI.setCurrent(ui); | ||
doReturn(Locale.GERMAN).when(ui).getLocale(); | ||
// WHEN | ||
final Locale currentLocale2 = HawkbitCommonUtil.getCurrentLocale(); | ||
// THEN | ||
assertEquals(Locale.GERMAN, currentLocale2); | ||
} | ||
|
||
@Test | ||
@Description("If a default locale is set in the environment, then it should take perceedence over requested browser locale") | ||
public void getLocaleToBeUsedShouldReturnDefaultLocalIfSet() { | ||
final UiProperties.Localization localizationProperties = Mockito.mock(UiProperties.Localization.class); | ||
|
||
// GIVEN | ||
doReturn(Locale.GERMAN).when(localizationProperties).getDefaultLocal(); | ||
// WHEN | ||
final Locale localeToBeUsed = HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, Locale.CHINESE); | ||
// THEN | ||
assertEquals(Locale.GERMAN, localeToBeUsed); | ||
} | ||
|
||
@Test | ||
@Description("If no default locale is set in the environment, then the requested browser locale may be used if supported") | ||
public void getLocaleToBeUsedShouldReturnRequestedLocalIfSupportedAndNoDefaultIsSet() { | ||
final UiProperties.Localization localizationProperties = Mockito.mock(UiProperties.Localization.class); | ||
|
||
// GIVEN | ||
doReturn(null).when(localizationProperties).getDefaultLocal(); | ||
doReturn(Arrays.asList(Locale.ENGLISH, Locale.GERMAN)).when(localizationProperties).getAvailableLocals(); | ||
|
||
// WHEN | ||
final Locale localeToBeUsed = HawkbitCommonUtil.getLocaleToBeUsed(localizationProperties, Locale.GERMAN); | ||
// THEN | ||
assertEquals(Locale.GERMAN, localeToBeUsed); | ||
} | ||
|
||
} |