0
私の質問によく似た質問/回答があることは知っていますが、私はまだ試しにこの問題を解決することができません。Mockito MissingMethodInvocationException
問題: 私は設定のクラスをモックしようとしていますが、Mockitoは、この行文句:
when(settings.settingsBuilder().put(new String("test"), "test").build()).thenReturn(settings)
MissiongMethodInvocationException:
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.
を、私は可能ないくつかの方法を試してみたが、結果がありません。ベローは実際のテスト方法です。
@RunWith(PowerMockRunner.class)
@PrepareForTest({Settings.class, Client.class})
public class AddressMatcherElasticTest {
private final AddressWebConfiguration configuration = mock(AddressWebConfiguration.class);
private final Settings settings = mock(Settings.class);
private final Client client = mock(Client.class);
@Test
public void match() throws Exception {
when(configuration.getClusterName()).thenReturn(new String("name"));
when(settings.settingsBuilder().put(new String("name"), "test").build()).thenReturn(settings);
AddressMatcherElastic test = new AddressMatcherElastic(configuration);
verify(configuration, times(1)).getClusterName();
}
}
ありがとうブライアン、それは働いた。 – Bob