在我的课堂上,我模拟了以下对象:
@Mock
private Health.Builder builder;
@Mock
private ServiceInstanceHealthIndicator serviceInstanceHealthIndicator;
在有关方法中,我具有以下相关代码段:
boolean microServicesHealthStatusIsDown = false;
List<String> serviceIds = Stream.of("Instanceone", "Instancetwo").collect(Collectors.toList());
List<ServiceInstance> serviceInstances = Collections.singletonList(serviceInstance);
ReflectionTestUtils.setField(serviceInstanceHealthIndicator, "serviceIds", serviceIds );
ReflectionTestUtils.setField(serviceInstanceHealthIndicator, "builder", builder );
ReflectionTestUtils.setField(serviceInstanceHealthIndicator, "microserviceHealthStatusIsDown", microServicesHealthStatusIsDown );
given(new ServiceInstanceHealthIndicator(serviceIds, builder, microServicesHealthStatusIsDown)).willReturn(ServiceInstanceHealthIndicator);
我认为问题可能是因为建造者来自最后一堂课,这可能是吗?这是堆栈跟踪:
org.mockito.exceptions.misusing.MissingMethodInvocationException:
when() requires an argument which has to be 'a method call on a mock'.
For example:
when(mock.getArticles()).thenReturn(articles);
Also, this error might show up because:
1. you stub either of: final/private/equals()/hashCode() methods.
Those methods *cannot* be stubbed/verified.
Mocking methods declared on non-public parent classes is not supported.
2. inside when() you don't call method on mock but on some other object.
我将如何模拟这个特定的对象创建?我曾尝试使用any()或eq()来走运,我应该如何在该行的参数中加注?