Mockito: How to mock a methods to get a parameter and return a specific value every time it’s called?

        PortBuildNumberGenerator mockBuildNumberGenerator = mock(PortBuildNumberGenerator.class);
        when(mockBuildNumberGenerator.generateNextPortBuildNumberInSequence(anyString())).thenAnswer(new Answer<string>() {

            @Override
            public String answer(InvocationOnMock invocation) throws Throwable {
                Object[] args = invocation.getArguments();
                return Integer.toString(Integer.parseInt((String)args[0]) + 1);
            }
        });

3 thoughts on “Mockito: How to mock a methods to get a parameter and return a specific value every time it’s called?

  1. With this latest form of the hack you do not have
    become afraid about account obstructed. We now have developed a completely new anti-ban script that links the overall game through our personal proxy servers.

Leave a Reply

Your email address will not be published. Required fields are marked *