public abstract class AbstractBiz<
TRequest extends SpecificRecord, TResponse extends SpecificRecord & HasResponseStatus> {
protected void addTags(TRequest request, Map<String, String> clickHouseTags) {
try {
// xxxx
} catch (Exception e) {
// log
}
}
}
public class RefundBizImpl extends AbstractBiz<RefundRequestType, RefundResponseType> {
}
@Test
public void testAddTags() throws Exception {
try {
Type genericSuperclass = RefundBizImpl.class.getGenericSuperclass();
ParameterizedType paramType = (ParameterizedType) genericSuperclass;
//获取泛型的类型
Type[] actualTypeArguments = paramType.getActualTypeArguments();
Method[] declaredMethods = ((ParameterizedTypeImpl) genericSuperclass).getRawType().getDeclaredMethods();
Method method = null;
for (Method declaredMethod : declaredMethods) {
String name = declaredMethod.getName();
if (StringUtils.equals(name, "addTags")) {
method = declaredMethod;
break;
}
}
if (method == null) {
return;
}
method.setAccessible(true);
method.invoke(refundOrderBiz, new RefundOrderRequestType(), new HashMap<String, String>() {{
}});
} catch (
Exception e) {
Assert.fail();
}
}
}