我试图在单元测试中验证在特定配置中未调用静态方法。
因此,我使用 PowerMock ( powermock-core:2.0.4& powermock-module-junit4:2.0.4) 及其 Mockito API ( powermock-api-mockito2:2.0.4)。
做的时候
PowerMockito.mockStatic(MyClass.class);
serviceUnderTest.methodThatShouldNotCallStaticMethod(arg1, arg2); //service not of type MyClass of course
PowerMockito.verifyStatic(MyClass.class, never());
MyClass.staticMethod(any(), any());
Run Code Online (Sandbox Code Playgroud)
在用注释的类中的测试方法上
@RunWith(PowerMockRunner.class)
@PrepareForTest({MyClass.class})
Run Code Online (Sandbox Code Playgroud)
我得到以下错误:org.mockito.exceptions.misusing.NotAMockException:
Argument passed to verify() is of type Class and is not a mock!。
我做错了什么以及如何解决?
谢谢
我试图用类型为 A 或 B 的类作为参数,仅此而已。
就像是
final class ChildClass<A | B> extends MotherClass {
Run Code Online (Sandbox Code Playgroud)
这样我就可以创建 aChildClass<A>或 aChildClass<B>但不能创建其他任何东西。
在Java中可以吗?
编辑:
我必须指定我正在使用 Java 8,并且我无法控制类 A 和 B(它们是我正在使用的 Android 框架的类)。
我正在使用 Java 8 的 lambda 表达式来分区列表(使用.collect(Collectors.partitioningBy(...))),我需要我的分区标准是元素是否是给定类的实例。
做如下工作
list.stream().collect(Collectors.partitioningBy(elt -> elt instanceof EltType))
Run Code Online (Sandbox Code Playgroud)
但是是否存在InstanceOf可以通过方法引用使用的现有“ ”谓词?
的文档Supplier::get并未明确说明其返回的可能性或不返回null。是否可以 ?
我想这可能是a的情况Supplier<Void>。在这种情况下,我如何调用 mySupplier以确保它不会导致Supplier<Void>?换句话说,哪一个T是这样的以至于它可以不是Void?