Suppress PMD rules SetDefaultTimeZone and SetDefaultLocale for selected tests

Ideally these should be rewritten to avoid relying on setting the defaults, but for now an effort is done to make sure that the initial value is restored after testing, and that
these tests don't run in parallel with other tests.

Signed-off-by: Ravi Nadahar <nadahar@rediffmail.com>
This commit is contained in:
Ravi Nadahar
2025-12-29 09:43:34 +01:00
committed by Kai Kreuzer
parent bad5f94ef4
commit 5a0477872b
8 changed files with 220 additions and 1 deletions
@@ -30,9 +30,14 @@ import javax.measure.quantity.Temperature;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
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.Mock;
import org.mockito.junit.jupiter.MockitoExtension;
import org.mockito.junit.jupiter.MockitoSettings;
@@ -96,8 +101,12 @@ import org.openhab.core.ui.items.ItemUIRegistry.WidgetLabelSource;
@ExtendWith(MockitoExtension.class)
@MockitoSettings(strictness = Strictness.LENIENT)
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class ItemUIRegistryImplTest {
@Nullable
private static TimeZone initialTimeZone;
// we need to get the decimal separator of the default locale for our tests
private static final char SEP = (new DecimalFormatSymbols().getDecimalSeparator());
private static final String ITEM_NAME = "Item";
@@ -110,7 +119,20 @@ public class ItemUIRegistryImplTest {
private @Mock @NonNullByDefault({}) Widget widgetMock;
private @Mock @NonNullByDefault({}) Item itemMock;
@BeforeAll
public static void setUpClass() {
initialTimeZone = TimeZone.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultTimeZone")
public static void tearDownClass() {
// Set the default time zone to its initial value.
TimeZone.setDefault(initialTimeZone);
}
@BeforeEach
@SuppressWarnings("PMD.SetDefaultTimeZone")
public void setup() throws Exception {
uiRegistry = new ItemUIRegistryImpl(registryMock, timeZoneProviderMock);
@@ -24,7 +24,12 @@ import javax.measure.quantity.Length;
import javax.measure.quantity.Temperature;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.core.i18n.UnitProvider;
@@ -44,10 +49,26 @@ import org.openhab.core.types.UnDefType;
* @author Henning Treu - Initial contribution
*/
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class ItemStateConverterImplTest {
@Nullable
private static Locale initialLocale;
private @NonNullByDefault({}) ItemStateConverterImpl itemStateConverter;
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
/**
* Locales having a different decimal and grouping separators to test string parsing and generation.
*/
@@ -70,6 +91,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testNullState(Locale locale) {
Locale.setDefault(locale);
@@ -80,7 +102,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.CompareObjectsWithEquals")
@SuppressWarnings({ "PMD.CompareObjectsWithEquals", "PMD.SetDefaultLocale" })
public void testNoConversion(Locale locale) {
Locale.setDefault(locale);
@@ -93,6 +115,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testStateConversion(Locale locale) {
Locale.setDefault(locale);
@@ -105,6 +128,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void numberItemWithoutDimensionShouldConvertToDecimalType(Locale locale) {
Locale.setDefault(locale);
@@ -117,6 +141,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void numberItemWitDimensionShouldConvertToItemStateDescriptionUnit(Locale locale) {
Locale.setDefault(locale);
@@ -134,6 +159,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void numberItemMiredConversion(Locale locale) {
Locale.setDefault(locale);
@@ -151,6 +177,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void numberItemWitDimensionShouldConvertToLocaleBasedUnit(Locale locale) {
Locale.setDefault(locale);
@@ -165,6 +192,7 @@ public class ItemStateConverterImplTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void numberItemShouldNotConvertUnitsWhereMeasurmentSystemEquals(Locale locale) {
Locale.setDefault(locale);
@@ -35,7 +35,11 @@ import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -49,8 +53,12 @@ import org.junit.jupiter.params.provider.ValueSource;
* @author Gaël L'hopital - added ability to use second and milliseconds unix time
*/
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class DateTimeTypeTest {
@Nullable
private static TimeZone initialTimeZone;
/**
* parameter test set class.
* each instance of this class represents a test which executes the test once.
@@ -175,6 +183,18 @@ public class DateTimeTypeTest {
}
}
@BeforeAll
public static void setUpClass() {
initialTimeZone = TimeZone.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultTimeZone")
public static void tearDownClass() {
// Set the default time zone to its initial value.
TimeZone.setDefault(initialTimeZone);
}
/**
* Test parameter maps collection.
*
@@ -296,6 +316,7 @@ public class DateTimeTypeTest {
@ParameterizedTest
@MethodSource("parameters")
@SuppressWarnings("PMD.SetDefaultTimeZone")
public void createDate(ParameterSet parameterSet) {
TimeZone.setDefault(parameterSet.defaultTimeZone);
// get DateTimeType from the current parameter
@@ -332,6 +353,7 @@ public class DateTimeTypeTest {
@ParameterizedTest
@MethodSource("parameters")
@SuppressWarnings("PMD.SetDefaultTimeZone")
public void formattingTest(ParameterSet parameterSet) {
TimeZone.setDefault(parameterSet.defaultTimeZone);
DateTimeType dt = createDateTimeType(parameterSet);
@@ -23,7 +23,12 @@ import java.util.Locale;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -35,8 +40,24 @@ import org.openhab.core.library.unit.Units;
* @author Stefan Triller - more tests for type conversions
*/
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class DecimalTypeTest {
@Nullable
private static Locale initialLocale;
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
/**
* Locales having a different decimal and grouping separators to test string parsing and generation.
*/
@@ -52,6 +73,7 @@ public class DecimalTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testKnownInvalidConstructors(Locale locale) {
Locale.setDefault(locale);
@@ -98,6 +120,7 @@ public class DecimalTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testLocalizedStringConstruction(Locale defaultLocale) {
Locale.setDefault(defaultLocale);
@@ -19,7 +19,12 @@ import java.util.Locale;
import java.util.stream.Stream;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;
@@ -29,8 +34,24 @@ import org.openhab.core.library.unit.Units;
* @author Kai Kreuzer - Initial contribution
*/
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class PercentTypeTest {
@Nullable
private static Locale initialLocale;
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
/**
* Locales having a different decimal and grouping separators to test string parsing and generation.
*/
@@ -46,6 +67,7 @@ public class PercentTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testKnownInvalidConstructors(Locale locale) {
Locale.setDefault(locale);
@@ -85,6 +107,7 @@ public class PercentTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testLocalizedStringConstruction(Locale defaultLocale) {
Locale.setDefault(defaultLocale);
@@ -106,6 +129,7 @@ public class PercentTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void negativeNumber(Locale defaultLocale) {
Locale.setDefault(defaultLocale);
@@ -119,6 +143,7 @@ public class PercentTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void moreThan100(Locale defaultLocale) {
Locale.setDefault(defaultLocale);
@@ -33,7 +33,12 @@ import javax.measure.quantity.Pressure;
import javax.measure.quantity.Temperature;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
@@ -58,11 +63,27 @@ import org.osgi.service.component.ComponentContext;
*/
@ExtendWith(MockitoExtension.class)
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class QuantityTypeArithmeticGroupFunctionTest {
@Nullable
private static Locale initialLocale;
private @Mock @NonNullByDefault({}) ComponentContext componentContext;
private final UnitProvider unitProvider = new TestUnitProvider();
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
/**
* Locales having a different decimal and grouping separators to test string parsing and generation.
*/
@@ -78,6 +99,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityType(Locale locale) {
Locale.setDefault(locale);
@@ -96,6 +118,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityTypeDifferentUnits(Locale locale) {
Locale.setDefault(locale);
@@ -114,6 +137,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityTypeIncompatibleUnits(Locale locale) {
Locale.setDefault(locale);
@@ -130,6 +154,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityType(Locale locale) {
Locale.setDefault(locale);
@@ -156,6 +181,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityTypeDifferentUnits(Locale locale) {
Locale.setDefault(locale);
@@ -175,6 +201,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityTypeIncompatibleUnits(Locale locale) {
Locale.setDefault(locale);
@@ -238,6 +265,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionQuantityType(Locale locale) {
Locale.setDefault(locale);
@@ -256,6 +284,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionQuantityTypeDifferentUnits(Locale locale) {
Locale.setDefault(locale);
@@ -274,6 +303,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionQuantityTypeIncompatibleUnits(Locale locale) {
Locale.setDefault(locale);
@@ -290,6 +320,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMinFunctionQuantityType(Locale locale) {
Locale.setDefault(locale);
@@ -308,6 +339,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionQuantityTypeOnDimensionless(Locale locale) {
Locale.setDefault(locale);
@@ -327,6 +359,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMinFunctionQuantityTypeDifferentUnits(Locale locale) {
Locale.setDefault(locale);
@@ -345,6 +378,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMinFunctionQuantityTypeIncompatibleUnits(Locale locale) {
Locale.setDefault(locale);
@@ -361,6 +395,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityTypeWithGroups(Locale locale) {
Locale.setDefault(locale);
@@ -389,6 +424,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityTypeDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -407,6 +443,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityTypeDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -426,6 +463,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionQuantityTypeDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -444,6 +482,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMinFunctionQuantityTypeDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -462,6 +501,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionColorTemperatureDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -481,6 +521,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityTypeColorTempDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -500,6 +541,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAvgFunctionQuantityTypeColorTempDifferentUnitsBaseMirek(Locale locale) {
Locale.setDefault(locale);
@@ -519,6 +561,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMinFunctionColorTemperatureDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -538,6 +581,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testMaxFunctionColorTemperatureDifferentUnitsBaseKelvin(Locale locale) {
Locale.setDefault(locale);
@@ -557,6 +601,7 @@ public class QuantityTypeArithmeticGroupFunctionTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSumFunctionQuantityTypeDifferentUnitsBaseWatt(Locale locale) {
Locale.setDefault(locale);
@@ -33,7 +33,12 @@ import javax.measure.quantity.Temperature;
import javax.measure.quantity.Time;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;
import org.openhab.core.library.dimension.DataAmount;
@@ -54,8 +59,24 @@ import tech.units.indriya.unit.UnitDimension;
*/
@SuppressWarnings("null")
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class QuantityTypeTest {
@Nullable
private static Locale initialLocale;
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
/**
* Locales having a different decimal and grouping separators to test string parsing and generation.
*/
@@ -82,6 +103,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testKnownInvalidConstructors(Locale locale) {
Locale.setDefault(locale);
@@ -117,6 +139,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testValidConstructors(Locale locale) {
Locale.setDefault(locale);
@@ -171,6 +194,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testLocalizedStringConstruction(Locale defaultLocale) {
Locale.setDefault(defaultLocale);
@@ -322,6 +346,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testConversionToHSBType(Locale locale) {
Locale.setDefault(locale);
@@ -332,6 +357,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testConversionToPercentType(Locale locale) {
Locale.setDefault(locale);
@@ -354,6 +380,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void toFullStringShouldParseToEqualState(Locale locale) {
Locale.setDefault(locale);
@@ -365,6 +392,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testAdd(Locale locale) {
Locale.setDefault(locale);
@@ -399,6 +427,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testSubtract(Locale locale) {
Locale.setDefault(locale);
@@ -475,6 +504,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testDivideNumber(Locale locale) {
Locale.setDefault(locale);
@@ -488,6 +518,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testDivideQuantityType(Locale locale) {
Locale.setDefault(locale);
@@ -544,6 +575,7 @@ public class QuantityTypeTest {
@ParameterizedTest
@MethodSource("locales")
@SuppressWarnings("PMD.SetDefaultLocale")
public void testDivideZero(Locale locale) {
Locale.setDefault(locale);
@@ -21,9 +21,14 @@ import java.util.Map;
import java.util.Map.Entry;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.parallel.Execution;
import org.junit.jupiter.api.parallel.ExecutionMode;
import org.openhab.core.automation.type.ModuleType;
import org.openhab.core.automation.type.ModuleTypeRegistry;
import org.openhab.core.storage.StorageService;
@@ -44,12 +49,16 @@ import org.slf4j.LoggerFactory;
*/
@SuppressWarnings("deprecation")
@NonNullByDefault
@Execution(ExecutionMode.SAME_THREAD)
public class HostFragmentSupportTest extends JavaOSGiTest {
private static final Locale BULGARIAN = Locale.of("bg");
private static final Locale DEFAULT = Locale.ENGLISH;
private static final Locale GERMAN = Locale.GERMANY;
@Nullable
private static Locale initialLocale;
private final Logger logger = LoggerFactory.getLogger(HostFragmentSupportTest.class);
private @NonNullByDefault({}) ModuleTypeRegistry registry;
private @NonNullByDefault({}) PackageAdmin pkgAdmin;
@@ -104,7 +113,20 @@ public class HostFragmentSupportTest extends JavaOSGiTest {
private boolean waiting = true;
@BeforeAll
public static void setUpClass() {
initialLocale = Locale.getDefault();
}
@AfterAll
@SuppressWarnings("PMD.SetDefaultLocale")
public static void tearDownClass() {
// Set the default locale to its initial value.
Locale.setDefault(initialLocale);
}
@BeforeEach
@SuppressWarnings("PMD.SetDefaultLocale")
public void before() {
logger.info("@Before.begin");