Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4100268
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T20:32:40+00:00 2026-05-20T20:32:40+00:00

Service Interface: public List<UserAccount> getUserAccounts(); public List<UserAccount> getUserAccounts(ResultsetOptions resultsetOptions, List<SortOption> sortOptions); Service Implementation: public

  • 0

Service Interface:

public List<UserAccount> getUserAccounts();
public List<UserAccount> getUserAccounts(ResultsetOptions resultsetOptions, List<SortOption> sortOptions);

Service Implementation:

public List<UserAccount> getUserAccounts() {
    return getUserAccounts(null, null);
}
public List<UserAccount> getUserAccounts(ResultsetOptions resultsetOptions, List<SortOption> sortOptions) {
    return getUserAccountDAO().getUserAccounts(resultsetOptions, sortOptions);
}

How can I test this using easymock or any other viable testing methodology? sample code will be appreciated. For the easy mock passing objects as parameters very confusing. Some one clearly explain whats the best approach to test the service layer? testing service interface will be considered as unit test or integration test?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-20T20:32:41+00:00Added an answer on May 20, 2026 at 8:32 pm

    Here you go, assuming you are using JUnit 4 with annotations:

    import static org.easymock.EasyMock.createStrictMock;
    import static org.easymock.EasyMock.expect;
    import static org.easymock.EasyMock.replay;
    import static org.easymock.EasyMock.verify;
    
    public class UserAccountServiceTest 
    
         private UserAccountServiceImpl service;
         private UserAccountDAO mockDao;
    
         /**
         * setUp overrides the default, We will use it to instantiate our required
         * objects so that we get a clean copy for each test.
         */
         @Before
         public void setUp() {
              service = new UserAccountServiceImpl();
              mockDao = createStrictMock(UserAccountDAO.class);
              service.setUserAccountDAO(mockDao);
         }
    
        /**
         * This method will test the "rosy" scenario of passing a valid
         * arguments and retrieveing the useraccounts.  
         */
         @Test
         public void testGetUserAccounts() {
    
              // fill in the values that you may want to return as results
              List<UserAccount> results = new User(); 
    
              /* You may decide to pass the real objects for ResultsetOptions & SortOptions */
              expect(mockDao.getUserAccounts(null, null)
                   .andReturn(results);
    
              replay(mockDao);
              assertNotNull(service.getUserAccounts(null, null));
              verify(mockDao);
         }
    
    }
    

    You might also find this article useful especially if you are using JUnit 3.

    Refer this for a quick help on JUnit 4.

    Hope that helps.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i wrote this simple example: //file TestController.java public interface TestController { public List<Test> findAll();
I have a WCF service and methods are exposed as below: public interface IService
I have a service with multiple contracts like so. [ServiceContract] public partial interface IBusinessFunctionDAO
I have a RPC service with the following method: public List<Serializable> myMethod(TransactionCall call) {...}
I have a list of servers, all exposing the same web service interface, that
I have a WCF service where I am trying to return a List (where
I am trying to get a WCF service to return a List that contains
My service interface is: [ServiceContract] public interface IMyService { [OperationContract] [WebInvoke(Method = GET, ResponseFormat
I have two Service classes which implement the same interface ServiceClass1 @Service public class
WCF Service INTERFACE : [ServiceContract] public interface ITest { [OperationContract] int TestCall(GenericType<MyType> x); [OperationContract]

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.