Add tests and changes for Base64Binary

This commit is contained in:
dotasek 2022-03-16 12:20:58 -04:00
parent 9903d15ecc
commit b5b43836eb
22 changed files with 335 additions and 122 deletions

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary10_30 {
public static org.hl7.fhir.dstu3.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu3.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
ConversionContext10_30.INSTANCE.getVersionConvertor_10_30().copyElement(src, tgt);
return tgt;
}

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary10_40 {
public static org.hl7.fhir.r4.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r4.model.Base64BinaryType();
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r4.model.Base64BinaryType();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r4.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
ConversionContext10_40.INSTANCE.getVersionConvertor_10_40().copyElement(src, tgt);
return tgt;
}

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary10_50 {
public static org.hl7.fhir.r5.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r5.model.Base64BinaryType();
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r5.model.Base64BinaryType();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r5.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
org.hl7.fhir.dstu2.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2.model.Base64BinaryType();
ConversionContext10_50.INSTANCE.getVersionConvertor_10_50().copyElement(src, tgt);
return tgt;
}

View File

@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary14_30 {
public static org.hl7.fhir.dstu3.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2016may.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = new org.hl7.fhir.dstu3.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2016may.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu3.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
ConversionContext14_30.INSTANCE.getVersionConvertor_14_30().copyElement(src, tgt);
return tgt;
}

View File

@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary14_40 {
public static org.hl7.fhir.r4.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2016may.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r4.model.Base64BinaryType tgt = new org.hl7.fhir.r4.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r4.model.Base64BinaryType();
ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2016may.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r4.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
ConversionContext14_40.INSTANCE.getVersionConvertor_14_40().copyElement(src, tgt);
return tgt;
}

View File

@ -5,15 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary14_50 {
public static org.hl7.fhir.r5.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu2016may.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r5.model.Base64BinaryType tgt = new org.hl7.fhir.r5.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r5.model.Base64BinaryType();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu2016may.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r5.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
if (src.hasValue()) tgt.setValue(src.getValue());
org.hl7.fhir.dstu2016may.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu2016may.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu2016may.model.Base64BinaryType();
ConversionContext14_50.INSTANCE.getVersionConvertor_14_50().copyElement(src, tgt);
return tgt;
}

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary30_40 {
public static org.hl7.fhir.r4.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu3.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r4.model.Base64BinaryType();
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r4.model.Base64BinaryType();
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu3.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r4.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
ConversionContext30_40.INSTANCE.getVersionConvertor_30_40().copyElement(src, tgt);
return tgt;
}

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary30_50 {
public static org.hl7.fhir.r5.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.dstu3.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r5.model.Base64BinaryType();
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r5.model.Base64BinaryType();
ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.dstu3.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r5.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
org.hl7.fhir.dstu3.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.dstu3.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.dstu3.model.Base64BinaryType();
ConversionContext30_50.INSTANCE.getVersionConvertor_30_50().copyElement(src, tgt);
return tgt;
}

View File

@ -5,13 +5,13 @@ import org.hl7.fhir.exceptions.FHIRException;
public class Base64Binary40_50 {
public static org.hl7.fhir.r5.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r4.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r5.model.Base64BinaryType();
org.hl7.fhir.r5.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r5.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r5.model.Base64BinaryType();
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
return tgt;
}
public static org.hl7.fhir.r4.model.Base64BinaryType convertBase64Binary(org.hl7.fhir.r5.model.Base64BinaryType src) throws FHIRException {
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValue()) : new org.hl7.fhir.r4.model.Base64BinaryType();
org.hl7.fhir.r4.model.Base64BinaryType tgt = src.hasValue() ? new org.hl7.fhir.r4.model.Base64BinaryType(src.getValueAsString()) : new org.hl7.fhir.r4.model.Base64BinaryType();
ConversionContext40_50.INSTANCE.getVersionConvertor_40_50().copyElement(src, tgt);
return tgt;
}

View File

@ -15,6 +15,10 @@ import java.util.stream.Stream;
public class VersionConvertorPrimitiveTypeTests {
private static String[] BASE64_BINARY_STRINGS = {
"dGhpcyBpcyB2YWxpZCBiYXNlNjQ="
};
private static String[] DEFAULT_DATE_PRECISION_STRINGS = {
"1933", "1933-01", "1933-01-02"
};
@ -41,6 +45,44 @@ public class VersionConvertorPrimitiveTypeTests {
private static Stream<Arguments> getParams() {
return Stream.of(
//Base64Binary
getDateTimeArgs(VersionConvertorFactory_10_30.class,
org.hl7.fhir.dstu2.model.Base64BinaryType.class, org.hl7.fhir.dstu2.model.Type.class,
org.hl7.fhir.dstu3.model.Base64BinaryType.class, org.hl7.fhir.dstu3.model.Type.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_10_40.class,
org.hl7.fhir.dstu2.model.Base64BinaryType.class, org.hl7.fhir.dstu2.model.Type.class,
org.hl7.fhir.r4.model.Base64BinaryType.class, org.hl7.fhir.r4.model.Type.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_10_50.class,
org.hl7.fhir.dstu2.model.Base64BinaryType.class, org.hl7.fhir.dstu2.model.Type.class,
org.hl7.fhir.r5.model.Base64BinaryType.class, org.hl7.fhir.r5.model.DataType.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_14_30.class,
org.hl7.fhir.dstu2016may.model.Base64BinaryType.class, org.hl7.fhir.dstu2016may.model.Type.class,
org.hl7.fhir.dstu3.model.Base64BinaryType.class, org.hl7.fhir.dstu3.model.Type.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_14_40.class,
org.hl7.fhir.dstu2016may.model.Base64BinaryType.class, org.hl7.fhir.dstu2016may.model.Type.class,
org.hl7.fhir.r4.model.Base64BinaryType.class, org.hl7.fhir.r4.model.Type.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_14_50.class,
org.hl7.fhir.dstu2016may.model.Base64BinaryType.class, org.hl7.fhir.dstu2016may.model.Type.class,
org.hl7.fhir.r5.model.Base64BinaryType.class, org.hl7.fhir.r5.model.DataType.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_30_40.class,
org.hl7.fhir.dstu3.model.Base64BinaryType.class, org.hl7.fhir.dstu3.model.Type.class,
org.hl7.fhir.r4.model.Base64BinaryType.class, org.hl7.fhir.r4.model.Type.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_30_50.class,
org.hl7.fhir.dstu3.model.Base64BinaryType.class, org.hl7.fhir.dstu3.model.Type.class,
org.hl7.fhir.r5.model.Base64BinaryType.class, org.hl7.fhir.r5.model.DataType.class,
BASE64_BINARY_STRINGS),
getDateTimeArgs(VersionConvertorFactory_40_50.class,
org.hl7.fhir.r4.model.Base64BinaryType.class, org.hl7.fhir.r4.model.Type.class,
org.hl7.fhir.r5.model.Base64BinaryType.class, org.hl7.fhir.r5.model.DataType.class,
BASE64_BINARY_STRINGS),
//Date
getDateTimeArgs(VersionConvertorFactory_10_30.class,
org.hl7.fhir.dstu2.model.DateType.class, org.hl7.fhir.dstu2.model.Type.class,

View File

@ -58,10 +58,15 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@Override
public void setValueAsString(String theValue) {
if (theValue != null) checkValidBase64(theValue);
super.setValueAsString(theValue);
}
protected byte[] parse(String theValue) {
if (theValue != null) {
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));

View File

@ -9,11 +9,19 @@ import static org.junit.jupiter.api.Assertions.*;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -26,13 +34,33 @@ class Base64BinaryTypeTest {
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}

View File

@ -59,10 +59,15 @@ public class Base64BinaryType extends PrimitiveType<byte[]> {
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@Override
public void setValueAsString(String theString) {
if (theString != null) checkValidBase64(theString);
super.setValueAsString(theString);
}
protected byte[] parse(String theValue) {
if (theValue != null) {
return Base64.decodeBase64(theValue.getBytes(ca.uhn.fhir.rest.api.Constants.CHARSET_UTF8));

View File

@ -9,11 +9,19 @@ import static org.junit.jupiter.api.Assertions.*;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -26,13 +34,33 @@ class Base64BinaryTypeTest {
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}

View File

@ -67,7 +67,6 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@ -117,6 +116,8 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
@Override
public void setValueAsString(String theValue) throws IllegalArgumentException {
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
fromStringValue(theValue);
setValue(parse(theValue));
}

View File

@ -9,11 +9,19 @@ import static org.junit.jupiter.api.Assertions.*;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -26,13 +34,33 @@ class Base64BinaryTypeTest {
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}

View File

@ -68,7 +68,6 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@ -118,6 +117,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
@Override
public void setValueAsString(String theValue) throws IllegalArgumentException {
if (theValue != null) checkValidBase64(theValue);
fromStringValue(theValue);
setValue(parse(theValue));
}

View File

@ -9,11 +9,19 @@ import static org.junit.jupiter.api.Assertions.*;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -26,13 +34,33 @@ class Base64BinaryTypeTest {
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}

View File

@ -67,7 +67,6 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@ -117,6 +116,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
@Override
public void setValueAsString(String theValue) throws IllegalArgumentException {
if (theValue != null) checkValidBase64(theValue);
fromStringValue(theValue);
setValue(parse(theValue));
}

View File

@ -10,11 +10,19 @@ import ca.uhn.fhir.parser.DataFormatException;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -28,13 +36,32 @@ class Base64BinaryTypeTest {
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}

View File

@ -67,7 +67,6 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
public Base64BinaryType(String theValue) {
super();
// Null values still result in non-null instance being created
if (theValue != null) checkValidBase64(theValue);
setValueAsString(theValue);
}
@ -117,6 +116,7 @@ public class Base64BinaryType extends PrimitiveType<byte[]> implements IPrimitiv
@Override
public void setValueAsString(String theValue) throws IllegalArgumentException {
if (theValue != null) checkValidBase64(theValue);
fromStringValue(theValue);
setValue(parse(theValue));
}

View File

@ -10,11 +10,19 @@ import ca.uhn.fhir.parser.DataFormatException;
class Base64BinaryTypeTest {
static final String NON_BASE_64 = "Picard was the best starship captain.";
static final String VALID_BASE_64 = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
@Test
@DisplayName("Passing a non Base64 encoded String to constructor causes exception.")
public void testNonBase64String() {
String nonBase64 = "Picard was the best starship captain.";
assertThrows(DataFormatException.class, () -> new Base64BinaryType(nonBase64));
assertThrows(DataFormatException.class, () -> new Base64BinaryType(NON_BASE_64));
}
@Test
@DisplayName("Passing a non Base64 encoded String to setValueAsString causes exception.")
public void testNonBase64StringValueSet() {
Base64BinaryType instance = new Base64BinaryType();
assertThrows(DataFormatException.class, () -> instance.setValueAsString(NON_BASE_64));
}
@Test
@ -28,13 +36,32 @@ class Base64BinaryTypeTest {
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
String v = "dGhpcyBpcyB2YWxpZCBiYXNlNjQ=";
Base64BinaryType b64 = new Base64BinaryType(v);
@DisplayName("setValueAsString with null argument value sets instance value as null.")
public void testNullSetValueAsString() throws DataFormatException {
String v = null;
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(v);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(v, b64.asStringValue());
Assertions.assertNull(b64.getValue());
Assertions.assertNull(b64.getValueAsString());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValid() {
Base64BinaryType b64 = new Base64BinaryType(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
@Test
@DisplayName("Valid Base64 String creates non-null instance with non-null values.")
public void testValidSetValueAsString() {
Base64BinaryType b64 = new Base64BinaryType();
b64.setValueAsString(VALID_BASE_64);
Assertions.assertNotNull(b64);
Assertions.assertNotNull(b64.getValue());
Assertions.assertEquals(VALID_BASE_64, b64.asStringValue());
}
}