Hi Guru,
It's
much easier not to test code if you don't create "new" objects
in your code.
By using the new operator and creating a
concrete class you're binding your code to the implementation.
Try this :
public class AccountManagerImpl implements AccountManager
{
private AccountWebService accountService;
public AccountManagerImpl(final AccountWebService accountService)
{
this.accountService = accountService;
}
public void addAccount(String accountDetails) throws Exception
{
// In some cases getting web service implementation with
static
methods.
//Do validation on input parameter.
//.......
this.accountService.addAccount(somerequest)
}
}
And pass your AccountWebServiceImpl implementation
into the AccountManagerImpl in the class that creates it.
Cheers,
Andy
| "gurm" <guru.maheswarareddy@wipro.com>
27-Aug-2009 15:30
|
Please respond to user@jmock.codehaus.org |
|
|
To
| user@jmock.codehaus.org
|
|
cc
|
|
|
Subject
| [jmock-user] How to mock web service
call? |
|
Hi,
I am new to Jmock.
Could you please tell me how to test below code?
publi Interface AccountWebService
{
void addAccount(String accountDetails) throws Exception;
}
public class AccountWebServiceImpl implements AccountWebService
{
public void addAccount(final String accountDetails) throws Exception
{
// Here web service actual implementation.
}
}
public Interface AccountManager
{
void addAccount(String accountDetails) throws Exception;
// Some other methods
}
public class AccountManagerImpl implements AccountManager
{
public AccountManagerImpl()
{
}
public void addAccount(String accountDetails) throws Exception
{
AccountWebService accountService = new AccountWebServiceImpl();
// In some cases getting web service implementation with
static
methods.
//Do validation on input parameter.
//.......
accountService.addAccount(somerequest)
}
}
How to mock AccountWebService here?
If we are creating objects within method instead of passing as parameters
,
How to test?
Thanks,
Guru
--
View this message in context: http://www.nabble.com/How-to-mock-web-service-call--tp25169189p25169189.html
Sent from the jMock - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe from this list, please visit:
http://xircles.codehaus.org/manage_email
-----------------------------------------------------------
This e-mail was sent by GlaxoSmithKline Services Unlimited
(registered in England and Wales No. 1047315), which is a
member of the GlaxoSmithKline group of companies. The
registered address of GlaxoSmithKline Services Unlimited
is 980 Great West Road, Brentford, Middlesex TW8 9GS.
-----------------------------------------------------------