-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathBaiduTest.java
More file actions
36 lines (28 loc) · 851 Bytes
/
BaiduTest.java
File metadata and controls
36 lines (28 loc) · 851 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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 BaiduTest {
@Test
public void search() throws SerpApiException {
// skip test if no api_key provided
if(System.getenv("SERPAPI_KEY") == null)
return;
// setup serpapi client
Map<String, String> auth = new HashMap<>();
auth.put("api_key", System.getenv("SERPAPI_KEY"));
SerpApi client = new SerpApi(auth);
// run search
Map<String, String> parameter = new HashMap<>();
parameter.put("engine", "baidu");
parameter.put("q", "coffee");
JsonObject results = client.search(parameter);
assertTrue(results.getAsJsonArray("organic_results").size() > 5);
}
}