Skip to content

Commit

Permalink
Fix Locale and TimeZone in tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nroduit committed Jul 26, 2024
1 parent 6b91f3b commit 04a8c67
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.util.TimeZone;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultTimeZone;

class DateTimeUtilsTest {
@Test
Expand Down Expand Up @@ -60,6 +61,7 @@ void testGetDicomTime() {

@Test
@DisplayName("Convert Date to LocalDate")
@DefaultTimeZone("UTC")
void testGetDateToLocalDate() {
assertNull(DateTimeUtils.toLocalDate(null));

Expand All @@ -75,6 +77,7 @@ void testGetDateToLocalDate() {

@Test
@DisplayName("Convert Date to LocalTime")
@DefaultTimeZone("UTC")
void testGetDateToLocalTime() {
assertNull(DateTimeUtils.toLocalTime(null));

Expand All @@ -90,6 +93,7 @@ void testGetDateToLocalTime() {

@Test
@DisplayName("Convert date to LocalDateTime")
@DefaultTimeZone("UTC")
void testGetDateToLocalDateTime() {
assertNull(DateTimeUtils.toLocalDateTime(null));

Expand All @@ -105,6 +109,7 @@ void testGetDateToLocalDateTime() {

@Test
@DisplayName("Get DateTime")
@DefaultTimeZone("UTC")
void testGetDateTime() {
assertNull(DateTimeUtils.dateTime((LocalDate) null, null));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,28 +29,14 @@
import org.dcm4che3.data.Attributes;
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.VR;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;
import org.junitpioneer.jupiter.DefaultTimeZone;

class DicomUtilsTest {

private Locale defaultLocale;

@BeforeEach
public void setUp() {
// Save the default locale to restore it after the test
defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
}

@AfterEach
public void tearDown() {
Locale.setDefault(defaultLocale);
}

@Test
@DisplayName("Get Period with different dates")
void testGetPeriod() {
Expand Down Expand Up @@ -158,6 +144,7 @@ void testIsNative() {

@Test
@DisplayName("Format text with different values and formats")
@DefaultLocale(language = "en", country = "US")
void testGetFormattedText() {
assertEquals("Value", DicomUtils.getFormattedText("Value", "Format"));
assertEquals("", DicomUtils.getFormattedText(null, "foo"));
Expand Down Expand Up @@ -208,6 +195,7 @@ void shouldFormatNonStringValue() {

@Test
@DisplayName("Format value with decimal and pattern")
@DefaultLocale(language = "en", country = "US")
void shouldFormatValueWithDecimalAndPattern() {
String result = DicomUtils.formatValue("1.2345", true, "$V:f$0.00$");
assertEquals("1.23", result);
Expand Down Expand Up @@ -257,6 +245,7 @@ void testGetStringArrayFromDicomElement() {

@Test
@DisplayName("Get Date from Dicom Element")
@DefaultTimeZone("Europe/Paris")
void testGetDateFromDicomElement() {
TimeZone timeZone = TimeZone.getDefault();
Attributes attributes = new Attributes();
Expand All @@ -280,6 +269,7 @@ void testGetDateFromDicomElement() {

@Test
@DisplayName("Get date array from Dicom Element with default value")
@DefaultTimeZone("Europe/Paris")
void testGetDatesFromDicomElement() {
TimeZone timeZone = TimeZone.getDefault();
Attributes dicom = new Attributes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,27 +15,12 @@
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertTrue;

import java.util.Locale;
import java.util.Objects;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;
import org.weasis.dicom.ref.AnatomicBuilder.Category;

class AnatomicBuilderTest {
private Locale defaultLocale;

@BeforeEach
public void setUp() {
// Save the default locale to restore it after the test
defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.FRANCE);
}

@AfterEach
public void tearDown() {
Locale.setDefault(defaultLocale);
}

@Test
void getAllBodyParts_returnsAllBodyParts() {
Expand All @@ -53,6 +38,7 @@ void getBodyPartsFromPredicate_returnsFilteredBodyParts() {
}

@Test
@DefaultLocale(language = "fr", country = "CH")
void getBodyPartFromCode() {
assertEquals(
BodyPart.values()[0], BodyPart.getBodyPartFromCode(BodyPart.values()[0].getCodeValue()));
Expand All @@ -70,6 +56,7 @@ void getBodyPartFromCode() {
}

@Test
@DefaultLocale(language = "fr", country = "CH")
void getBodyPartFromLegacyCode() {
assertEquals(
BodyPart.values()[0],
Expand Down Expand Up @@ -105,6 +92,7 @@ void getBodyPartFromCodeMeaning() {
}

@Test
@DefaultLocale(language = "fr", country = "CH")
void getAnatomicModifierFromCode() {
assertEquals(
AnatomicModifier.values()[0],
Expand All @@ -120,6 +108,7 @@ void getAnatomicModifierFromCode() {
}

@Test
@DefaultLocale(language = "fr", country = "CH")
void getSurfacePartFromCode() {
assertEquals(
SurfacePart.values()[0],
Expand Down Expand Up @@ -158,6 +147,7 @@ void getCodingScheme() {
}

@Test
@DefaultLocale(language = "fr", country = "CH")
void category() {
assertEquals("Sites anatomiques dermatologiques", Category.SURFACE.toString());

Expand Down

0 comments on commit 04a8c67

Please sign in to comment.