use of org.hl7.fhir.convertors.conv14_50.VersionConvertor_14_50 in project org.hl7.fhir.core by hapifhir.
the class VersionConvertorPrimitiveTypeTests method testDirectConversion.
@ParameterizedTest(name = "Test index: {index} Source Class={1} First Value={3} Second Class={4} Second Value={6}")
@MethodSource("getDirectConversionParams")
public <K, L> void testDirectConversion(Class<K> srcTypeClazz, Class<L> tgtTypeClazz, Function<K, L> convertFunction, String[] srcStrings, String[] tgtStrings) throws NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException {
ConversionContext10_30.INSTANCE.init(mock(VersionConvertor_10_30.class), CONTEXT_PATH);
ConversionContext10_40.INSTANCE.init(mock(VersionConvertor_10_40.class), CONTEXT_PATH);
ConversionContext10_50.INSTANCE.init(mock(VersionConvertor_10_50.class), CONTEXT_PATH);
ConversionContext14_50.INSTANCE.init(mock(VersionConvertor_14_50.class), CONTEXT_PATH);
ConversionContext30_50.INSTANCE.init(mock(VersionConvertor_30_50.class), CONTEXT_PATH);
ConversionContext40_50.INSTANCE.init(mock(VersionConvertor_40_50.class), CONTEXT_PATH);
Method srcSetValueAsStringMethod = srcTypeClazz.getMethod("setValueAsString", String.class);
Method srcGetValueAsString = srcTypeClazz.getMethod("getValueAsString");
Method srcHasValue = srcTypeClazz.getMethod("hasValue");
for (int i = 0; i < srcStrings.length; i++) {
K srcInstance = srcTypeClazz.getDeclaredConstructor().newInstance();
srcSetValueAsStringMethod.invoke(srcInstance, srcStrings[i]);
String srcValueAsString = (String) srcGetValueAsString.invoke(srcInstance);
Assertions.assertEquals(srcStrings[i], srcValueAsString);
boolean srcHasValueReturn = (boolean) srcHasValue.invoke(srcInstance);
L tgtInstance = convertFunction.apply(srcInstance);
Method tgtGetValueAsString = tgtTypeClazz.getMethod("getValueAsString");
Method tgtHasValue = tgtTypeClazz.getMethod("hasValue");
if (srcHasValueReturn) {
String tgtValueAsString = (String) tgtGetValueAsString.invoke(tgtInstance);
Assertions.assertEquals(tgtStrings[i], tgtValueAsString);
} else {
boolean tgtHasValueReturn = (boolean) tgtHasValue.invoke(tgtInstance);
Assertions.assertFalse(tgtHasValueReturn);
}
}
ConversionContext10_30.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_40.INSTANCE.close(CONTEXT_PATH);
ConversionContext10_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext14_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext30_50.INSTANCE.close(CONTEXT_PATH);
ConversionContext40_50.INSTANCE.close(CONTEXT_PATH);
}
Aggregations