Skip to content

Commit 6b91f3b

Browse files
committed
Fix locale for tests
1 parent 8021911 commit 6b91f3b

File tree

2 files changed

+21
-37
lines changed

2 files changed

+21
-37
lines changed

weasis-dicom-tools/src/test/java/org/dcm4che3/img/util/DicomUtilsTest.java

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -29,34 +29,26 @@
2929
import org.dcm4che3.data.Attributes;
3030
import org.dcm4che3.data.Tag;
3131
import org.dcm4che3.data.VR;
32-
import org.junit.jupiter.api.AfterAll;
32+
import org.junit.jupiter.api.AfterEach;
3333
import org.junit.jupiter.api.Assertions;
34-
import org.junit.jupiter.api.BeforeAll;
34+
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.DisplayName;
3636
import org.junit.jupiter.api.Test;
37-
import org.junit.jupiter.api.TestInstance;
3837

39-
@TestInstance(
40-
TestInstance.Lifecycle.PER_CLASS) // To enable BeforeAll and AfterAll for Locale.setDefault()
4138
class DicomUtilsTest {
4239

43-
private static final String ORIGINAL_LANGUAGE = System.getProperty("user.language", "en");
44-
private static final String ORIGINAL_COUNTRY = System.getProperty("user.country", "US");
40+
private Locale defaultLocale;
4541

46-
@BeforeAll
47-
public void setUpAll() {
48-
System.setProperty("user.language", "en");
49-
System.setProperty("user.country", "US");
50-
// Clear the Locale cache
42+
@BeforeEach
43+
public void setUp() {
44+
// Save the default locale to restore it after the test
45+
defaultLocale = Locale.getDefault();
5146
Locale.setDefault(Locale.US);
5247
}
5348

54-
@AfterAll
55-
public void tearDownAll() {
56-
System.setProperty("user.language", ORIGINAL_LANGUAGE);
57-
System.setProperty("user.country", ORIGINAL_COUNTRY);
58-
// Clear the Locale cache
59-
Locale.setDefault(new Locale(ORIGINAL_LANGUAGE, ORIGINAL_COUNTRY));
49+
@AfterEach
50+
public void tearDown() {
51+
Locale.setDefault(defaultLocale);
6052
}
6153

6254
@Test

weasis-dicom-tools/src/test/java/org/weasis/dicom/ref/AnatomicBuilderTest.java

Lines changed: 11 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,24 @@
1717

1818
import java.util.Locale;
1919
import java.util.Objects;
20-
import org.junit.jupiter.api.AfterAll;
21-
import org.junit.jupiter.api.BeforeAll;
20+
import org.junit.jupiter.api.AfterEach;
21+
import org.junit.jupiter.api.BeforeEach;
2222
import org.junit.jupiter.api.Test;
23-
import org.junit.jupiter.api.TestInstance;
2423
import org.weasis.dicom.ref.AnatomicBuilder.Category;
2524

26-
@TestInstance(
27-
TestInstance.Lifecycle.PER_CLASS) // To enable BeforeAll and AfterAll for Locale.setDefault()
2825
class AnatomicBuilderTest {
29-
private static final String ORIGINAL_LANGUAGE = System.getProperty("user.language", "en");
30-
private static final String ORIGINAL_COUNTRY = System.getProperty("user.country", "US");
31-
32-
@BeforeAll
33-
public void setUpAll() {
34-
System.setProperty("user.language", "fr");
35-
System.setProperty("user.country", "FR");
36-
// Clear the Locale cache
26+
private Locale defaultLocale;
27+
28+
@BeforeEach
29+
public void setUp() {
30+
// Save the default locale to restore it after the test
31+
defaultLocale = Locale.getDefault();
3732
Locale.setDefault(Locale.FRANCE);
3833
}
3934

40-
@AfterAll
41-
public void tearDownAll() {
42-
System.setProperty("user.language", ORIGINAL_LANGUAGE);
43-
System.setProperty("user.country", ORIGINAL_COUNTRY);
44-
// Clear the Locale cache
45-
Locale.setDefault(new Locale(ORIGINAL_LANGUAGE, ORIGINAL_COUNTRY));
35+
@AfterEach
36+
public void tearDown() {
37+
Locale.setDefault(defaultLocale);
4638
}
4739

4840
@Test

0 commit comments

Comments
 (0)