@Test
  public void testGeocodeWithComponentFilter() throws Exception {
    try (LocalTestServerContext sc =
        new LocalTestServerContext(
            "\n"
                + "{\n"
                + "   \"results\" : [\n"
                + "      {\n"
                + "         \"address_components\" : [\n"
                + "            {\n"
                + "               \"long_name\" : \"Santa Cruz de Tenerife\",\n"
                + "               \"short_name\" : \"Santa Cruz de Tenerife\",\n"
                + "               \"types\" : [ \"locality\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Santa Cruz de Tenerife\",\n"
                + "               \"short_name\" : \"TF\",\n"
                + "               \"types\" : [ \"administrative_area_level_2\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Canary Islands\",\n"
                + "               \"short_name\" : \"CN\",\n"
                + "               \"types\" : [ \"administrative_area_level_1\", \"political\" ]\n"
                + "            },\n"
                + "            {\n"
                + "               \"long_name\" : \"Spain\",\n"
                + "               \"short_name\" : \"ES\",\n"
                + "               \"types\" : [ \"country\", \"political\" ]\n"
                + "            }\n"
                + "         ],\n"
                + "         \"formatted_address\" : \"Santa Cruz de Tenerife, Spain\",\n"
                + "         \"geometry\" : {\n"
                + "            \"bounds\" : {\n"
                + "               \"northeast\" : {\n"
                + "                  \"lat\" : 28.487616,\n"
                + "                  \"lng\" : -16.2356646\n"
                + "               },\n"
                + "               \"southwest\" : {\n"
                + "                  \"lat\" : 28.4280248,\n"
                + "                  \"lng\" : -16.3370045\n"
                + "               }\n"
                + "            },\n"
                + "            \"location\" : {\n"
                + "               \"lat\" : 28.4636296,\n"
                + "               \"lng\" : -16.2518467\n"
                + "            },\n"
                + "            \"location_type\" : \"APPROXIMATE\",\n"
                + "            \"viewport\" : {\n"
                + "               \"northeast\" : {\n"
                + "                  \"lat\" : 28.487616,\n"
                + "                  \"lng\" : -16.2356646\n"
                + "               },\n"
                + "               \"southwest\" : {\n"
                + "                  \"lat\" : 28.4280248,\n"
                + "                  \"lng\" : -16.3370045\n"
                + "               }\n"
                + "            }\n"
                + "         },\n"
                + "         \"place_id\" : \"ChIJcUElzOzMQQwRLuV30nMUEUM\",\n"
                + "         \"types\" : [ \"locality\", \"political\" ]\n"
                + "      }\n"
                + "   ],\n"
                + "   \"status\" : \"OK\"\n"
                + "}\n")) {
      GeocodingResult[] results =
          GeocodingApi.newRequest(sc.context)
              .address("santa cruz")
              .components(ComponentFilter.country("ES"))
              .await()
              .results;

      assertNotNull(Arrays.toString(results));

      assertEquals("Santa Cruz de Tenerife, Spain", results[0].formattedAddress);
      assertEquals("ChIJcUElzOzMQQwRLuV30nMUEUM", results[0].placeId);

      sc.assertParamValue("country:ES", "components");
      sc.assertParamValue("santa cruz", "address");
    }
  }
Geocode with component filtering: <a
href="https://maps.googleapis.com/maps/api/geocode/json?address=santa+cruz&components=country:ES">
Geocoding "santa cruz" with country set to ES</a>.
src/test/java/com/google/maps/GeocodingApiTest.java