0

When I run the test method, I got the following output:

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.
  2. Inside when() you don't call a method on mock but on some other object.
@Test // @Ignore("Fails when run with build") public void FailWhenImNotReady() throws ApplicationException, SystemException { Map<String, String> rabbitMqProperties = new HashMap<String, String>(); rabbitMqProperties.put("amqp.addresses", "10.20"); rabbitMqProperties.put("amqp.virtualhost", "/pc"); rabbitMqProperties.put("amqp.username", "Deejay"); rabbitMqProperties.put("amqp.password", "deephouse"); rabbitMqProperties.put("amqp.port", "9805"); System.getProperties().putAll(rabbitMqProperties); UserCredentials userCredentials = new UserCredentials(); userCredentials.setUserID("989864"); userCredentials.setAuthenticationSystem("djp"); EnterpriseMessageHeader enterpriseMessageHeader = new EnterpriseMessageHeader(); enterpriseMessageHeader.setUserCredentials(userCredentials); LaunchAppRequest launchAppRequest = new LaunchAppRequest(); launchAppRequest.setUcn("4848"); launchAppRequest.setHeader(enterpriseMessageHeader); when(userLogon.isUserLoggedIn(anyString(), anyString())).thenReturn(Boolean.TRUE); when(Voice.lead()).thenReturn(76584l); when(ConnectionFactoryProvider.getVocalist()).thenReturn(mock(Vocalist.class)); LaunchAppResponse response = AppLogicBean.launchApp(launchAppRequest); assertFalse(response.isSuccessful()); assertEquals(response.getErrorMessage(), MusicProducer.PROXY_MSG); } 

1 Answer 1

1

You have two errors actually:

 when(Voice.lead()).thenReturn(76584l); when(ConnectionFactoryProvider.getVocalist()).thenReturn(mock(Vocalist.class)); 

You are trying to mock static methods. Mockito cannot be used to mock static methods. If you really want to do that, you should look closer at PowerMock.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.