### Question:
R4AddressFhirToDhisTransformerUtils extends AbstractAddressFhirToDhisTransformerUtils { @Nullable @Override public ICompositeType getPrimaryAddress( @Nonnull List<? extends ICompositeType> addresses ) { return getOptionalPrimaryAddress( addresses ).orElse( new Address() ); } R4AddressFhirToDhisTransformerUtils( @Nonnull ScriptExecutionContext scriptExecutionContext, @Nonnull R4DateTimeFhirToDhisTransformerUtils dateTimeTransformerUtils ); @Nonnull @Override Set<FhirVersion> getFhirVersions(); @Nullable @Override ICompositeType getPrimaryAddress( @Nonnull List<? extends ICompositeType> addresses ); @Nullable @Override String getSingleLine( @Nullable ICompositeType address, @Nonnull String delimiter ); @Nullable @Override String getConstructedText( @Nullable ICompositeType address, @Nonnull String delimiter ); @Nullable @Override String getText( @Nullable ICompositeType address );  }### Answer:
@Test public void primaryExpired() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.HOME ) .setPeriod( new Period().setEnd( Date.from( ZonedDateTime.now().minusDays( 1 ).toInstant() ) ) ) ); addresses.add( new Address().setType( Address.AddressType.POSTAL ).setUse( Address.AddressUse.OLD ) ); Assert.assertSame( addresses.get( 1 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryTemp() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.TEMP ) ); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.OLD ) ); Assert.assertSame( addresses.get( 0 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryWork() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.HOME ) ); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.WORK ) ); Assert.assertSame( addresses.get( 0 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryNull() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.NULL ) ); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.WORK ) ); Assert.assertSame( addresses.get( 0 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryUnspecified() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ) ); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.WORK ) ); Assert.assertSame( addresses.get( 0 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryPhysical() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.PHYSICAL ).setUse( Address.AddressUse.HOME ) ); addresses.add( new Address().setType( Address.AddressType.POSTAL ).setUse( Address.AddressUse.HOME ) ); Assert.assertSame( addresses.get( 0 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryBoth() { final List<Address> addresses = new ArrayList<>(); addresses.add( new Address().setType( Address.AddressType.POSTAL ).setUse( Address.AddressUse.HOME ) ); addresses.add( new Address().setType( Address.AddressType.BOTH ).setUse( Address.AddressUse.HOME ) ); Assert.assertSame( addresses.get( 1 ), utils.getPrimaryAddress( addresses ) ); }
@Test public void primaryEmpty() { final List<Address> addresses = new ArrayList<>(); Assert.assertNotNull( utils.getPrimaryAddress( addresses ) ); }