FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
serpapi-java/src/test/java/serpapi/MarkdownApiTest.java at master · serpapi/serpapi-java · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
serpapi
/
serpapi-java
Public
Notifications
You must be signed in to change notification settings
Fork
2
Star
8
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
serpapi-java
/
src
/
test
/
java
/
serpapi
/
MarkdownApiTest.java
Copy path
More file actions
More file actions
Latest commit
History
History
History
67 lines (54 loc) · 1.84 KB
Breadcrumbs
serpapi-java
/
src
/
test
/
java
/
serpapi
/
MarkdownApiTest.java
Copy path
File metadata and controls
67 lines (54 loc) · 1.84 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
package
serpapi
;
import
org
.
junit
.
Test
;
import
java
.
util
.
HashMap
;
import
java
.
util
.
Map
;
import
static
org
.
junit
.
Assert
.*;
/**
* Test SerpApi.markdown() method.
*
* Offline: the HTTP client is stubbed, so no network call and no SERPAPI_KEY
* are needed. What matters here is the request this client builds, which can
* be asserted without a live backend.
*/
public
class
MarkdownApiTest
{
/**
* Stubbed HTTP client that records the query it was asked to send.
*/
private
static
class
RecordingHttp
extends
SerpApiHttp
{
Map
<
String
,
String
>
recorded
;
RecordingHttp
() {
super
(
"/search"
);
}
@
Override
public
String
get
(
Map
<
String
,
String
>
parameter
) {
this
.
recorded
=
parameter
;
return
"## Search results
\n
\n
1. [Coffee](https://example.com)
\n
"
;
}
}
@
Test
public
void
markdownRequestsMdOutput
()
throws
SerpApiException
{
SerpApi
serpapi
=
new
SerpApi
(
new
HashMap
<>());
RecordingHttp
http
=
new
RecordingHttp
();
serpapi
.
client
=
http
;
Map
<
String
,
String
>
parameter
=
new
HashMap
<>();
parameter
.
put
(
"q"
,
"coffee"
);
String
content
=
serpapi
.
markdown
(
parameter
);
assertEquals
(
"md"
,
http
.
recorded
.
get
(
"output"
));
assertEquals
(
"coffee"
,
http
.
recorded
.
get
(
"q"
));
assertEquals
(
"/search"
,
http
.
path
);
assertTrue
(
content
.
startsWith
(
"## Search results"
));
}
@
Test
public
void
markdownMergesDefaultParameter
()
throws
SerpApiException
{
Map
<
String
,
String
>
auth
=
new
HashMap
<>();
auth
.
put
(
"api_key"
,
"secret"
);
auth
.
put
(
"engine"
,
"google"
);
SerpApi
serpapi
=
new
SerpApi
(
auth
);
RecordingHttp
http
=
new
RecordingHttp
();
serpapi
.
client
=
http
;
serpapi
.
markdown
(
new
HashMap
<>());
assertEquals
(
"secret"
,
http
.
recorded
.
get
(
"api_key"
));
assertEquals
(
"google"
,
http
.
recorded
.
get
(
"engine"
));
assertEquals
(
"md"
,
http
.
recorded
.
get
(
"output"
));
}
}
Back
|
FazBrowse Home
|
New Git URL