mirror of
https://gitlab.com/restcountries/restcountries.git
synced 2026-03-31 15:07:46 +01:00
WIP #286 fixing tests for flags and sovereign states
This commit is contained in:
@@ -124,8 +124,8 @@ class RestCountriesV4Test {
|
||||
var countries = CountryServiceV4.getInstance().getAll();
|
||||
try {
|
||||
var result = countries.stream().noneMatch(
|
||||
country -> null == country.getFlags().getPng() || null == country.getFlags().getSvg()
|
||||
|| null == country.getFlags().getAlt());
|
||||
country -> null == country.getFlag().getPng() || null == country.getFlag().getSvg()
|
||||
|| null == country.getFlag().getAlt() || null == country.getFlag().getEmoji());
|
||||
assertTrue(result);
|
||||
} catch (Exception ex) {
|
||||
Assertions.fail();
|
||||
@@ -185,4 +185,10 @@ class RestCountriesV4Test {
|
||||
var nonIndependent = CountryServiceV4.getInstance().getIndependent(false);
|
||||
assertFalse(nonIndependent.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSovereignState() {
|
||||
var aruba = CountryServiceV4.getInstance().getByAlpha("AW").stream().findFirst().orElseThrow();
|
||||
Assertions.assertEquals("NLD", aruba.getSovereignState());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -314,6 +314,32 @@ class V4JsonStructureTest {
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testFlagStructure() {
|
||||
for (JsonElement el : countries) {
|
||||
JsonObject c = el.getAsJsonObject();
|
||||
assertTrue(c.has("flag"), "Missing flag for " + c.get("cca2"));
|
||||
assertFalse(c.get("flag").isJsonNull(), "flag should not be null for " + c.get("cca2"));
|
||||
assertTrue(c.get("flag").isJsonObject(), "flag should be an object for " + c.get("cca2"));
|
||||
JsonObject flag = c.getAsJsonObject("flag");
|
||||
assertTrue(flag.has("svg"), "flag should have svg for " + c.get("cca2"));
|
||||
assertTrue(flag.has("png"), "flag should have png for " + c.get("cca2"));
|
||||
assertTrue(flag.has("alt"), "flag should have alt for " + c.get("cca2"));
|
||||
assertTrue(flag.has("emoji"), "flag should have emoji for " + c.get("cca2"));
|
||||
assertFalse(flag.get("emoji").getAsString().isEmpty(), "flag.emoji should not be empty for " + c.get("cca2"));
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
void testSovereignStateField() {
|
||||
for (JsonElement el : countries) {
|
||||
JsonObject c = el.getAsJsonObject();
|
||||
if (c.has("sovereignState")) {
|
||||
assertFalse(c.get("sovereignState").isJsonNull(), "sovereignState should not be null for " + c.get("cca2"));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void assertIsArrayIfPresent(JsonObject obj, String field) {
|
||||
if (obj.has(field) && !obj.get(field).isJsonNull()) {
|
||||
assertTrue(obj.get(field).isJsonArray(),
|
||||
|
||||
Reference in New Issue
Block a user