Mockito Spy calls the actual method of the spied class instead of returning the hardcoded mock
问题 Here's my Spy statement OAuthService oAuthServiceMock = Mockito.mock(OAuthService.class); Mockito.doReturn(oAuthServiceMock).when(inviteServiceSpy.buildOAuthService(RESOURCE_URL, CONSUMER_KEY, CONSUMER_SECRET)); Here's the method in the actual class public OAuthService buildOAuthService(String RESOURCE_URL, String CONSUMER_KEY, String CONSUMER_SECRET) { return new ServiceBuilder() .provider(new DummyOAuth1ApiProvider(RESOURCE_URL)) .apiKey(CONSUMER_KEY) .apiSecret(CONSUMER_SECRET)