[dedup] avoid NPEs in the countryInference dedup utility
This commit is contained in:
parent
8f551afa52
commit
75a11d0ba5
|
@ -90,7 +90,7 @@ public class AbstractPaceFunctions extends PaceCommonUtils {
|
||||||
inferFrom = normalize(inferFrom);
|
inferFrom = normalize(inferFrom);
|
||||||
inferFrom = filterAllStopWords(inferFrom);
|
inferFrom = filterAllStopWords(inferFrom);
|
||||||
Set<String> cities = getCities(inferFrom, 4);
|
Set<String> cities = getCities(inferFrom, 4);
|
||||||
return citiesToCountry(cities).stream().findFirst().orElse("UNKNOWN");
|
return citiesToCountry(cities).stream().filter(Objects::nonNull).findFirst().orElse("UNKNOWN");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String cityInference(String original) {
|
public static String cityInference(String original) {
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
|
|
||||||
package eu.dnetlib.pace.common;
|
package eu.dnetlib.pace.common;
|
||||||
|
|
||||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
import static org.junit.jupiter.api.Assertions.*;
|
||||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
|
||||||
|
|
||||||
import org.junit.jupiter.api.*;
|
import org.junit.jupiter.api.*;
|
||||||
|
|
||||||
|
@ -54,8 +53,17 @@ public class PaceFunctionTest extends AbstractPaceFunctions {
|
||||||
System.out.println("Fixed aliases : " + fixAliases(TEST_STRING));
|
System.out.println("Fixed aliases : " + fixAliases(TEST_STRING));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test()
|
||||||
|
public void countryInferenceTest_NPE() {
|
||||||
|
assertThrows(
|
||||||
|
NullPointerException.class,
|
||||||
|
() -> countryInference("UNKNOWN", null),
|
||||||
|
"Expected countryInference() to throw an NPE");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void countryInferenceTest() {
|
public void countryInferenceTest() {
|
||||||
|
assertEquals("UNKNOWN", countryInference("UNKNOWN", ""));
|
||||||
assertEquals("IT", countryInference("UNKNOWN", "Università di Bologna"));
|
assertEquals("IT", countryInference("UNKNOWN", "Università di Bologna"));
|
||||||
assertEquals("UK", countryInference("UK", "Università di Bologna"));
|
assertEquals("UK", countryInference("UK", "Università di Bologna"));
|
||||||
assertEquals("IT", countryInference("UNKNOWN", "Universiteé de Naples"));
|
assertEquals("IT", countryInference("UNKNOWN", "Universiteé de Naples"));
|
||||||
|
|
Loading…
Reference in New Issue