Skip to content

Commit 56305b6

Browse files
jvmvikclaude
andcommitted
fix(test): stop GoogleEventsTest NPE on empty events_results
The google_events engine returned no events_results for q=coffee, so getAsJsonArray returned null and .size() threw an NPE, failing CI. Use a location-scoped query, assert non-null with the response body in the message so future failures are diagnosable, and relax the size threshold from >5 to >0. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent ec86d1a commit 56305b6

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/test/java/serpapi/example/GoogleEventsTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package serpapi.example;
22
import serpapi.*;
33

4+
import com.google.gson.JsonArray;
45
import com.google.gson.JsonObject;
56
import com.google.gson.JsonPrimitive;
67
import org.junit.Test;
@@ -29,9 +30,11 @@ public void search() throws SerpApiException {
2930
// run search
3031
Map<String, String> parameter = new HashMap<>();
3132
parameter.put("engine", "google_events");
32-
parameter.put("q", "coffee");
33+
parameter.put("q", "Events in Austin, TX");
3334
JsonObject results = client.search(parameter);
34-
assertTrue(results.getAsJsonArray("events_results").size() > 5);
35+
JsonArray events = results.getAsJsonArray("events_results");
36+
assertNotNull("no events_results in response: " + results, events);
37+
assertTrue(events.size() > 0);
3538
}
3639

3740
}

0 commit comments

Comments
 (0)