Skip to content

Commit

Permalink
Merge pull request #8 from reeyur/bugfix/adjust-README-and-Response
Browse files Browse the repository at this point in the history
Update the README and adjust the return type of getData in the Response.
  • Loading branch information
yury-awesome authored Sep 23, 2019
2 parents faca723 + 25ff509 commit b816e8c
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ public class DemoCase {
```xml
<suite name="TestNGSample">
<listeners>
<listener class-name="com.meituan.lyrebird.client.events.TestNGListener" />
<listener class-name="com.meituan.lyrebird.client.listeners.TestNGListener" />
</listeners>
<test name="Test Demo">
<classes>
Expand All @@ -149,7 +149,7 @@ public class DemoCase {
- 方法二:源码中直接添加

```java
import com.meituan.lyrebird.client.events.TestNGListener;
import com.meituan.lyrebird.client.listeners.TestNGListener;
import com.meituan.lyrebird.client.MockData;
...

Expand Down
16 changes: 9 additions & 7 deletions src/main/java/com/meituan/lyrebird/client/api/Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,23 @@ public void setHeaders(Map<String, String> headers) {
/**
* 传入 jsonPath 查询服务端返回数据中的对应内容
*
* @param jsonPath refer: https://github.com/json-path/JsonPath/edit/master/README.md
* @return 根据 jsonPath 查询得到的返回数据
* @param <T>
* @param jsonPath refer: https://github.com/json-path/JsonPath/edit/master/README.md
* @return 根据 jsonPath 查询得到的返回数据
*/
public Object getData(String jsonPath) {
public <T> T getData(String jsonPath) {
return JsonPath.parse(data).read(jsonPath);
}

/**
* 传入 jsonPath, type 限制查询服务端返回数据的内容类型
*
* @param jsonPath refer: https://github.com/json-path/JsonPath/edit/master/README.md
* @param type 限制返回数据的类型 如:Integer.class 即限制返回的数据内容要求是整型
* @return 根据 jsonPath 和 type类型限制 查询得到的返回数据
* @param <T>
* @param jsonPath refer: https://github.com/json-path/JsonPath/edit/master/README.md
* @param type expected return type (will try to map)
* @return 根据 jsonPath 查询得到的返回数据
*/
public Object getData(String jsonPath, Class<?> type) {
public <T> T getData(String jsonPath, Class<T> type) {
return JsonPath.parse(data).read(jsonPath, type);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ public void testFlowResponse() throws LyrebirdClientException {

assertEquals(200, flow.getResponse().getCode());
assertEquals("tester", flow.getResponse().getHeaders().get("name"));
assertEquals(18, flow.getResponse().getData("$.age"));
assertEquals(Integer.valueOf(18), flow.getResponse().getData("$.age"));
assertEquals("15.58", flow.getResponse().getData("$.price", String.class));
}

Expand Down

0 comments on commit b816e8c

Please sign in to comment.