gpt4 book ai didi

java - 使用 mockito stub final 方法

转载 作者:行者123 更新时间:2023-11-30 08:27:01 40 4
gpt4 key购买 nike

<分区>

我需要使用具有 final 方法的模拟。所以我使用 powermock 但它不起作用

class B {
public final int nb() {
return 4;
}
}

@RunWith(PowerMockRunner.class)
@PrepareForTest(B.class)
public class Exemple extends TestCase {
@Test
public void test() {
B b = PowerMockito.mock(B.class);

PowerMockito.when(b.nb()).thenReturn(5);

final int actualState = b.nb();

assertEquals(5, actualState);

}
}

如果有人有解决方案,提前谢谢你

40 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com