From 33a3d78ff321340def2d7ce2667b6ea8ae23b05c Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 3 Jan 2026 21:52:59 -0600 Subject: [PATCH 1/5] Update project to Java 21, Gradle 8.5, and modernize CI/CD Summary of changes: - Upgraded Java target to version 21. - Updated Gradle wrapper to version 8.5 for Java 21 compatibility. - Refactored SerpApi.java to remove incorrect inheritance from Exception. - Updated GitHub Actions workflow to use Java 21 and gradle-setup-java action. - Switched environment variable for API keys to SERPAPI_KEY in tests and CI. - Reorganized tests: moved engine examples to src/test/java/serpapi/example/. - Fixed failures in LocationApiTest and GoogleReverseImageTest. --- .github/workflows/gradle.yml | 13 +- LICENSE | 2 +- README.md | 2 +- README.md.erb | 2 +- build.gradle | 8 +- demo/Makefile | 6 +- demo/build.gradle | 3 + gradle/wrapper/gradle-wrapper.properties | 2 +- src/main/java/serpapi/SerpApi.java | 2 +- src/test/java/basic_search_result.json | 175 ------------------ src/test/java/serpapi/AccountApiTest.java | 4 +- src/test/java/serpapi/LocationApiTest.java | 4 +- src/test/java/serpapi/SearchApiTest.java | 41 ++++ ...ApiTest.java => SearchArchiveApiTest.java} | 29 +-- .../{ => example}/AppleAppStoreTest.java | 4 +- .../java/serpapi/{ => example}/BaiduTest.java | 4 +- .../java/serpapi/{ => example}/BingTest.java | 4 +- .../serpapi/{ => example}/DuckduckgoTest.java | 4 +- .../java/serpapi/{ => example}/EbayTest.java | 4 +- .../{ => example}/GoogleAutocompleteTest.java | 4 +- .../{ => example}/GoogleEventsTest.java | 4 +- .../{ => example}/GoogleImagesTest.java | 4 +- .../serpapi/{ => example}/GoogleJobsTest.java | 4 +- .../GoogleLocalServicesTest.java | 4 +- .../serpapi/{ => example}/GoogleMapsTest.java | 4 +- .../serpapi/{ => example}/GooglePlayTest.java | 4 +- .../{ => example}/GoogleProductTest.java | 4 +- .../{ => example}/GoogleReverseImageTest.java | 7 +- .../{ => example}/GoogleScholarTest.java | 4 +- .../serpapi/{ => example}/GoogleTest.java | 4 +- .../serpapi/{ => example}/HomeDepotTest.java | 4 +- .../java/serpapi/{ => example}/NaverTest.java | 4 +- .../serpapi/{ => example}/WalmartTest.java | 4 +- .../java/serpapi/{ => example}/YahooTest.java | 4 +- .../serpapi/{ => example}/YoutubeTest.java | 4 +- 35 files changed, 115 insertions(+), 265 deletions(-) delete mode 100644 src/test/java/basic_search_result.json create mode 100644 src/test/java/serpapi/SearchApiTest.java rename src/test/java/serpapi/{SerpApiTest.java => SearchArchiveApiTest.java} (60%) rename src/test/java/serpapi/{ => example}/AppleAppStoreTest.java (88%) rename src/test/java/serpapi/{ => example}/BaiduTest.java (88%) rename src/test/java/serpapi/{ => example}/BingTest.java (88%) rename src/test/java/serpapi/{ => example}/DuckduckgoTest.java (88%) rename src/test/java/serpapi/{ => example}/EbayTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleAutocompleteTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleEventsTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleImagesTest.java (89%) rename src/test/java/serpapi/{ => example}/GoogleJobsTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleLocalServicesTest.java (89%) rename src/test/java/serpapi/{ => example}/GoogleMapsTest.java (89%) rename src/test/java/serpapi/{ => example}/GooglePlayTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleProductTest.java (89%) rename src/test/java/serpapi/{ => example}/GoogleReverseImageTest.java (77%) rename src/test/java/serpapi/{ => example}/GoogleScholarTest.java (88%) rename src/test/java/serpapi/{ => example}/GoogleTest.java (88%) rename src/test/java/serpapi/{ => example}/HomeDepotTest.java (88%) rename src/test/java/serpapi/{ => example}/NaverTest.java (88%) rename src/test/java/serpapi/{ => example}/WalmartTest.java (88%) rename src/test/java/serpapi/{ => example}/YahooTest.java (88%) rename src/test/java/serpapi/{ => example}/YoutubeTest.java (88%) diff --git a/.github/workflows/gradle.yml b/.github/workflows/gradle.yml index 27c7871..95f5b44 100644 --- a/.github/workflows/gradle.yml +++ b/.github/workflows/gradle.yml @@ -15,14 +15,17 @@ jobs: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 - - name: Set up JDK 1.8 - uses: actions/setup-java@v1 + - uses: actions/checkout@v4 + - name: Set up JDK 21 + uses: actions/setup-java@v4 with: - java-version: 1.8 + java-version: '21' + distribution: 'temurin' - name: Grant execute permission for gradlew run: chmod +x gradlew + - name: Build with Gradle + uses: gradle/actions/setup-gradle@v3 - name: test run: ./gradlew test env: - API_KEY: ${{secrets.API_KEY}} \ No newline at end of file + SERPAPI_KEY: ${{secrets.SERPAPI_KEY}} \ No newline at end of file diff --git a/LICENSE b/LICENSE index 5d31a9d..fd42aa3 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2018-2024 SerpApi +Copyright (c) 2018-2025 SerpApi Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 4e46957..22a91cc 100644 --- a/README.md +++ b/README.md @@ -123,7 +123,7 @@ it prints the first 3 location matching Austin (Texas, Texas, Rochester) Let's run a search to get a search_id. ```java Map auth = new HashMap<>(); -auth.put("api_key", System.getenv("API_KEY")); +auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi serpapi = new SerpApi(auth); Map parameter = new HashMap<>(); diff --git a/README.md.erb b/README.md.erb index 2a33cfe..ffea8d7 100644 --- a/README.md.erb +++ b/README.md.erb @@ -135,7 +135,7 @@ it prints the first 3 location matching Austin (Texas, Texas, Rochester) Let's run a search to get a search_id. ```java Map auth = new HashMap<>(); -auth.put("api_key", System.getenv("API_KEY")); +auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi serpapi = new SerpApi(auth); Map parameter = new HashMap<>(); diff --git a/build.gradle b/build.gradle index ec29b8e..7ac1980 100644 --- a/build.gradle +++ b/build.gradle @@ -9,12 +9,12 @@ plugins { // Package default archivesBaseName = 'serpapi' -version = '1.0.0' +version = '1.1.0' group = 'com.github.serpapi' // java version -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +sourceCompatibility = 21 +targetCompatibility = 21 // Load repositories repositories { @@ -65,6 +65,6 @@ publishing { } wrapper { - gradleVersion = "7.3.3" + gradleVersion = "8.5" distributionType = Wrapper.DistributionType.ALL } diff --git a/demo/Makefile b/demo/Makefile index e4c2ab5..a98d3b8 100644 --- a/demo/Makefile +++ b/demo/Makefile @@ -1,9 +1,9 @@ .PHONY: build -ifndef API_KEY -$(error "API_KEY must be defined") +ifndef SERPAPI_KEY +$(error "SERPAPI_KEY must be defined") else -$(info "found API_KEY variable") +$(info "found SERPAPI_KEY variable") endif all: init clean build run diff --git a/demo/build.gradle b/demo/build.gradle index 321c5da..7f4da8e 100644 --- a/demo/build.gradle +++ b/demo/build.gradle @@ -14,6 +14,9 @@ plugins { id 'application' } +sourceCompatibility = 21 +targetCompatibility = 21 + repositories { mavenCentral() diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index 669386b..d0d403e 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-all.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.5-all.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/src/main/java/serpapi/SerpApi.java b/src/main/java/serpapi/SerpApi.java index 9b2f79c..3a0f425 100644 --- a/src/main/java/serpapi/SerpApi.java +++ b/src/main/java/serpapi/SerpApi.java @@ -11,7 +11,7 @@ /** * SerpApi wraps HTTP interaction with the service serpapi.com */ -public class SerpApi extends Exception { +public class SerpApi { /** * client parameters diff --git a/src/test/java/basic_search_result.json b/src/test/java/basic_search_result.json deleted file mode 100644 index d2dd85b..0000000 --- a/src/test/java/basic_search_result.json +++ /dev/null @@ -1,175 +0,0 @@ -{ - "search_metadata": { - "id": "5c91926661a1347a7a2ebe3a", - "status": "Success", - "created_at": "2019-03-20 01:07:50 UTC", - "processed_at": "2019-03-20 01:07:50 UTC", - "google_url": "https://www.google.com/search?q=Coffee&oq=Coffee&uule=w+CAIQICIaQXVzdGluLFRleGFzLFVuaXRlZCBTdGF0ZXM&hl=en&gl=us&num=10&safe=active&start=10&sourceid=chrome&ie=UTF-8", - "total_time_taken": 10.29 - }, - "search_parameters": { - "q": "Coffee", - "location_requested": "Austin, Texas, United States", - "location_used": "Austin,Texas,United States", - "google_domain": "google.com", - "hl": "en", - "gl": "us", - "safe": "active", - "start": "10", - "device": "desktop" - }, - "search_information": { - "total_results": 23620000000, - "time_taken_displayed": 0.6, - "query_displayed": "Coffee" - }, - "organic_results": [ - { - "position": 1, - "title": "What is Coffee? - National Coffee Association", - "link": "http://www.ncausa.org/about-coffee/what-is-coffee", - "displayed_link": "www.ncausa.org › About Coffee › What is Coffee?", - "snippet": "Coffee trees are pruned short to conserve their energy and aid in harvesting, but can grow to more than 30 feet (9 meters) high. Each tree is covered with green, ...", - "cached_page_link": "http://webcache.googleusercontent.com/search?q=cache:eukMDyc_TlwJ:www.ncausa.org/about-coffee/what-is-coffee+&cd=11&hl=en&ct=clnk&gl=us" - }, - { - "position": 2, - "title": "The History of Coffee - National Coffee Association", - "link": "http://www.ncausa.org/about-coffee/history-of-coffee", - "displayed_link": "www.ncausa.org › About Coffee › History of Coffee", - "snippet": "No one knows exactly how or when coffee was discovered, though there are many legends about its origin. ... Coffee grown worldwide can trace its heritage back centuries to the ancient coffee forests on the Ethiopian plateau. There, legend says the goat herder Kaldi first discovered the ...", - "cached_page_link": "http://webcache.googleusercontent.com/search?q=cache:lVL_jlE3B80J:www.ncausa.org/about-coffee/history-of-coffee+&cd=12&hl=en&ct=clnk&gl=us" - }, - { - "position": 3, - "title": "The Coffee House « Austin Improv Comedy Shows, Classes – The ...", - "link": "http://www.hideouttheatre.com/coffeehouse", - "displayed_link": "www.hideouttheatre.com/coffeehouse", - "snippet": "The Hideout is downtown Austin's oldest independent coffee house. We are open morning to night, weekdays and weekends and serve beer, wine, fresh ...", - "cached_page_link": "http://webcache.googleusercontent.com/search?q=cache:VD32HaeikQMJ:www.hideouttheatre.com/coffeehouse+&cd=13&hl=en&ct=clnk&gl=us", - "related_pages_link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=related:www.hideouttheatre.com/coffeehouse+Coffee&tbo=1&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChAfMAJ6BAgJEAU", - "rich_snippet": { - "bottom": { - "extensions": [ - "Thu, Mar 21", - "PGraph", - "Thu, Mar 21", - "Austin Secrets", - "Thu, Mar 21", - "The Free Fringe" - ] - } - } - }, - { - "position": 4, - "title": "Home | The Coffee Bean & Tea Leaf", - "link": "https://www.coffeebean.com/", - "displayed_link": "https://www.coffeebean.com/", - "snippet": "Never run out of your favorite coffees, teas and powders again with our auto-delivery subscription. Select how often your products arrive, pause and cancel ...", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:WpQxSYo2c6AJ:https://www.coffeebean.com/+&cd=14&hl=en&ct=clnk&gl=us", - "related_pages_link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=related:https://www.coffeebean.com/+Coffee&tbo=1&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChAfMAN6BAgFEAU" - }, - { - "position": 5, - "title": "Coffee Review - The World's Leading Coffee Guide", - "link": "https://www.coffeereview.com/", - "displayed_link": "https://www.coffeereview.com/", - "snippet": "Coffee reviews, espresso ratings, informative articles, and coffee blogs by Kenneth Davids and other coffee experts.", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:c9jncvPT1SsJ:https://www.coffeereview.com/+&cd=15&hl=en&ct=clnk&gl=us" - }, - { - "position": 6, - "title": "Coffee: Benefits, nutrition, and risks - Medical News Today", - "link": "https://www.medicalnewstoday.com/articles/270202.php", - "displayed_link": "https://www.medicalnewstoday.com/articles/270202.php", - "date": "Dec 14, 2017", - "snippet": "Drinking coffee may do much more than simply provide an energy boost when needed. Several scientific studies have identified a number of ...", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:FB_36c_qnUAJ:https://www.medicalnewstoday.com/articles/270202.php+&cd=16&hl=en&ct=clnk&gl=us" - }, - { - "position": 7, - "title": "Peet's Coffee: The Original Craft Coffee", - "link": "https://www.peets.com/", - "displayed_link": "https://www.peets.com/", - "snippet": "Since 1966, Peet's Coffee has offered superior coffees and teas by sourcing the best quality coffee beans and tea leaves in the world and adhering to strict ...", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:BCjzno6zP6wJ:https://www.peets.com/+&cd=17&hl=en&ct=clnk&gl=us", - "related_pages_link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=related:https://www.peets.com/+Coffee&tbo=1&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChAfMAZ6BAgGEAU" - }, - { - "position": 8, - "title": "The Best Coffee from Starbucks Coffee", - "link": "https://www.starbucks.com/coffee", - "displayed_link": "https://www.starbucks.com/coffee", - "snippet": "Next stop: Asia / Pacific. Journey through the world's coffee regions with our Passport Series—coffee selected to give you a sense of place. Now we're visiting ...", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:R7fHYjcarfsJ:https://www.starbucks.com/coffee+&cd=18&hl=en&ct=clnk&gl=us", - "related_pages_link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=related:https://www.starbucks.com/coffee+Coffee&tbo=1&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChAfMAd6BAgHEAU" - }, - { - "position": 9, - "title": "Seventh Flag Coffee - Austin", - "link": "http://www.seventhflagcoffee.com/", - "displayed_link": "www.seventhflagcoffee.com/", - "snippet": "Seventh Flag Coffee Co. is dedicated to creating the best overall coffee experience for every customer that walks through our doors. We are transforming the ...", - "cached_page_link": "http://webcache.googleusercontent.com/search?q=cache:VZCbBEneWWkJ:www.seventhflagcoffee.com/+&cd=19&hl=en&ct=clnk&gl=us", - "related_pages_link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=related:www.seventhflagcoffee.com/+Coffee&tbo=1&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChAfMAh6BAgIEAU" - }, - { - "position": 10, - "title": "Cosmic Coffee + Beer Garden - Austin, Tx", - "link": "https://www.cosmiccoffeebeer.com/", - "displayed_link": "https://www.cosmiccoffeebeer.com/", - "snippet": "specialty coffee, craft cocktails, locally brewed beer, food trailers and live music in a permaculture inspired garden setting in south austin, tx.", - "cached_page_link": "https://webcache.googleusercontent.com/search?q=cache:tsOR-R1-gmQJ:https://www.cosmiccoffeebeer.com/+&cd=20&hl=en&ct=clnk&gl=us" - } - ], - "related_searches": [ - { - "query": "mozarts coffee", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=mozarts+coffee&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigAegQIChAB" - }, - { - "query": "bennu coffee", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=bennu+coffee&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigBegQIChAC" - }, - { - "query": "coffee near me", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=coffee+near+me&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigCegQIChAD" - }, - { - "query": "coffee austin", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=coffee+austin&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigDegQIChAE" - }, - { - "query": "best coffee in austin", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=best+coffee+in+austin&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigEegQIChAF" - }, - { - "query": "coffee shops near me", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=coffee+shops+near+me&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigFegQIChAG" - }, - { - "query": "houndstooth coffee", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=houndstooth+coffee&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigGegQIChAH" - }, - { - "query": "epoch coffee", - "link": "https://www.google.com/search?safe=active&gl=us&hl=en&q=epoch+coffee&sa=X&ved=2ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDVAigHegQIChAI" - } - ], - "pagination": { - "current": 2, - "next": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=20&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDw0wMIjAE", - "other_pages": { - "1": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=0&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIeQ", - "3": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=20&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIfA", - "4": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=30&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIfg", - "5": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=40&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIgAE", - "6": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=50&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIggE", - "7": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=60&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIhAE", - "8": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=70&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIhgE", - "9": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=80&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIiAE", - "10": "https://www.google.com/search?q=Coffee&safe=active&gl=us&hl=en&ei=b5KRXOC6Bc3EswWc34_YDQ&start=90&sa=N&ved=0ahUKEwigrp6FxI_hAhVN4qwKHZzvA9s4ChDy0wMIigE" - } - } -} \ No newline at end of file diff --git a/src/test/java/serpapi/AccountApiTest.java b/src/test/java/serpapi/AccountApiTest.java index cb49d6d..8ca2778 100644 --- a/src/test/java/serpapi/AccountApiTest.java +++ b/src/test/java/serpapi/AccountApiTest.java @@ -16,12 +16,12 @@ public class AccountApiTest { @Test public void account() throws Exception { - if (System.getenv("API_KEY") == null) { + if (System.getenv("SERPAPI_KEY") == null) { return; } Map parameter = new HashMap(); - parameter.put("api_key", System.getenv("API_KEY")); + parameter.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(parameter); JsonObject info = client.account(); System.out.println(info.toString()); diff --git a/src/test/java/serpapi/LocationApiTest.java b/src/test/java/serpapi/LocationApiTest.java index 35ca1e9..1b0915d 100644 --- a/src/test/java/serpapi/LocationApiTest.java +++ b/src/test/java/serpapi/LocationApiTest.java @@ -17,13 +17,13 @@ public class LocationApiTest { @Test public void location() throws Exception { - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; SerpApi serpapi = new SerpApi(); Map parameter = new HashMap(); - parameter.put("q", "Austin"); + parameter.put("q", "Austin, TX"); parameter.put("limit", "3"); JsonArray location = serpapi.location(parameter); assertEquals("Austin, TX", location.get(0).getAsJsonObject().get("name").getAsString()); diff --git a/src/test/java/serpapi/SearchApiTest.java b/src/test/java/serpapi/SearchApiTest.java new file mode 100644 index 0000000..7109619 --- /dev/null +++ b/src/test/java/serpapi/SearchApiTest.java @@ -0,0 +1,41 @@ +package serpapi; + +import com.google.gson.JsonObject; +import com.google.gson.JsonPrimitive; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +import static org.junit.Assert.*; + +/** + * Test main class + */ +public class SearchApiTest { + + @Test + public void search() throws SerpApiException, InterruptedException { + // skip test if no api_key provided + if(System.getenv("SERPAPI_KEY") == null) + return; + + Map auth = new HashMap<>(); + auth.put("api_key", System.getenv("SERPAPI_KEY")); + SerpApi serpapi = new SerpApi(auth); + + Map parameter = new HashMap<>(); + parameter.put("q", "Coffee"); + parameter.put("location", "Austin, Texas, United States"); + parameter.put("hl", "en"); + parameter.put("gl", "us"); + parameter.put("google_domain", "google.com"); + parameter.put("safe", "active"); + parameter.put("start", "10"); + parameter.put("device", "desktop"); + + JsonObject results = serpapi.search(parameter); + assertTrue(results.getAsJsonArray("organic_results").size() > 5); + } + +} diff --git a/src/test/java/serpapi/SerpApiTest.java b/src/test/java/serpapi/SearchArchiveApiTest.java similarity index 60% rename from src/test/java/serpapi/SerpApiTest.java rename to src/test/java/serpapi/SearchArchiveApiTest.java index 4abc9bd..c1e5e99 100644 --- a/src/test/java/serpapi/SerpApiTest.java +++ b/src/test/java/serpapi/SearchArchiveApiTest.java @@ -12,40 +12,17 @@ /** * Test main class */ -public class SerpApiTest { +public class SearchArchiveApiTest { - @Test - public void search() throws SerpApiException, InterruptedException { - // skip test if no api_key provided - if(System.getenv("API_KEY") == null) - return; - - Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); - SerpApi serpapi = new SerpApi(auth); - - Map parameter = new HashMap<>(); - parameter.put("q", "Coffee"); - parameter.put("location", "Austin, Texas, United States"); - parameter.put("hl", "en"); - parameter.put("gl", "us"); - parameter.put("google_domain", "google.com"); - parameter.put("safe", "active"); - parameter.put("start", "10"); - parameter.put("device", "desktop"); - - JsonObject results = serpapi.search(parameter); - assertTrue(results.getAsJsonArray("organic_results").size() > 5); - } @Test public void searchArchive() throws SerpApiException, InterruptedException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; Map parameter = new HashMap<>(); - parameter.put("api_key", System.getenv("API_KEY")); + parameter.put("api_key", System.getenv("SERPAPI_KEY")); parameter.put("q", "Coffee"); parameter.put("location", "Austin, Texas, United States"); parameter.put("hl", "en"); diff --git a/src/test/java/serpapi/AppleAppStoreTest.java b/src/test/java/serpapi/example/AppleAppStoreTest.java similarity index 88% rename from src/test/java/serpapi/AppleAppStoreTest.java rename to src/test/java/serpapi/example/AppleAppStoreTest.java index a8d5708..a1af4f5 100644 --- a/src/test/java/serpapi/AppleAppStoreTest.java +++ b/src/test/java/serpapi/example/AppleAppStoreTest.java @@ -17,12 +17,12 @@ public class AppleAppStoreTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/BaiduTest.java b/src/test/java/serpapi/example/BaiduTest.java similarity index 88% rename from src/test/java/serpapi/BaiduTest.java rename to src/test/java/serpapi/example/BaiduTest.java index 8cbee14..cea68d7 100644 --- a/src/test/java/serpapi/BaiduTest.java +++ b/src/test/java/serpapi/example/BaiduTest.java @@ -17,12 +17,12 @@ public class BaiduTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/BingTest.java b/src/test/java/serpapi/example/BingTest.java similarity index 88% rename from src/test/java/serpapi/BingTest.java rename to src/test/java/serpapi/example/BingTest.java index defc69e..6adacf7 100644 --- a/src/test/java/serpapi/BingTest.java +++ b/src/test/java/serpapi/example/BingTest.java @@ -17,12 +17,12 @@ public class BingTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/DuckduckgoTest.java b/src/test/java/serpapi/example/DuckduckgoTest.java similarity index 88% rename from src/test/java/serpapi/DuckduckgoTest.java rename to src/test/java/serpapi/example/DuckduckgoTest.java index 22d9cee..5a5ba47 100644 --- a/src/test/java/serpapi/DuckduckgoTest.java +++ b/src/test/java/serpapi/example/DuckduckgoTest.java @@ -17,12 +17,12 @@ public class DuckduckgoTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/EbayTest.java b/src/test/java/serpapi/example/EbayTest.java similarity index 88% rename from src/test/java/serpapi/EbayTest.java rename to src/test/java/serpapi/example/EbayTest.java index facdf60..874f48e 100644 --- a/src/test/java/serpapi/EbayTest.java +++ b/src/test/java/serpapi/example/EbayTest.java @@ -17,12 +17,12 @@ public class EbayTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleAutocompleteTest.java b/src/test/java/serpapi/example/GoogleAutocompleteTest.java similarity index 88% rename from src/test/java/serpapi/GoogleAutocompleteTest.java rename to src/test/java/serpapi/example/GoogleAutocompleteTest.java index b2f9518..a279363 100644 --- a/src/test/java/serpapi/GoogleAutocompleteTest.java +++ b/src/test/java/serpapi/example/GoogleAutocompleteTest.java @@ -17,12 +17,12 @@ public class GoogleAutocompleteTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleEventsTest.java b/src/test/java/serpapi/example/GoogleEventsTest.java similarity index 88% rename from src/test/java/serpapi/GoogleEventsTest.java rename to src/test/java/serpapi/example/GoogleEventsTest.java index ffddcaf..df46c1a 100644 --- a/src/test/java/serpapi/GoogleEventsTest.java +++ b/src/test/java/serpapi/example/GoogleEventsTest.java @@ -17,12 +17,12 @@ public class GoogleEventsTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleImagesTest.java b/src/test/java/serpapi/example/GoogleImagesTest.java similarity index 89% rename from src/test/java/serpapi/GoogleImagesTest.java rename to src/test/java/serpapi/example/GoogleImagesTest.java index a2c9932..cf27d53 100644 --- a/src/test/java/serpapi/GoogleImagesTest.java +++ b/src/test/java/serpapi/example/GoogleImagesTest.java @@ -17,12 +17,12 @@ public class GoogleImagesTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleJobsTest.java b/src/test/java/serpapi/example/GoogleJobsTest.java similarity index 88% rename from src/test/java/serpapi/GoogleJobsTest.java rename to src/test/java/serpapi/example/GoogleJobsTest.java index 9bc5a85..eb274c2 100644 --- a/src/test/java/serpapi/GoogleJobsTest.java +++ b/src/test/java/serpapi/example/GoogleJobsTest.java @@ -17,12 +17,12 @@ public class GoogleJobsTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleLocalServicesTest.java b/src/test/java/serpapi/example/GoogleLocalServicesTest.java similarity index 89% rename from src/test/java/serpapi/GoogleLocalServicesTest.java rename to src/test/java/serpapi/example/GoogleLocalServicesTest.java index f0cc543..b3574d4 100644 --- a/src/test/java/serpapi/GoogleLocalServicesTest.java +++ b/src/test/java/serpapi/example/GoogleLocalServicesTest.java @@ -17,12 +17,12 @@ public class GoogleLocalServicesTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleMapsTest.java b/src/test/java/serpapi/example/GoogleMapsTest.java similarity index 89% rename from src/test/java/serpapi/GoogleMapsTest.java rename to src/test/java/serpapi/example/GoogleMapsTest.java index 0e6ac43..37ea934 100644 --- a/src/test/java/serpapi/GoogleMapsTest.java +++ b/src/test/java/serpapi/example/GoogleMapsTest.java @@ -17,12 +17,12 @@ public class GoogleMapsTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GooglePlayTest.java b/src/test/java/serpapi/example/GooglePlayTest.java similarity index 88% rename from src/test/java/serpapi/GooglePlayTest.java rename to src/test/java/serpapi/example/GooglePlayTest.java index 403eab5..b603697 100644 --- a/src/test/java/serpapi/GooglePlayTest.java +++ b/src/test/java/serpapi/example/GooglePlayTest.java @@ -17,12 +17,12 @@ public class GooglePlayTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleProductTest.java b/src/test/java/serpapi/example/GoogleProductTest.java similarity index 89% rename from src/test/java/serpapi/GoogleProductTest.java rename to src/test/java/serpapi/example/GoogleProductTest.java index 1ced6d2..65d089f 100644 --- a/src/test/java/serpapi/GoogleProductTest.java +++ b/src/test/java/serpapi/example/GoogleProductTest.java @@ -19,12 +19,12 @@ public class GoogleProductTest { // @Test // public void search() throws SerpApiException { // // skip test if no api_key provided - // if(System.getenv("API_KEY") == null) + // if(System.getenv("SERPAPI_KEY") == null) // return; // // setup serpapi client // Map auth = new HashMap<>(); - // auth.put("api_key", System.getenv("API_KEY")); + // auth.put("api_key", System.getenv("SERPAPI_KEY")); // SerpApi client = new SerpApi(auth); // // run search diff --git a/src/test/java/serpapi/GoogleReverseImageTest.java b/src/test/java/serpapi/example/GoogleReverseImageTest.java similarity index 77% rename from src/test/java/serpapi/GoogleReverseImageTest.java rename to src/test/java/serpapi/example/GoogleReverseImageTest.java index de2abf4..e2f6298 100644 --- a/src/test/java/serpapi/GoogleReverseImageTest.java +++ b/src/test/java/serpapi/example/GoogleReverseImageTest.java @@ -17,12 +17,12 @@ public class GoogleReverseImageTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search @@ -30,7 +30,8 @@ public void search() throws SerpApiException { parameter.put("engine", "google_reverse_image"); parameter.put("image_url", "https://i.imgur.com/5bGzZi7.jpg"); JsonObject results = client.search(parameter); - assertTrue(results.getAsJsonArray("image_sizes").size() > 1); + assertTrue(results.has("image_results")); + assertTrue(results.getAsJsonArray("image_results").size() > 0); } } \ No newline at end of file diff --git a/src/test/java/serpapi/GoogleScholarTest.java b/src/test/java/serpapi/example/GoogleScholarTest.java similarity index 88% rename from src/test/java/serpapi/GoogleScholarTest.java rename to src/test/java/serpapi/example/GoogleScholarTest.java index 8ec41a4..7724439 100644 --- a/src/test/java/serpapi/GoogleScholarTest.java +++ b/src/test/java/serpapi/example/GoogleScholarTest.java @@ -17,12 +17,12 @@ public class GoogleScholarTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/GoogleTest.java b/src/test/java/serpapi/example/GoogleTest.java similarity index 88% rename from src/test/java/serpapi/GoogleTest.java rename to src/test/java/serpapi/example/GoogleTest.java index 0b5acd4..086cdd4 100644 --- a/src/test/java/serpapi/GoogleTest.java +++ b/src/test/java/serpapi/example/GoogleTest.java @@ -17,12 +17,12 @@ public class GoogleTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/HomeDepotTest.java b/src/test/java/serpapi/example/HomeDepotTest.java similarity index 88% rename from src/test/java/serpapi/HomeDepotTest.java rename to src/test/java/serpapi/example/HomeDepotTest.java index 3a4a345..94f4415 100644 --- a/src/test/java/serpapi/HomeDepotTest.java +++ b/src/test/java/serpapi/example/HomeDepotTest.java @@ -17,12 +17,12 @@ public class HomeDepotTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/NaverTest.java b/src/test/java/serpapi/example/NaverTest.java similarity index 88% rename from src/test/java/serpapi/NaverTest.java rename to src/test/java/serpapi/example/NaverTest.java index 98b433e..c83a346 100644 --- a/src/test/java/serpapi/NaverTest.java +++ b/src/test/java/serpapi/example/NaverTest.java @@ -17,12 +17,12 @@ public class NaverTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/WalmartTest.java b/src/test/java/serpapi/example/WalmartTest.java similarity index 88% rename from src/test/java/serpapi/WalmartTest.java rename to src/test/java/serpapi/example/WalmartTest.java index a7d440b..d1b19a9 100644 --- a/src/test/java/serpapi/WalmartTest.java +++ b/src/test/java/serpapi/example/WalmartTest.java @@ -17,12 +17,12 @@ public class WalmartTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/YahooTest.java b/src/test/java/serpapi/example/YahooTest.java similarity index 88% rename from src/test/java/serpapi/YahooTest.java rename to src/test/java/serpapi/example/YahooTest.java index be147f8..4452465 100644 --- a/src/test/java/serpapi/YahooTest.java +++ b/src/test/java/serpapi/example/YahooTest.java @@ -17,12 +17,12 @@ public class YahooTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search diff --git a/src/test/java/serpapi/YoutubeTest.java b/src/test/java/serpapi/example/YoutubeTest.java similarity index 88% rename from src/test/java/serpapi/YoutubeTest.java rename to src/test/java/serpapi/example/YoutubeTest.java index 1d2ce26..4e71a65 100644 --- a/src/test/java/serpapi/YoutubeTest.java +++ b/src/test/java/serpapi/example/YoutubeTest.java @@ -17,12 +17,12 @@ public class YoutubeTest { @Test public void search() throws SerpApiException { // skip test if no api_key provided - if(System.getenv("API_KEY") == null) + if(System.getenv("SERPAPI_KEY") == null) return; // setup serpapi client Map auth = new HashMap<>(); - auth.put("api_key", System.getenv("API_KEY")); + auth.put("api_key", System.getenv("SERPAPI_KEY")); SerpApi client = new SerpApi(auth); // run search From c610e5056e069ba0b09c4b4954acc23491d74a39 Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 3 Jan 2026 21:54:26 -0600 Subject: [PATCH 2/5] Add JaCoCo coverage support and make coverage target --- Makefile | 5 +++++ build.gradle | 6 ++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/Makefile b/Makefile index 12175ea..8ad9028 100644 --- a/Makefile +++ b/Makefile @@ -15,6 +15,11 @@ init: test: ./gradlew test --info +# Run test coverage +coverage: + ./gradlew test jacocoTestReport + @echo "Coverage report: build/reports/jacoco/test/html/index.html" + build: clean ./gradlew build publishToMavenLocal -x test @echo "see build/lib" diff --git a/build.gradle b/build.gradle index 7ac1980..c07171f 100644 --- a/build.gradle +++ b/build.gradle @@ -1,10 +1,8 @@ // Java library plugins { id 'java-library' -} - -plugins { - id 'maven-publish' + id 'maven-publish' + id 'jacoco' } // Package default From 3a01d58b32542ee86c3857ae4e0152a7813f5b9f Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 3 Jan 2026 22:26:10 -0600 Subject: [PATCH 3/5] test fail when SERPAPI_KEY is null --- src/test/java/serpapi/AccountApiTest.java | 5 ++++- src/test/java/serpapi/LocationApiTest.java | 8 ++++++-- src/test/java/serpapi/SearchApiTest.java | 7 ++++--- src/test/java/serpapi/SearchArchiveApiTest.java | 8 ++++---- 4 files changed, 18 insertions(+), 10 deletions(-) diff --git a/src/test/java/serpapi/AccountApiTest.java b/src/test/java/serpapi/AccountApiTest.java index 8ca2778..364229d 100644 --- a/src/test/java/serpapi/AccountApiTest.java +++ b/src/test/java/serpapi/AccountApiTest.java @@ -12,12 +12,15 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +/*** + * Test SerpApi.account() method. + */ public class AccountApiTest { @Test public void account() throws Exception { if (System.getenv("SERPAPI_KEY") == null) { - return; + fail("SERPAPI_KEY is not set"); } Map parameter = new HashMap(); diff --git a/src/test/java/serpapi/LocationApiTest.java b/src/test/java/serpapi/LocationApiTest.java index 1b0915d..76fe0c3 100644 --- a/src/test/java/serpapi/LocationApiTest.java +++ b/src/test/java/serpapi/LocationApiTest.java @@ -13,12 +13,16 @@ import static org.junit.Assert.*; import static org.mockito.Mockito.*; +/** + * Test SerpApi.location() method. + */ public class LocationApiTest { @Test public void location() throws Exception { - if(System.getenv("SERPAPI_KEY") == null) - return; + if(System.getenv("SERPAPI_KEY") == null) { + fail("SERPAPI_KEY is not set"); + } SerpApi serpapi = new SerpApi(); diff --git a/src/test/java/serpapi/SearchApiTest.java b/src/test/java/serpapi/SearchApiTest.java index 7109619..8f54924 100644 --- a/src/test/java/serpapi/SearchApiTest.java +++ b/src/test/java/serpapi/SearchApiTest.java @@ -10,15 +10,16 @@ import static org.junit.Assert.*; /** - * Test main class + * Test SerpApi.search() method. */ public class SearchApiTest { @Test public void search() throws SerpApiException, InterruptedException { // skip test if no api_key provided - if(System.getenv("SERPAPI_KEY") == null) - return; + if(System.getenv("SERPAPI_KEY") == null) { + fail("SERPAPI_KEY is not set"); + } Map auth = new HashMap<>(); auth.put("api_key", System.getenv("SERPAPI_KEY")); diff --git a/src/test/java/serpapi/SearchArchiveApiTest.java b/src/test/java/serpapi/SearchArchiveApiTest.java index c1e5e99..b8dcf6e 100644 --- a/src/test/java/serpapi/SearchArchiveApiTest.java +++ b/src/test/java/serpapi/SearchArchiveApiTest.java @@ -10,16 +10,16 @@ import static org.junit.Assert.*; /** - * Test main class + * Test SerpApi.searchArchive() method. */ public class SearchArchiveApiTest { - @Test public void searchArchive() throws SerpApiException, InterruptedException { // skip test if no api_key provided - if(System.getenv("SERPAPI_KEY") == null) - return; + if(System.getenv("SERPAPI_KEY") == null) { + fail("SERPAPI_KEY is not set"); + } Map parameter = new HashMap<>(); parameter.put("api_key", System.getenv("SERPAPI_KEY")); From 4788a7be966fa2ad1d1d96c38df6c2b18aa055cb Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 3 Jan 2026 22:38:24 -0600 Subject: [PATCH 4/5] Fix Javadoc warnings in SerpApi, SerpApiHttp, and ParameterStringBuilder --- src/main/java/serpapi/ParameterStringBuilder.java | 6 ++++++ src/main/java/serpapi/SerpApi.java | 2 ++ src/main/java/serpapi/SerpApiHttp.java | 8 ++++++++ 3 files changed, 16 insertions(+) diff --git a/src/main/java/serpapi/ParameterStringBuilder.java b/src/main/java/serpapi/ParameterStringBuilder.java index 231563b..905fb07 100644 --- a/src/main/java/serpapi/ParameterStringBuilder.java +++ b/src/main/java/serpapi/ParameterStringBuilder.java @@ -10,6 +10,12 @@ */ public class ParameterStringBuilder { + /** + * Default constructor + */ + public ParameterStringBuilder() { + } + /*** * getParamsString * @param params search parameters diff --git a/src/main/java/serpapi/SerpApi.java b/src/main/java/serpapi/SerpApi.java index 3a0f425..7a53369 100644 --- a/src/main/java/serpapi/SerpApi.java +++ b/src/main/java/serpapi/SerpApi.java @@ -131,6 +131,8 @@ private JsonObject json(String endpoint, Map parameter) throws S } /*** + * Get the HTTP client used for requests + * * @return http client */ public SerpApiHttp getClient() { diff --git a/src/main/java/serpapi/SerpApiHttp.java b/src/main/java/serpapi/SerpApiHttp.java index 622fd3d..b97605c 100644 --- a/src/main/java/serpapi/SerpApiHttp.java +++ b/src/main/java/serpapi/SerpApiHttp.java @@ -189,6 +189,8 @@ protected void triggerSerpApiException(String content) throws SerpApiException { } /** + * Get the HTTP connection timeout + * * @return current HTTP connection timeout */ public int getHttpConnectionTimeout() { @@ -196,6 +198,8 @@ public int getHttpConnectionTimeout() { } /** + * Set the HTTP connection timeout + * * @param httpConnectionTimeout set HTTP connection timeout */ public void setHttpConnectionTimeout(int httpConnectionTimeout) { @@ -203,6 +207,8 @@ public void setHttpConnectionTimeout(int httpConnectionTimeout) { } /** + * Get the HTTP read timeout + * * @return current HTTP read timeout */ public int getHttpReadTimeout() { @@ -210,6 +216,8 @@ public int getHttpReadTimeout() { } /** + * Set the HTTP read timeout + * * @param httpReadTimeout set HTTP read timeout */ public void setHttpReadTimeout(int httpReadTimeout) { From 334e07c1815bcb8fb8288d7b0e6e98f3f5461859 Mon Sep 17 00:00:00 2001 From: Victor Benarbia Date: Sat, 3 Jan 2026 22:39:23 -0600 Subject: [PATCH 5/5] Enhance Makefile with additional build targets and update Javadoc command to use Gradle wrapper --- Makefile | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 8ad9028..50db6ae 100644 --- a/Makefile +++ b/Makefile @@ -20,10 +20,12 @@ coverage: ./gradlew test jacocoTestReport @echo "Coverage report: build/reports/jacoco/test/html/index.html" +# Build the project build: clean ./gradlew build publishToMavenLocal -x test @echo "see build/lib" +# Build the demo project oobt: build $(MAKE) -C demo all @@ -31,8 +33,9 @@ oobt: build readme: erb -T '-' README.md.erb > README.md +# Build the javadoc doc: - gradle javadoc --info --warning-mode all + ./gradlew javadoc --info --warning-mode all # Create a release using GitHub release: doc build