Win a copy of OCP Java SE 8 Programmer II Exam Study Guide this week in the OCP forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

verify a Argument Captor in junit tests  RSS feed

 
Ranch Hand
Posts: 155
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have this kind of a method,


I want to capture both datumData.basic and conceptKey here.Both methods called by same mock object.
I verified the method Arguments.But when I tried to capture conceptKey using getIdentifier method it doesn't succeed.
It show it doesn't invoked. But When I debug the code I saw debug is go through getIdentifier() method and I got conceptKey  value also.

Why it doesn't succed;

this is my test case:

@Test
  public void testUpdateConceptReferenceDatumIdentifiers() throws SpiderException
  {

 
    verify(mockInternalJournalToolkitInterface).addIdentifier(basicDataArgumentCaptor.capture(), Matchers.any());
    assertEquals(basicDataArgumentCaptor.getValue().ctx,getBasicData().ctx);
    assertEquals(basicDataArgumentCaptor.getValue().subtype , getBasicData().subtype);
   
    verify(mockInternalJournalToolkitInterface).getIdentifier(identifierArgumentCaptor.capture(), conceptKeyfArgumentCaptor.capture());
    System.out.println(conceptKeyfArgumentCaptor.getValue());  
  }

this is my error !!!

Wanted but not invoked:
mockInternalJournalToolkitInterface.getIdentifier(
    <Capturing argument>,
    <Capturing argument>
);

Is there any way to verify both arguments in one line or any other method to do this?
Please explain me?
 
chamini prashakthi
Ranch Hand
Posts: 155
3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Oh my self found the solution.It was a mistaken from me.
here method call first and then call to
So first I must call to getIdentifier So I added

then verified following lines this order ...



 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!