JUnit - How to mock helper class method call?
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Simon_Samuel
Posted On:   Sunday, September 25, 2005 06:37 PM

Hi, Can someone guide me on this please. I am trying to write a unit test for the following: methodA() { myservice.callMe(); Date d = MyHelper.createDate(); } Here is the helper class: public class MyHelper { protected MyHelper() { } ... ... public static Date createDate() { ... } } I have a private constructor to prevent anyone from instatiating the helper class. Now here is my test: testMethodA() { // Mocked the call to myservice // These are my questions: ?? I would like to mock t   More>>

Hi,
Can someone guide me on this please. I am trying to write a unit test for the following:



			
methodA() {
myservice.callMe();
Date d = MyHelper.createDate();
}


Here is the helper class:



			
public class MyHelper {
protected MyHelper() {
}
...
...
public static Date createDate() {
...
}
}




I have a private constructor to prevent anyone from instatiating the helper class. Now here is my test:



			
testMethodA() {
// Mocked the call to myservice

// These are my questions:


?? I would like to mock the method call on the helper class as the helper method functionality has been tested in isolation, in the test for the helper class.


?? How will I define the helper class method call?


?? I tried using MockClassControl (easymock) but since the constructor is protected, I get an error saying that the constructor is not visible.


			
}

I need some guidance guys. Thanks in advance.

Sam.    <<Less
About | Sitemap | Contact