test: genService 单元测试方法
parent
aced04e349
commit
e6dcd42158
|
|
@ -325,7 +325,7 @@ public class OpenAccAllCompanyRequest implements ApiRequest {
|
|||
* 开户资料信息
|
||||
*/
|
||||
@SerializedName("file_list")
|
||||
private List<OpenAccAllPersonRequest.FileList> fileList;
|
||||
private List<FileList> fileList;
|
||||
|
||||
/**
|
||||
* 开户经度
|
||||
|
|
|
|||
|
|
@ -325,7 +325,7 @@ public class OpenAccCompanyRequest implements ApiRequest {
|
|||
* 开户资料信息
|
||||
*/
|
||||
@SerializedName("file_list")
|
||||
private List<OpenAccAllPersonRequest.FileList> fileList;
|
||||
private List<FileList> fileList;
|
||||
|
||||
/**
|
||||
* 开户经度
|
||||
|
|
|
|||
|
|
@ -160,7 +160,7 @@ public class OpenAccPersonRequest implements ApiRequest {
|
|||
* 开户资料信息
|
||||
*/
|
||||
@SerializedName("file_list")
|
||||
private List<OpenAccAllPersonRequest.FileList> fileList;
|
||||
private List<FileList> fileList;
|
||||
|
||||
/**
|
||||
* 开户经度
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load Diff
|
|
@ -8,7 +8,9 @@ import java.lang.reflect.Method;
|
|||
import java.lang.reflect.ParameterizedType;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
@UtilityClass
|
||||
public class RefGenTestMethod {
|
||||
|
|
@ -41,7 +43,7 @@ public class RefGenTestMethod {
|
|||
private static void genRequestParams(Class<?> request) {
|
||||
print("void extracted%sParams(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
||||
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
Set<Class<?>> list = new HashSet<>();
|
||||
Method[] methods = request.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
|
|
@ -55,7 +57,7 @@ public class RefGenTestMethod {
|
|||
|
||||
String sun = actualType.getSimpleName();
|
||||
print("\t%s.%s %s = new %s.%s();\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), request.getSimpleName(), actualType.getSimpleName());
|
||||
print("\textracted%sNestParams(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\textracted%s%sNestParams(%s);\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\trequest.%s(Lists.list(%s));\n", method.getName(), sun.toLowerCase());
|
||||
} else {
|
||||
printParams(FMT_REQUEST_METHOD, method);
|
||||
|
|
@ -65,7 +67,7 @@ public class RefGenTestMethod {
|
|||
print("}\n");
|
||||
|
||||
for (Class<?> clazz : list) {
|
||||
genNest(clazz);
|
||||
genNest(request, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -73,7 +75,7 @@ public class RefGenTestMethod {
|
|||
private static void genRequestAssertions(Class<?> request) {
|
||||
print("void extracted%sAssertions(%s request) {\n", request.getSimpleName(), request.getSimpleName());
|
||||
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
Set<Class<?>> list = new HashSet<>();
|
||||
Method[] methods = request.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
|
|
@ -87,24 +89,20 @@ public class RefGenTestMethod {
|
|||
|
||||
String sun = actualType.getSimpleName();
|
||||
print("\tfor (%s.%s %s : request.%s()) {\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), method.getName().replace("set", "get"));
|
||||
print("\t\textracted%sNestNestAssertions(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\t\textracted%s%sNestAssertions(%s);\n", request.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\t}\n", method.getName(), sun.toLowerCase());
|
||||
} else {
|
||||
printAssertions(FMT_REQUEST_ASSERTIONS, method, true);
|
||||
}
|
||||
}
|
||||
print("}\n");
|
||||
|
||||
for (Class<?> clazz : list) {
|
||||
genNest(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
private static void genResponseParams(Class<?> response) {
|
||||
print("void extracted%sParams(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
||||
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
Set<Class<?>> list = new HashSet<>();
|
||||
Method[] methods = response.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
|
|
@ -117,8 +115,8 @@ public class RefGenTestMethod {
|
|||
|
||||
String sun = actualType.getSimpleName();
|
||||
print("\t%s.%s %s = new %s.%s();\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), response.getSimpleName(), actualType.getSimpleName());
|
||||
print("\textracted%sNestParams(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\tresponse.set%s(Lists.list(%s));\n", method.getName(), sun.toLowerCase());
|
||||
print("\textracted%s%sNestParams(%s);\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\tresponse.%s(Lists.list(%s));\n", method.getName(), sun.toLowerCase());
|
||||
} else {
|
||||
printParams(FMT_RESPONSE_METHOD, method);
|
||||
}
|
||||
|
|
@ -126,7 +124,7 @@ public class RefGenTestMethod {
|
|||
print("}\n");
|
||||
|
||||
for (Class<?> clazz : list) {
|
||||
genNest(clazz);
|
||||
genNest(response, clazz);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -134,7 +132,7 @@ public class RefGenTestMethod {
|
|||
private static void genResponseAssertions(Class<?> response) {
|
||||
print("void extracted%sAssertions(%s response) {\n", response.getSimpleName(), response.getSimpleName());
|
||||
|
||||
List<Class<?>> list = new ArrayList<>();
|
||||
Set<Class<?>> list = new HashSet<>();
|
||||
Method[] methods = response.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
|
|
@ -147,17 +145,13 @@ public class RefGenTestMethod {
|
|||
|
||||
String sun = actualType.getSimpleName();
|
||||
print("\tfor (%s.%s %s : response.%s()) {\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase(), method.getName().replace("set", "get"));
|
||||
print("\t\textracted%sNestNestAssertions(%s);\n", actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\t\textracted%s%sNestAssertions(%s);\n", response.getSimpleName(), actualType.getSimpleName(), sun.toLowerCase());
|
||||
print("\t}\n", method.getName(), sun.toLowerCase());
|
||||
} else {
|
||||
printAssertions(FMT_RESPONSE_ASSERTIONS, method, false);
|
||||
}
|
||||
}
|
||||
print("}\n");
|
||||
|
||||
for (Class<?> clazz : list) {
|
||||
genNest(clazz);
|
||||
}
|
||||
}
|
||||
|
||||
public static void gen(Class<?> request, Class<?> response, String methodName, String url) {
|
||||
|
|
@ -191,10 +185,10 @@ public class RefGenTestMethod {
|
|||
genResponseAssertions(response);
|
||||
}
|
||||
|
||||
public static void genNest(Class<?> request) {
|
||||
print("void extracted%sNestParams(%s nest) {\n", request.getSimpleName(), request.getSimpleName());
|
||||
public static void genNest(Class<?> clazz, Class<?> clazzNest) {
|
||||
print("void extracted%s%sNestParams(%s.%s nest) {\n", clazz.getSimpleName(), clazzNest.getSimpleName(), clazz.getSimpleName(), clazzNest.getSimpleName());
|
||||
|
||||
Method[] methods = request.getMethods();
|
||||
Method[] methods = clazzNest.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
continue;
|
||||
|
|
@ -205,7 +199,7 @@ public class RefGenTestMethod {
|
|||
|
||||
print("}\n");
|
||||
|
||||
print("void extracted%sNestAssertions(%s nest) {\n", request.getSimpleName(), request.getSimpleName());
|
||||
print("void extracted%s%sNestAssertions(%s.%s nest) {\n", clazz.getSimpleName(), clazzNest.getSimpleName(), clazz.getSimpleName(), clazzNest.getSimpleName());
|
||||
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
|
|
@ -274,12 +268,12 @@ public class RefGenTestMethod {
|
|||
"import java.math.BigDecimal;\n\n");
|
||||
|
||||
print("@ExtendWith(MockitoExtension.class)\n");
|
||||
print("void %sTest {\n", clazz.getSimpleName());
|
||||
print("class %sTest {\n", clazz.getSimpleName());
|
||||
print("@InjectMocks\n");
|
||||
print("private %s service\n\n", clazz.getSimpleName());
|
||||
print("private %s service;\n\n", clazz.getSimpleName());
|
||||
|
||||
print("@Mocks\n");
|
||||
print("private ApiClient apiClient\n\n");
|
||||
print("@Mock\n");
|
||||
print("private ApiClient apiClient;\n\n");
|
||||
|
||||
Method[] methods = clazz.getMethods();
|
||||
for (Method method : methods) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,8 @@
|
|||
package com.czcb.scfs.api.test;
|
||||
|
||||
import com.czcb.scfs.api.service.v2.account.AccountService;
|
||||
import com.czcb.scfs.api.service.v2.account.model.*;
|
||||
import com.czcb.scfs.api.service.v1.account.AccountService;
|
||||
import com.czcb.scfs.api.service.v2.account.model.PersonOpenAccountThreeElementRequest;
|
||||
import com.czcb.scfs.api.service.v2.account.model.PersonOpenAccountThreeElementResponse;
|
||||
import com.czcb.scfs.api.service.v2.bills.model.*;
|
||||
import com.czcb.scfs.api.service.v2.bmd.model.*;
|
||||
import com.czcb.scfs.api.service.v2.communal.model.FiveCascadeQueryRequest;
|
||||
|
|
@ -217,9 +218,9 @@ class RefGenTestMethodTest {
|
|||
// RefGenTestMethod.gen(ProjectQueryRequest.class, ProjectQueryResponse.class,
|
||||
// "projectQuery", "/purchase/project-query");
|
||||
|
||||
RefGenTestMethod.genNest(ProjectQueryResponse.CreditInfoList.class);
|
||||
RefGenTestMethod.genNest(ProjectQueryResponse.ProjectInfoList.class);
|
||||
RefGenTestMethod.genNest(ProjectQueryResponse.CreditRepayList.class);
|
||||
// RefGenTestMethod.genNest(ProjectQueryResponse.CreditInfoList.class);
|
||||
// RefGenTestMethod.genNest(ProjectQueryResponse.ProjectInfoList.class);
|
||||
// RefGenTestMethod.genNest(ProjectQueryResponse.CreditRepayList.class);
|
||||
|
||||
// RefGenTestMethod.gen(ProjectPayRequest.class, ProjectPayResponse.class,
|
||||
// "projectPay", "/purchase/project-pay");
|
||||
|
|
|
|||
Loading…
Reference in New Issue