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 f1a396c commit 1449f81
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class AnatomicBuilder {
public interface CategoryBuilder {
String getContextUID();

String getTIdentifier();
String getIdentifier();

String getTitle();
}
Expand All @@ -48,7 +48,7 @@ public String getContextUID() {
return ContextUID;
}

public String getTIdentifier() {
public String getIdentifier() {
return identifier;
}

Expand Down Expand Up @@ -98,7 +98,7 @@ public String getContextUID() {
}

@Override
public String getTIdentifier() {
public String getIdentifier() {
return identifier;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ public static void write(Attributes dcm, AnatomicRegion region) {
private static void writeRegionContext(Code code, CategoryBuilder category) {
if (category != null) {
code.setContextUID(category.getContextUID());
code.setContextIdentifier(category.getTIdentifier());
code.setContextIdentifier(category.getIdentifier());
}
}

Expand Down
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,24 +29,14 @@
import org.dcm4che3.data.Attributes;
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.VR;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;
import org.junitpioneer.jupiter.DefaultTimeZone;

@DefaultLocale(language = "en", country = "US")
class DicomUtilsTest {
static final Locale defaultLocale = Locale.getDefault();

@BeforeAll
static void setUp() {
Locale.setDefault(Locale.US); // Force Locale for testing date format
}

@AfterAll
static void tearDown() {
Locale.setDefault(defaultLocale);
}

@Test
@DisplayName("Get Period with different dates")
Expand Down Expand Up @@ -254,6 +244,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 @@ -277,6 +268,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,25 +15,13 @@
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.AfterAll;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;
import org.weasis.dicom.ref.AnatomicBuilder.Category;

@DefaultLocale(language = "en", country = "US")
class AnatomicBuilderTest {
static final Locale defaultLocale = Locale.getDefault();

@BeforeAll
static void setUp() {
Locale.setDefault(Locale.FRENCH); // Force Locale for testing date format
}

@AfterAll
static void tearDown() {
Locale.setDefault(defaultLocale);
}

@Test
void getAllBodyParts_returnsAllBodyParts() {
Expand All @@ -56,8 +44,8 @@ void getBodyPartFromCode() {
BodyPart.values()[0], BodyPart.getBodyPartFromCode(BodyPart.values()[0].getCodeValue()));

BodyPart bodyPart = BodyPart.getBodyPartFromCode("128559007");
assertEquals("Artère géniculaire", bodyPart.getCodeMeaning());
assertEquals("Artère géniculaire", bodyPart.toString());
assertEquals("Genicular artery", bodyPart.getCodeMeaning());
assertEquals("Genicular artery", bodyPart.toString());
assertEquals(CodingScheme.SCT, bodyPart.getCodingScheme());
assertTrue(bodyPart.isPaired());
assertFalse(bodyPart.isCommon());
Expand All @@ -74,7 +62,7 @@ void getBodyPartFromLegacyCode() {
AnatomicBuilder.getBodyPartFromLegacyCode(BodyPart.values()[0].getLegacyCode()));
BodyPart bodyPart = AnatomicBuilder.getBodyPartFromLegacyCode("PANCREATICDUCT");
assertNotNull(bodyPart);
assertEquals("Canal pancréatique", bodyPart.toString());
assertEquals("Pancreatic duct", bodyPart.toString());
assertEquals(CodingScheme.SCT, bodyPart.getCodingScheme());
assertFalse(bodyPart.isPaired());
assertTrue(bodyPart.isCommon());
Expand Down Expand Up @@ -110,7 +98,7 @@ void getAnatomicModifierFromCode() {

AnatomicModifier modifier = AnatomicModifier.getAnatomicModifierFromCode("49370004");
assertNotNull(modifier);
assertEquals("Latéral", modifier.toString());
assertEquals("Lateral", modifier.toString());
assertEquals(CodingScheme.SCT, modifier.getCodingScheme());

String key = "nonExistentKey";
Expand All @@ -125,7 +113,7 @@ void getSurfacePartFromCode() {

SurfacePart surfacePart = SurfacePart.getSurfacePartFromCode("130319");
assertNotNull(surfacePart);
assertEquals("Peau de l'hélix postérieur supérieur de l'oreille", surfacePart.toString());
assertEquals("Skin of superior posterior helix of ear", surfacePart.toString());
assertEquals(CodingScheme.DCM, surfacePart.getCodingScheme());
assertTrue(surfacePart.isPaired());
assertNull(surfacePart.getLegacyCode());
Expand Down Expand Up @@ -157,7 +145,7 @@ void getCodingScheme() {

@Test
void category() {
assertEquals("Sites anatomiques dermatologiques", Category.SURFACE.toString());
assertEquals("Dermatology Anatomic Site", Category.SURFACE.toString());

String key = "nonExistentKey";
assertEquals('!' + key + '!', MesCategory.getString(key));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
import org.dcm4che3.data.Tag;
import org.dcm4che3.data.VR;
import org.junit.jupiter.api.Test;
import org.junitpioneer.jupiter.DefaultLocale;
import org.weasis.dicom.ref.AnatomicBuilder.Category;
import org.weasis.dicom.ref.AnatomicBuilder.OtherCategory;

@DefaultLocale(language = "en", country = "US")
class AnatomicRegionTest {

@Test
Expand Down

0 comments on commit 1449f81

Please sign in to comment.