Skip to content

Commit 9966b3f

Browse files
committed
fix 2 failing java test
improve client declaration in the test
1 parent 33e30bf commit 9966b3f

21 files changed

+190
-211
lines changed

src/test/java/serpapi/AppleAppStoreTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "apple_app_store");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("term", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("term", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
3534
}
3635

src/test/java/serpapi/BaiduTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "baidu");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
3534
}
3635

src/test/java/serpapi/BingTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "bing");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
34-
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
33+
assertTrue(results.getAsJsonArray("organic_results").size() > 1);
3534
}
3635

3736
}

src/test/java/serpapi/DuckduckgoTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "duckduckgo");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
3534
}
3635

src/test/java/serpapi/EbayTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "ebay");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("_nkw", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("_nkw", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
3534
}
3635

src/test/java/serpapi/GoogleAutocompleteTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "google_autocomplete");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("suggestions").size() > 5);
3534
}
3635

src/test/java/serpapi/GoogleEventsTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "google_events");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("events_results").size() > 5);
3534
}
3635

src/test/java/serpapi/GoogleImagesTest.java

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "google_images");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("engine", "google_images");
32-
parameter.put("tbm", "isch");
33-
parameter.put("q", "coffee");
34-
35-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("engine", "google_images");
32+
parameter.put("tbm", "isch");
33+
parameter.put("q", "coffee");
34+
JsonObject results = client.search(parameter);
3635
assertTrue(results.getAsJsonArray("images_results").size() > 5);
3736
}
3837

src/test/java/serpapi/GoogleJobsTest.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,16 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "google_jobs");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "coffee");
32-
33-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "coffee");
32+
JsonObject results = client.search(parameter);
3433
assertTrue(results.getAsJsonArray("jobs_results").size() > 5);
3534
}
3635

src/test/java/serpapi/GoogleLocalServicesTest.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,17 @@ public void search() throws SerpApiException {
2020
if(System.getenv("API_KEY") == null)
2121
return;
2222

23-
// set search context
23+
// setup serpapi client
24+
Map<String, String> auth = new HashMap<>();
25+
auth.put("api_key", System.getenv("API_KEY"));
26+
SerpApi client = new SerpApi(auth);
27+
28+
// run search
2429
Map<String, String> parameter = new HashMap<>();
2530
parameter.put("engine", "google_local_services");
26-
parameter.put("api_key", System.getenv("API_KEY"));
27-
28-
SerpApi serpapi = new SerpApi(parameter);
29-
30-
// set search parameter
31-
parameter.put("q", "electrician");
32-
parameter.put("data_cid", "6745062158417646970");
33-
34-
JsonObject results = serpapi.search(parameter);
31+
parameter.put("q", "electrician");
32+
parameter.put("data_cid", "6745062158417646970");
33+
JsonObject results = client.search(parameter);
3534
assertTrue(results.getAsJsonArray("local_ads").size() > 5);
3635
}
3736

0 commit comments

Comments
 (0)