Results 1 to 14 of 14
Thread: Junit error
- 07-11-2011, 11:36 AM #1
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
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
- 07-11-2011, 12:08 PM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Stack trace?
Full exception text?
Line the exception is thrown from?
- 07-12-2011, 07:02 AM #3
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
It points to "when" statement.
error:java.lang.NullPointerExceptionLast edited by acmohan; 07-12-2011 at 08:01 AM.
- 07-12-2011, 07:08 AM #4
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
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.
- 07-12-2011, 09:23 AM #5
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
There were three questions up there. Stack trace?
And can you please post your code in code tags:
Focus on one error at a time.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); }
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?
- 07-12-2011, 11:49 AM #6
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
i am using mockito.
expect(DaoImpl.getService().process(Java Code:AdaoImpl DaoImpl; @Before public void setUp(){ DaoImpl=new AdaoImpl(); DaoImpl.setService(mock(Service.class)); }
request, null, null)).andReturn(response);
- 07-12-2011, 01:05 PM #7
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
One last try and them I'm out of here...
STACK TRACE?
- 07-12-2011, 01:28 PM #8
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
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.
- 07-12-2011, 01:35 PM #9
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
Sorry.
I find it hard to believe you cannot get a stack trace.
Without it how do you know where the exception is thrown?
- 07-12-2011, 01:41 PM #10
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
I have clearly mentioned where i am getting error.
i am unable to find why i am getting such error.hope you get it.Java Code:expect(DaoImpl.getService().process( request, null, null)).andReturn(response);
- 07-12-2011, 01:46 PM #11
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
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...
- 07-12-2011, 01:50 PM #12
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
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 :(.
- 07-12-2011, 02:13 PM #13
Moderator
- Join Date
- Apr 2009
- Posts
- 10,484
- Rep Power
- 16
So?
You say you have a NullPointerException.
You say it is on this line:
even though you apparently cannot give a stack trace (which begs the question of how you know it is on that line).Java Code:expect(DaoImpl.getService().process( request, null, null)).andReturn(response);
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.
- 07-12-2011, 02:25 PM #14
Member
- Join Date
- Jul 2011
- Posts
- 26
- Rep Power
- 0
Similar Threads
-
JUNIT Error | Please Help
By EpyonCustom in forum New To JavaReplies: 3Last Post: 07-11-2011, 11:45 AM -
JUnit
By cka in forum EclipseReplies: 3Last Post: 07-27-2010, 04:14 PM -
Error - "The import org.junit cannot be resolved"
By Jessaurum in forum New To JavaReplies: 7Last Post: 11-03-2009, 03:20 AM -
Getting Error while running Junit testcase in Eclipse
By Indu in forum EclipseReplies: 0Last Post: 06-26-2009, 07:40 AM -
Junit
By Azndaddy in forum New To JavaReplies: 6Last Post: 06-15-2008, 06:47 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks