list(Integer id) throws WxErrorException;
/**
*
diff --git a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
index 82cd8c345..d836517fa 100644
--- a/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
+++ b/weixin-java-cp/src/main/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImpl.java
@@ -48,13 +48,13 @@ public class WxCpDepartmentServiceImpl implements WxCpDepartmentService {
}
@Override
- public List listAll() throws WxErrorException {
+ public List list(Integer id) throws WxErrorException {
String url = "https://qyapi.weixin.qq.com/cgi-bin/department/list";
+ if (id != null) {
+ url += "?id=" + id;
+ }
+
String responseContent = this.mainService.get(url, null);
- /*
- * 操蛋的微信API,创建时返回的是 { group : { id : ..., name : ...} }
- * 查询时返回的是 { groups : [ { id : ..., name : ..., count : ... }, ... ] }
- */
JsonElement tmpJsonElement = new JsonParser().parse(responseContent);
return WxCpGsonBuilder.INSTANCE.create()
.fromJson(tmpJsonElement.getAsJsonObject().get("department"),
diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
index 5e2502082..522d169cf 100644
--- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
+++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/api/impl/WxCpDepartmentServiceImplTest.java
@@ -8,6 +8,7 @@ import org.testng.annotations.*;
import java.util.List;
+import static org.assertj.core.api.Assertions.assertThat;
import static org.testng.Assert.*;
/**
@@ -34,16 +35,24 @@ public class WxCpDepartmentServiceImplTest {
System.out.println(departId);
}
- @Test
- public void testListAll() throws Exception {
+ @DataProvider
+ public Object[][] departIds(){
+ return new Object[][]{
+ {null},
+ {1},
+ {5}
+ };
+ }
+
+ @Test(dataProvider = "departIds")
+ public void testList(Integer id) throws Exception {
System.out.println("=================获取部门");
- List departList = this.wxCpService.getDepartmentService().listAll();
- assertNotNull(departList);
- assertTrue(departList.size() > 0);
+ List departList = this.wxCpService.getDepartmentService().list(id);
+ assertThat(departList).isNotEmpty();
for (WxCpDepart g : departList) {
this.depart = g;
System.out.println(this.depart.getId() + ":" + this.depart.getName());
- assertNotNull(g.getName());
+ assertThat(g.getName()).isNotBlank();
}
}