### Question:
Dstu3VitalSignFhirToDhisTransformerUtils extends AbstractVitalSignFhirToDhisTransformerUtils { @Nullable @Override public Double getWeight( @Nullable ICompositeType value, @Nullable Object weightUnit, boolean round ) throws TransformerDataException { if ( value == null ) { return null; } if ( weightUnit == null ) { throw new TransformerMappingException( "Weight unit has not been specified." ); } final WeightUnit resultingWeightUnit; try { resultingWeightUnit = NameUtils.toEnumValue( WeightUnit.class, weightUnit ); } catch ( IllegalArgumentException e ) { throw new TransformerMappingException( "Specified weight unit is invalid: " + weightUnit ); } if ( !(value instanceof Quantity) ) { throw new TransformerDataException( "Weight must be included as quantity, but element is " + value.getClass().getSimpleName() + "." ); } final Quantity quantity = (Quantity) value; if ( !UNIT_SYSTEM.equals( quantity.getSystem() ) ) { throw new TransformerDataException( UNIT_SYSTEM + " is expected as unit system: " + quantity.getSystem() ); } final WeightUnit actualWeightUnit = WeightUnit.getByUcumCode( quantity.getCode() ); if ( actualWeightUnit == null ) { throw new TransformerDataException( "Unknown UCUM weight unit code: " + quantity.getCode() ); } final BigDecimal actualValue = quantity.getValue(); if ( actualValue == null ) { return null; } final double convertedValue = actualWeightUnit.convertTo( actualValue.doubleValue(), resultingWeightUnit ); return round ? Math.round( convertedValue ) : convertedValue; } Dstu3VitalSignFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); @Nullable @Override Double getWeight( @Nullable ICompositeType value, @Nullable Object weightUnit, boolean round ); @Nullable @Override Double getHeight( @Nullable ICompositeType value, @Nullable Object heightUnit, boolean round ); static final String UNIT_SYSTEM; }### Answer:
@Test public void getWeight() { final Observation observation = new Observation(); observation.addComponent().setValue( new Quantity().setValue( 3.38 ).setSystem( "http: Assert.assertEquals( (Double) 3380.0, utils.getWeight( observation.getComponent().get( 0 ).getValueQuantity(), "gram", false ) ); }
@Test public void getWeightRounded() { final Observation observation = new Observation(); observation.addComponent().setValue( new Quantity().setValue( 3.38 ).setSystem( "http: Assert.assertEquals( (Double) 3.0, utils.getWeight( observation.getComponent().get( 0 ).getValueQuantity(), "kilo_gram", true ) ); }