Skip to content

Commit

Permalink
Merge pull request #21 from codice/npe
Browse files Browse the repository at this point in the history
Added null safety to CCs that do not have numeric mapping
  • Loading branch information
bdeining authored Sep 17, 2019
2 parents 9a8315a + 24b5aca commit 804803c
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import static org.junit.Assert.assertThat;

import java.util.Set;
import org.codice.countrycode.CountryCodeSimple.StandardFormat;
import org.junit.Ignore;
import org.junit.Test;

Expand Down Expand Up @@ -101,6 +102,14 @@ public void testConversionNoNumericCode() {
assertThat("IP", equalTo(result.iterator().next()));
}

@Test
public void testConversionNonExistentCode() {
Set<String> result =
CountryCodeSimple.convert(
"ZZ", StandardFormat.ISO_3166_1_ALPHA2, StandardFormat.GENC_3_0_0_ALPHA3);
assertThat(0, equalTo(result.size()));
}

// todo this demonstrates a bug where the input format is ignored by the converter impl
// we should fix this bug
@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
*/
package org.codice.countrycode.standards.common;

import java.util.Objects;
import org.codice.countrycode.standard.CountryCode;

public class StandardUtils {
Expand All @@ -24,6 +25,8 @@ public static boolean containsFormatValue(CountryCode countryCode, String value)
.getStandard()
.getFormatNames()
.stream()
.anyMatch(formatName -> countryCode.getAsFormat(formatName).equalsIgnoreCase(value));
.map(formatName -> countryCode.getAsFormat(formatName))
.filter(Objects::nonNull)
.anyMatch(formatName -> formatName.equalsIgnoreCase(value));
}
}

0 comments on commit 804803c

Please sign in to comment.