关于测试的问题
Topic source这样写:
private Class<T> getParameterizedType() {
Class<?> cls = getClass();
while (cls.getSuperclass() != AbstractDao.class) {
cls = cls.getSuperclass();
}
Type type = cls.getGenericSuperclass();
...
}
这样不管几级继承都能正确找到直接继承 AbstractDao 的 Class
- 1
Pyrojewel
按照当前的写法,通不过测试,想要通过测试必须要改成
```java
private Class<T> getParameterizedType() {
Type type = getClass().getSuperclass().getGenericSuperclass();
```
java.lang.IllegalArgumentException: Class com.itranswarp.learnjava.service.UserServiceTest$1 does not have parameterized type.
不然会出现上述exception。但如果改成上面这样,运行的时候就会报错啦。请问有没有一种写法使得运行和测试都不报错呢?