Link to home
Start Free TrialLog in
Avatar of trance12
trance12

asked on

easymock compilation issue

Can someone advice what is wrong with the below syntax in my JwsShortMesssageServiceUnitTest file?

HandlePollingMessageResponseDto resp = new HandlePollingMessageResponseDto();
        resp.setResponse_Text("test");
        resp.setSmsc_Number(9999);
expect(mockSpringShortMessageFacade.handlePollingMessage((PollAnswer) anyObject())).andReturn(resp);

PollAnswer is a domain model object and the facade returns a domain model object PollSetup

The error it returns is:
The method anyObject() is undefined for the type JwsShortMesssageServiceUnitTest
      - The method expect(PollSetup) is undefined for the type
       JwsShortMesssageServiceUnitTest

Thanks
public PollSetup handlePollingMessage(PollAnswer pollAnswer)
        throws ServiceUnavailableException, ShortMessageApplicationException,
            InvalidResponseException;

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

looks like it should be EasyMock.anyObject

Avatar of Ajay-Singh
Ajay-Singh

Whats the compilation error you are getting?
Avatar of trance12

ASKER

This is the error:

The method anyObject() is undefined for the type JwsShortMesssageServiceUnitTest
      - The method expect(PollSetup) is undefined for the type
       JwsShortMesssageServiceUnitTest
actually making it EasyMock.anyObject took care of the 1st issue but not the second one..
how is mockSpringShortMessageFacade defined?

> actually making it EasyMock.anyObject took care of the 1st issue but not the second one..

thats because you have 2 different problems :)
mockSpringShortMessageFacade is defined as

private SpringShortMessageApplicationFacade mockSpringShortMessageFacade and that implements ShortMessageFacade
public interface ShortMessageFacade {
 
 
    public PollSetup handlePollingMessage(PollAnswer pollAnswer)
        throws ServiceUnavailableException, ShortMessageApplicationException,
            InvalidResponseException;
}

Open in new window

how is it initialized?  It looks like is not a mock instance

private SpringShortMessageApplicationFacade mockSpringShortMessageFacade;
mockSpringShortMessageFacade = EasyMock.createMock(SpringShortMessageApplicationFacade.class);

and the SpringShortMessageApplicationFacade class is shown below

public class SpringShortMessageApplicationFacade implements ShortMessageFacade {
    @Autowired
    protected MessageDao messageDao;
    protected PollAnswerDao pollAnswerDao;
    protected PollSetupDao pollSetupDao;
    protected PollSetup pollSetup;
    protected PollAnswer pollAnswer;
 
    @Transactional(readOnly = false, propagation = Propagation.REQUIRED)
 
    public PollSetup handlePollingMessage(PollAnswer message)
        throws ServiceUnavailableException, ShortMessageApplicationException,
            InvalidResponseException {
   
         pollAnswerDao.create(message);
 
        return pollSetupDao.readPollingMessageResponse(message.getSmscNumber());
    }
}

Open in new window

is the error message the same?

can you post the complete unit test method


Here is the complete class...




public class JwsShortMesssageServiceUnitTest {
    private static final Logger logger = LoggerFactory.getLogger(JwsShortMesssageServiceUnitTest.class);
    private JwsShortMessageService shortMessageService;
    private SpringShortMessageApplicationFacade mockSpringShortMessageFacade;
 
    /**
     * setUp
     *
     * @throws BeansException .
     */
    @Before
    public void setUp() throws BeansException {
        if (logger.isDebugEnabled()) {
            logger.debug("##################################################");
            logger.debug("Before Adding test data");
            logger.debug("##################################################");
        }
        mockSpringShortMessageFacade = EasyMock.createMock(SpringShortMessageApplicationFacade.class);
 
        final ShortMessageAssembler smUtil = new ShortMessageAssembler();
 
        shortMessageService = new JwsShortMessageService() {
                    ApplicationContext context = new GenericApplicationContext() {
                            public Object getBean(String arg0)
                                throws BeansException {
                                if (arg0.equals(
                                            "facade-shortmessageenablerApplicationFacade")) {
                                    return mockSpringShortMessageFacade;
                                } else if (arg0.equals(
                                            "util-shortMessageUtil")) {
                                    return smUtil;
                                } else {
                                    return super.getBean(arg0);
                                }
                            }
                        };
 
                    /**
                     * Gets the application context.
                     *
                     * @return the application context
                     */
                    protected ApplicationContext getApplicationContext() {
                        logger.debug("bBefore cleaning test data");
 
                        return context;
                    }
                };
 
    }
 
 
    //    /**
    //     * tearDown
    //     */
    @After
    public void tearDown() {
        if (logger.isDebugEnabled()) {
            logger.debug("##################################################");
            logger.debug("Before cleaning test data");
            logger.debug("##################################################");
        }
 
         reset(mockSpringShortMessageFacade);
    }
 
    @Test()
    public void testSmsPollingOK()
        throws ServiceUnavailableException, InvalidResponseException {
        // SETUP	
        HandlePollingMessageRequestDto dto = new HandlePollingMessageRequestDto();
        dto.setCallerIdentity("someuser");
        dto.setClientId("someuser");
        dto.setClientPassword("someuser");
        dto.setMessage("some message");
        dto.setMsisdn("13001456");
        dto.setProcessId("someuser");
        dto.setSignOnIdentity("someuser");
        dto.setShort_Message_Id(4444);
        dto.setMessage("test only");
 
        HandlePollingMessageResponseDto resp = new HandlePollingMessageResponseDto();
        resp.setResponse_Text("test");
        resp.setSmsc_Number(9999);
        expect(mockSpringShortMessageFacade.handlePollingMessage((PollAnswer) EasyMock.anyObject())).andReturn(resp);
        replay(mockSpringShortMessageFacade);
 
 
        resp = shortMessageService.handlePollingMessage(dto);
 
        // VERIFY
        //shortMessageService.handlePollingMessage(dto);
         verify(mockSpringShortMessageFacade);
        logger.debug("yayayaya");
    }
}

Open in new window

yes..the error message is the same..
I just realized that resp  should be a domain object and not a dto...in line 82

Although it doesnt take away the error
PollSetup resp = new PollSetup();
        resp.setResponseText("test");
        resp.setSmscNumber(9999);
        expect(mockSpringShortMessageFacade.handlePollingMessage((PollAnswer) EasyMock.anyObject())).andReturn(resp);
        replay(mockSpringShortMessageFacade);
 
        shortMessageService.handlePollingMessage(dto);

Open in new window

try :

        expect(mockSpringShortMessageFacade.handlePollingMessage(EasyMock.anyObject())).andReturn(resp);

I tried that..it gives

The method handlePollingMessage(PollAnswer) in the type SpringShortMessageApplicationFacade is not applicable for the arguments (Object)
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
yes...thats been imported..
sorry i checked the wrong file...I'm not in the right frame of mind..:)...

yes i forgot to import import static org.easymock.EasyMock.*;......that did it..:)

Thanks heaps...!!