Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

InvalidUseOfMatchersException exception using PowerMockito to call static method with String array argument #16

Open
rajmaria opened this issue Sep 8, 2016 · 0 comments

Comments

@rajmaria
Copy link

rajmaria commented Sep 8, 2016

Hi there,

org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Misplaced argument matcher detected here:

I am facing the org.mockito.exceptions.misusing.InvalidUseOfMatchersException exception while doing powermockito on following static method
public class ShellCommandUtil {
public static ArrayList executeShellCommand(String[] shellcmd) {
ArrayList output = new ArrayList();
//remove the actual logic of sending shellcommand to the system and getting the result
return output;
}}

TestMethod written is defined below

@RunWith(PowerMockRunner.class)
@PrepareForTest(ShellCommandUtil.class)
public class ShellDataTest{
@test
public void testExecuteShellCommand() {
ArrayList resultData = new ArrayList();
resultData.add("data1");
resultData.add("data2");
PowerMockito.mockStatic(ShellCommandUtil.class);
PowerMockito.when(ShellCommandUtil.executeShellCommand(Mockito.any(String[].class))).thenReturn(resultData);
}
}

Can you please help what is defined wrong here in this line

PowerMockito.when(ShellCommandUtil.executeShellCommand(Mockito.any(String[].class))).thenReturn(resultData);

In pom.xml, I have added the following dependency

org.powermock powermock-mockito-release-full 1.6.4 pom
@rajmaria rajmaria changed the title WrongTypeOfReturnValue exception using PowerMockito to call static method with String array argument InvalidUseOfMatchersException exception using PowerMockito to call static method with String array argument Sep 8, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant