Results 1 to 14 of 14

Thread: Junit error

  1. #1
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default Junit error

    etup(){
    dordao.exampleservice(mock(exampleservice.class));
    }

    @Test
    public void exampl(){
    ..
    .
    .
    .
    when(dordao.exampleservice.process(any(request.cla ss),any(RequestHeaderT.class),(Holder<ResponseHead erT>) any()).thenreturn(response));

    List<String> lst=exampleservice.example();
    //example will return list of strings
    .
    .
    .
    }

    above is the sample if i run this i get
    java.lang.NullPointerException OR
    Type mismatch 3 parameters expected but one recorded.

    can any one help on this.Its really urgent

    thanks in advance
    acm

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Stack trace?
    Full exception text?
    Line the exception is thrown from?

  3. #3
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    It points to "when" statement.

    error:java.lang.NullPointerException
    Last edited by acmohan; 07-12-2011 at 08:01 AM.

  4. #4
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    one more error "java.lang.IllegalStateException: no last call on a mock available" below is the code.

    @Test
    public void testGetis() {
    ServiceProcessResponse response = new ServiceProcessResponse();

    response.setStatus("S");
    response.setError(null);
    ServiceProcessRequest request=new ServiceProcessRequest();
    request.setEmailAddress("11");
    request.setOrderNumber("123");
    expect(DaoImpl.getService().process(
    request, null, null)).andReturn(response);
    replay(promotionDaoImpl);
    DaoImpl.data(anyString(),anyBoolean(), anyBoolean());
    verify(DaoImpl);
    }
    i am getting error at "when" statement line.

    here when i say return(response) ,it s returning null instead of what i have defined.

    can any one help on this please.
    Last edited by acmohan; 07-12-2011 at 08:03 AM.

  5. #5
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    There were three questions up there. Stack trace?

    And can you please post your code in code tags:
    Java Code:
    @Test
    	public void testGetis() {
    		ServiceProcessResponse response = new ServiceProcessResponse();
    		
    		response.setStatus("S");
    		response.setError(null);
    		ServiceProcessRequest request=new ServiceProcessRequest();
    		request.setEmailAddress("11");
    		request.setOrderNumber("123");
    		expect(DaoImpl.getService().process(
    				request, null, null)).andReturn(response);
    		replay(promotionDaoImpl);
    		DaoImpl.data(anyString(),anyBoolean(), anyBoolean());
    		verify(DaoImpl);
    	}
    Focus on one error at a time.
    What mocking framework are you using?
    How are you setting up the mocked objects?
    How are you injecting them into the class you are testing?

  6. #6
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    i am using mockito.
    Java Code:
    AdaoImpl DaoImpl;
    @Before
    public void setUp(){
    DaoImpl=new AdaoImpl();
    DaoImpl.setService(mock(Service.class));
    }
    expect(DaoImpl.getService().process(
    request, null, null)).andReturn(response);

  7. #7
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    One last try and them I'm out of here...
    STACK TRACE?

  8. #8
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    I am really sorry for it. My sts got crashed.
    let me explain to u .
    when i run above test case in debug mode,
    when "DaoImpl.getService().process(request, null, null).andReturn(response) " calls ( wat we mean s when we call getService.process just return us response(which we have set)). but its s setting back to null i.e response=null. so i am getting null pointer exception.
    hope u get it.
    i am really sorry i am nt able to provide stack trace.
    can you suggest something on this.

  9. #9
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    Sorry.
    I find it hard to believe you cannot get a stack trace.
    Without it how do you know where the exception is thrown?

  10. #10
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    I have clearly mentioned where i am getting error.
    Java Code:
    expect(DaoImpl.getService().process(
    request, null, null)).andReturn(response);
    i am unable to find why i am getting such error.hope you get it.

  11. #11
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    How did you know that was the line if you can't post a stack trace?
    Because otherwise, DaoImpl is null, the return from getService() is null, or the expect() is returning null.
    Now, according to your setup code DaoImpl and Service are set...

  12. #12
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

    Default

    when ever we call "getService().process(request, null, null))" we expect it to return response which we have defined.but i am getting it as null. i am not able get y. if you have any suggestion how can i trace it,it will be great help else will leave this thread here :(.

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,044
    Rep Power
    20

    Default

    So?
    You say you have a NullPointerException.
    You say it is on this line:
    Java Code:
    expect(DaoImpl.getService().process(
    				request, null, null)).andReturn(response);
    even though you apparently cannot give a stack trace (which begs the question of how you know it is on that line).

    In which case you need to check whether DaoImpl, or the thing returned by getService(), is null.
    Write some code before the expect() call to check that, and see.
    Until you do that no one can help you.

  14. #14
    acmohan is offline Member
    Join Date
    Jul 2011
    Posts
    26
    Rep Power
    0

Similar Threads

  1. JUNIT Error | Please Help
    By EpyonCustom in forum New To Java
    Replies: 3
    Last Post: 07-11-2011, 11:45 AM
  2. JUnit
    By cka in forum Eclipse
    Replies: 3
    Last Post: 07-27-2010, 04:14 PM
  3. Error - "The import org.junit cannot be resolved"
    By Jessaurum in forum New To Java
    Replies: 7
    Last Post: 11-03-2009, 03:20 AM
  4. Replies: 0
    Last Post: 06-26-2009, 07:40 AM
  5. Junit
    By Azndaddy in forum New To Java
    Replies: 6
    Last Post: 06-15-2008, 06:47 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •