refactor: 单元测试方法生成类
parent
4df38f04b2
commit
022d7c6bf0
|
|
@ -325,7 +325,7 @@ public class OpenAccountCompanyRequest implements ApiRequest {
|
|||
* 开户资料信息
|
||||
*/
|
||||
@SerializedName("file_list")
|
||||
private List<OpenAccAllPersonRequest.FileList> fileList;
|
||||
private List<FileList> fileList;
|
||||
|
||||
/**
|
||||
* 开户经度
|
||||
|
|
|
|||
|
|
@ -0,0 +1,103 @@
|
|||
package com.czcb.scfs.api.service.v1.account;
|
||||
|
||||
import com.czcb.scfs.api.service.v1.account.model.OpenAccSubRequest;
|
||||
import com.czcb.scfs.api.service.v1.account.model.OpenAccSubResponse;
|
||||
import org.junit.jupiter.api.Assertions;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class AccountServiceTest {
|
||||
|
||||
@Test
|
||||
void openAccSub() {
|
||||
OpenAccSubRequest request = new OpenAccSubRequest();
|
||||
request.setChannelNo("setChannelNo");
|
||||
request.setAppNo("setAppNo");
|
||||
request.setSerialNo("setSerialNo");
|
||||
request.setAccountNo("setAccountNo");
|
||||
request.setAccountName("setAccountName");
|
||||
request.setAccountClass("setAccountClass");
|
||||
request.setTransDate("setTransDate");
|
||||
request.setTransTradeTime("setTransTradeTime");
|
||||
|
||||
Assertions.assertEquals("setChannelNo", request.getChannelNo());
|
||||
|
||||
OpenAccSubResponse response = new OpenAccSubResponse();
|
||||
response.setRecode("setRecode");
|
||||
response.setRecodeInfo("setRecodeInfo");
|
||||
response.setSubAccountNo("setSubAccountNo");
|
||||
response.setSubAccountName("setSubAccountName");
|
||||
response.setSysDate("setSysDate");
|
||||
response.setSysTime("setSysTime");
|
||||
|
||||
Assertions.assertEquals("setRecode", response.getRecode());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void createAccount() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccPerson() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccAllPerson() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccCompany() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccAllCompany() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void modAccPerson() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void modAccCompany() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryBalance() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryBalanceBatch() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void queryCardInfo() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void addPrimAccPerson() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void addPrimAccCompany() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void inqPrimAcc() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void setPrimAcc() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void delPrimAcc() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void closedAcc() {
|
||||
}
|
||||
|
||||
@Test
|
||||
void openAccInner() {
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
|
|
@ -0,0 +1,84 @@
|
|||
package com.czcb.scfs.api.test;
|
||||
|
||||
import lombok.experimental.UtilityClass;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
@UtilityClass
|
||||
public class RefGenTestMethod {
|
||||
private static final String FMT_TEST = "@Test \nvoid %sTest() {\n";
|
||||
private static final String FMT_REQUEST = " %s request = new %s();\n";
|
||||
private static final String FMT_REQUEST_JSON = " String requestJson = Json.toJson(request);\n Assertions.assertEquals(\"\", requestJson);\n";
|
||||
private static final String FMT_RESPONSE = " %s response = new %s();\n";
|
||||
private static final String FMT_RESPONSE_JSON = " String responseJson = Json.toJson(response);\n Assertions.assertEquals(\"\", responseJson);";
|
||||
private static final String FMT_RESPONSE_RESULT_JSON = " String resultJson = Json.toJson(result);\n Assertions.assertEquals(\"\", resultJson);";
|
||||
private static final String FMT_REQUEST_METHOD = " request.%s(\"%s\");\n";
|
||||
private static final String FMT_RESPONSE_METHOD = " response.%s(\"%s\");\n";
|
||||
private static final String FMT_REQUEST_ASSERTIONS = " Assertions.assertEquals(\"%s\", request.%s());\n";
|
||||
private static final String FMT_RESPONSE_ASSERTIONS = " Assertions.assertEquals(\"%s\", response.%s());\n";
|
||||
private static final String FMT_REQUEST_MOCK = " HttpResponse<%s> httpResponse = TestHttpResponse.create(\"%s\", response, %s.class);\n";
|
||||
private static final String FMT_REQUEST_MOCK_REST = " %s result = service.%s(request);\n";
|
||||
private static final String FMT_REQUEST_MOCK_ITO = " Mockito.when(apiClient.post(\n" +
|
||||
" Mockito.eq(\"%s\"),\n" +
|
||||
" Mockito.any(HttpHeaders.class),\n" +
|
||||
" Mockito.any(RequestBody.class),\n" +
|
||||
" Mockito.eq(%s.class)))\n" +
|
||||
" .thenReturn(httpResponse);\n";
|
||||
|
||||
public static void gen(Class<?> request, Class<?> response, String methodName, String url) {
|
||||
System.out.printf(FMT_TEST, methodName);
|
||||
System.out.printf(FMT_REQUEST, request.getSimpleName(), request.getSimpleName());
|
||||
|
||||
Method[] methods = request.getMethods();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
continue;
|
||||
}
|
||||
System.out.printf(FMT_REQUEST_METHOD, method.getName(), method.getName());
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
for (Method method : methods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
continue;
|
||||
}
|
||||
System.out.printf(FMT_REQUEST_ASSERTIONS, method.getName(), method.getName().replace("set", "get"));
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("System.out.println(Json.toJson(request));");
|
||||
System.out.printf(FMT_REQUEST_JSON);
|
||||
System.out.println();
|
||||
|
||||
System.out.printf(FMT_RESPONSE, response.getSimpleName(), response.getSimpleName());
|
||||
Method[] responseMethods = response.getMethods();
|
||||
for (Method method : responseMethods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
continue;
|
||||
}
|
||||
System.out.printf(FMT_RESPONSE_METHOD, method.getName(), method.getName());
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
for (Method method : responseMethods) {
|
||||
if (!method.getName().startsWith("set")) {
|
||||
continue;
|
||||
}
|
||||
System.out.printf(FMT_RESPONSE_ASSERTIONS, method.getName(), method.getName().replace("set", "get"));
|
||||
}
|
||||
|
||||
System.out.println();
|
||||
System.out.println("System.out.println(Json.toJson(response));");
|
||||
System.out.printf(FMT_RESPONSE_JSON);
|
||||
System.out.println("\n");
|
||||
|
||||
System.out.printf(FMT_REQUEST_MOCK, response.getSimpleName(), url, response.getSimpleName());
|
||||
System.out.printf(FMT_REQUEST_MOCK_ITO, url, response.getSimpleName());
|
||||
System.out.printf(FMT_REQUEST_MOCK_REST, response.getSimpleName(), methodName);
|
||||
|
||||
System.out.println();
|
||||
System.out.println("System.out.println(Json.toJson(result));");
|
||||
System.out.printf(FMT_RESPONSE_RESULT_JSON);
|
||||
System.out.println("\n}");
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,51 @@
|
|||
package com.czcb.scfs.api.test;
|
||||
|
||||
import com.czcb.scfs.api.service.v2.account.model.*;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
class RefGenTestMethodTest {
|
||||
|
||||
@Test
|
||||
void gen() {
|
||||
RefGenTestMethod.gen(PersonOpenAccountThreeElementRequest.class, PersonOpenAccountThreeElementResponse.class,
|
||||
"personOpenAccountThreeElement", "/account/v2/person-open-account-three-element");
|
||||
|
||||
RefGenTestMethod.gen(PersonOpenAccountFourElementRequest.class, PersonOpenAccountFourElementResponse.class,
|
||||
"personOpenAccountFourElement", "/account/v2/person-open-account-four-element");
|
||||
|
||||
RefGenTestMethod.gen(OpenAccountCompanyRequest.class, OpenAccountCompanyResponse.class,
|
||||
"openAccountCompany", "/account/v2/company-open-account");
|
||||
|
||||
RefGenTestMethod.gen(ModAccPersonRequest.class, ModAccPersonResponse.class,
|
||||
"modAccPerson", "/account/v2/person-mod-account");
|
||||
|
||||
RefGenTestMethod.gen(ModAccCompanyRequest.class, ModAccCompanyResponse.class,
|
||||
"modAccCompany", "/account/v2/company-mod-account");
|
||||
|
||||
RefGenTestMethod.gen(QueryBalanceRequest.class, QueryBalanceResponse.class,
|
||||
"queryBalance", "/account/v2/query-balance");
|
||||
|
||||
RefGenTestMethod.gen(QueryCardInfoRequest.class, QueryCardInfoResponse.class,
|
||||
"queryCardInfo", "/card-bin/v2/query");
|
||||
|
||||
RefGenTestMethod.gen(PersonBindRequest.class, PersonBindResponse.class,
|
||||
"personBind", "/bank-card/v2/person-bind");
|
||||
|
||||
RefGenTestMethod.gen(CompanyBindRequest.class, CompanyBindResponse.class,
|
||||
"companyBind", "/bank-card/v2/company-bind");
|
||||
|
||||
|
||||
RefGenTestMethod.gen(BankCardQueryRequest.class, BankCardQueryResponse.class,
|
||||
"bankCardQuery", "/bank-card/v2/query");
|
||||
|
||||
|
||||
RefGenTestMethod.gen(UnbindRequest.class, UnbindResponse.class,
|
||||
"unbind", "/bank-card/v2/unbind");
|
||||
|
||||
RefGenTestMethod.gen(ClosedAccRequest.class, ClosedAccResponse.class,
|
||||
"closedAcc", "/account/v2/closed-account");
|
||||
|
||||
RefGenTestMethod.gen(OpenAccInnerRequest.class, OpenAccInnerResponse.class,
|
||||
"openAccInner", "/account/v2/inner-open-account");
|
||||
}
|
||||
}
|
||||
Loading…
Reference in New Issue