Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 714
  • Last Modified:

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

0
trance12
Asked:
trance12
  • 10
  • 7
1 Solution
 
objectsCommented:
looks like it should be EasyMock.anyObject

0
 
Ajay-SinghCommented:
Whats the compilation error you are getting?
0
 
trance12Author Commented:
This is the error:

The method anyObject() is undefined for the type JwsShortMesssageServiceUnitTest
      - The method expect(PollSetup) is undefined for the type
       JwsShortMesssageServiceUnitTest
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
trance12Author Commented:
actually making it EasyMock.anyObject took care of the 1st issue but not the second one..
0
 
objectsCommented:
how is mockSpringShortMessageFacade defined?

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

thats because you have 2 different problems :)
0
 
trance12Author Commented:
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

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

0
 
trance12Author Commented:
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

0
 
objectsCommented:
is the error message the same?

can you post the complete unit test method


0
 
trance12Author Commented:
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

0
 
trance12Author Commented:
yes..the error message is the same..
0
 
trance12Author Commented:
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

0
 
objectsCommented:
try :

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

0
 
trance12Author Commented:
I tried that..it gives

The method handlePollingMessage(PollAnswer) in the type SpringShortMessageApplicationFacade is not applicable for the arguments (Object)
0
 
objectsCommented:
Have you imported EasyMock?

import static org.easymock.EasyMock.*;


0
 
trance12Author Commented:
yes...thats been imported..
0
 
trance12Author Commented:
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...!!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 10
  • 7
Tackle projects and never again get stuck behind a technical roadblock.
Join Now