Java源码示例:com.maxmind.geoip2.record.Continent

示例1
@Test
public void lookupShouldReturnCountryIsoWhenDatabaseReaderWasSet() throws NoSuchFieldException, IOException,
        GeoIp2Exception {
    // given
    final Country country = new Country(null, null, null, "fr", null);
    final Continent continent = new Continent(null, "eu", null, null);
    final City city = new City(singletonList("test"), null, null, singletonMap("test", "Paris"));
    final Location location = new Location(null, null, 48.8566, 2.3522,
            null, null, null);
    final ArrayList<Subdivision> subdivisions = new ArrayList<>();
    subdivisions.add(new Subdivision(null, null, null, "paris", null));
    final CityResponse cityResponse = new CityResponse(city, continent, country, location, null,
            null, null, null, subdivisions, null);

    final DatabaseReader databaseReader = Mockito.mock(DatabaseReader.class);
    given(databaseReader.city(any())).willReturn(cityResponse);

    FieldSetter.setField(maxMindGeoLocationService,
            maxMindGeoLocationService.getClass().getDeclaredField("databaseReader"), databaseReader);

    // when
    final Future<GeoInfo> future = maxMindGeoLocationService.lookup(TEST_IP, null);

    // then
    assertThat(future.succeeded()).isTrue();
    assertThat(future.result())
            .isEqualTo(GeoInfo.builder()
                    .vendor("maxmind")
                    .continent("eu")
                    .country("fr")
                    .region("paris")
                    .city("Paris")
                    .lat(48.8566f)
                    .lon(2.3522f)
                    .build());
}
 
示例2
protected void extractCountryFields(final Parsable<?> parsable, final String inputname, AbstractCountryResponse response)
    throws DissectionFailure {
    if (wantAnyContinent) {
        Continent continent = response.getContinent();
        if (continent != null) {
            if (wantContinentName) {
                parsable.addDissection(inputname, "STRING", "continent.name", continent.getName());
            }
            if (wantContinentCode) {
                parsable.addDissection(inputname, "STRING", "continent.code", continent.getCode());
            }
        }
    }
    if (wantAnyCountry) {
        Country country = response.getCountry();
        if (country != null) {
            if (wantCountryName) {
                parsable.addDissection(inputname, "STRING", "country.name", country.getName());
            }
            if (wantCountryIso) {
                parsable.addDissection(inputname, "STRING", "country.iso", country.getIsoCode());
            }

            if (wantCountryGetConfidence) {
                parsable.addDissection(inputname, "NUMBER", "country.getconfidence", country.getConfidence());
            }
            if (wantCountryIsInEuropeanUnion) {
                parsable.addDissection(inputname, "BOOLEAN", "country.isineuropeanunion", country.isInEuropeanUnion() ? 1L : 0L);
            }
        }
    }
}