【发布时间】:2021-09-27 05:35:54
【问题描述】:
将java转换为kotlin,它有一个java包级别的可见性类
class NotificationManager extends Base {
NotificationManager(Context context) {
super(context);
... ...
}
断言此构造函数的单元测试不公开
@Test
public void verify_Constructor() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
Constructor<NotificationManager> constructor = NotificationManager.class.getDeclaredConstructor(Context.class);
constructor.newInstance(application);
assertFalse(Modifier.isPublic(constructor.getModifiers()));
}
转换kotlin后变成内部可见性
internal class NotificationManager internal constructor(context: Context) : Base(context) {...}
但测试在 assertFalse(Modifier.isPublic(constructor.getModifiers())); 失败。
在单元测试中如何断言 kotlin 内部类的构造函数不公开?
【问题讨论】:
标签: unit-testing kotlin constructor