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
@@ -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");