NitfAttributeConverters { @Nullable public static String fipsToStandardCountryCode(@Nullable String fipsCode) throws NitfAttributeTransformException { List<String> countryCodes = countryCodeConverter.convertFipsToIso3(fipsCode); if (countryCodes.size() > 1) { throw new NitfAttributeTransformException( String.format( "Found %s while converting %s, but expected only 1 conversion value.", countryCodes, fipsCode), fipsCode); } if (CollectionUtils.isEmpty(countryCodes)) { return null; } return countryCodes.get(0); } NitfAttributeConverters(CountryCodeConverter converter); @Nullable static Date nitfDate(@Nullable DateTime nitfDateTime); @Nullable static String fipsToStandardCountryCode(@Nullable String fipsCode);  }
@Test public void testValidFipsToSingleIso() { NitfTestCommons.setupNitfUtilities("US", Collections.singletonList("USA")); String convertedValue = NitfAttributeConverters.fipsToStandardCountryCode("US"); assertThat(convertedValue, is("USA")); }
@Test public void testInvalidFipsToSingleIso() { NitfTestCommons.setupNitfUtilities("US", Arrays.asList("USA", "CAN")); expectedException.expect(NitfAttributeTransformException.class); expectedException.expect(hasProperty("originalValue", is("US"))); NitfAttributeConverters.fipsToStandardCountryCode("US"); }
@Test public void testNoFipsToSingleIsoMapping() { NitfTestCommons.setupNitfUtilities("NOT_A_FIPS", Collections.emptyList()); assertThat(NitfAttributeConverters.fipsToStandardCountryCode("US"), is(nullValue())); }
@Test public void testNullFipsValue() { NitfTestCommons.setupNitfUtilities("US", Collections.singletonList("USA")); assertThat(NitfAttributeConverters.fipsToStandardCountryCode(null), is(nullValue())); }