When I want to test my method I got this error, I am new to unit testing. Not able to find the exact issue.Seems like error in the second last line of the test method while printing test6
log.
Any suggestion !
12 Jul 2021 13:51:54,915 [INFO ] (main) amazon.platform.config.AppConfigTree:1756: No appgroup found
test1
test2
test3
test4
test5
org.mockito.exceptions.misusing.InvalidUseOfMatchersException:
Invalid use of argument matchers!
4 matchers expected, 3 recorded:
This exception may occur if matchers are combined with raw values:
//incorrect:
someMethod(anyObject(), "raw String");
When using matchers, all arguments have to be provided by matchers.
For example:
//correct:
someMethod(anyObject(), eq("String by matcher"));
For more info see javadoc for Matchers class.
This is the class that I want to test.
public String addCommitAndPushUntrackedChanges(final String deviceName, final List<String> filesList)
throws GitAPIException, IOException, DependencyFailureException {
final String tempCommitBranchName = String.format("Add Sync "
+ "rules : [%s]", deviceName);
final File gitFile = new File(String.join("/", CLONED_REPO_PATH, ".git"));
String CommitId = jgitAccessor.addAndCommitUntrackedChanges(gitFile, deviceName, tempCommitBranchName, filesList);
gitFarmServiceAccessor.loadTmpSshTicket();
jgitAccessor.pushToTemporaryBranch(gitFile, REPO_URI, deviceName);
return CommitId;
}
This is the test method
@InjectMocks
CreateIngestionRulesTaskBuilder builder;
@Test
public void addCommitAndPushUntrackedChanges_happyCase() throws Exception {
System.out.println("test1");
Mockito.doNothing().when(gitFarmServiceAccessor).loadTmpSshTicket();
System.out.println("test2");
System.out.println("test3");
Mockito.doNothing().when(jgitAccessor).pushToTemporaryBranch(REPO_FILE, REPO_LOCATION,"abc");
System.out.println("test4");
when(jgitAccessor.addAndCommitUntrackedChanges(eq(REPO_FILE),eq(TEST_DEVICE_NAME),eq(TEST_COMMIT_MSG), anyList())).thenReturn(eq(TEST_COMMIT_ID));
System.out.println("test5");
builder.addCommitAndPushUntrackedChanges(any(), anyList());
System.out.println("test6");
}