### Question:
MessageStoreManagerImpl implements MessageStoreManager, ApplicationContextAware { public GatewayRequest constructMessage(MessageRequest messageRequest, Language defaultLang) { GatewayRequest gatewayRequest = buildGatewayRequest(messageRequest); GatewayRequestDetails gatewayDetails = (GatewayRequestDetails) applicationContext.getBean("gatewayRequestDetails", GatewayRequestDetails.class); gatewayDetails.setMessageType(messageRequest.getMessageType()); try { if (messageRequest.getMessageType() == MessageType.TEXT) { String template = fetchTemplate(messageRequest, defaultLang); logger.debug("message template fetched"); logger.debug(template); String message = parseTemplate(template, messageRequest.getPersInfos()); logger.debug("message contructed"); logger.debug(message); int maxLength = (charsPerSMS - concatAllowance) * maxConcat - 1; message = message.length() <= maxLength ? message : message.substring(0, maxLength); int numPages = (int) Math.ceil(message.length() % (charsPerSMS - concatAllowance)); gatewayDetails.setNumberOfPages(numPages); gatewayRequest.setMessage(message); gatewayDetails.setMessage(message); } gatewayRequest.setMessageStatus(MStatus.SCHEDULED); gatewayRequest.setGatewayRequestDetails(gatewayDetails); } catch (MotechException ex) { logger.error("MotechException: " + ex.getMessage()); gatewayRequest.setMessageStatus(MStatus.FAILED); gatewayRequest.setMessage(null); GatewayResponse gwResp = coreManager.createGatewayResponse(); gwResp.setGatewayRequest(gatewayRequest); gwResp.setMessageStatus(MStatus.FAILED); gwResp.setResponseText(ex.getMessage()); gatewayRequest.getResponseDetails().add(gwResp); } gatewayDetails.getGatewayRequests().add(gatewayRequest); logger.debug("GatewayRequest object successfully constructed"); logger.debug(gatewayDetails); return gatewayRequest; }  GatewayRequest constructMessage(MessageRequest messageRequest, Language defaultLang); String parseTemplate(String template, Set<NameValuePair> templateParams); String formatPhoneNumber(String requesterPhone, MessageType type); CoreManager getCoreManager(); void setCoreManager(CoreManager coreManager); void setMaxConcat(int maxConcat); void setCharsPerSMS(int charsPerSMS); void setConcatAllowance(int concatAllowance); void setLocalNumberExpression(String localNumberExpression); void setDefaultCountryCode(String defaultCountryCode); void setApplicationContext(ApplicationContext applicationContext);  }### Answer:
@Test public void testConstructMessage() { System.out.println("consrtuctMessage"); MessageRequest message = new MessageRequestImpl(); message.setMessageType(MessageType.TEXT); Language defaultLang = new LanguageImpl(); message.setPersInfos(new HashSet<NameValuePair>()); message.setNotificationType(new NotificationTypeImpl()); expect( mockCore.createMessageTemplateDAO() ).andReturn(mockTemplateDao); expect( mockTemplateDao.getTemplateByLangNotifMType((Language)anyObject(), (NotificationType) anyObject(), (MessageType) anyObject(), (Language) anyObject()) ).andReturn(template); expect( applicationContext.getBean("gatewayRequest", GatewayRequest.class) ).andReturn(new GatewayRequestImpl()); expect( applicationContext.getBean("gatewayRequestDetails", GatewayRequestDetails.class) ).andReturn(new GatewayRequestDetailsImpl()); replay(mockCore, mockTemplateDao, applicationContext); System.out.println("111111" + instance); GatewayRequest result = instance.constructMessage(message, defaultLang); assertNotNull(result); verify(mockCore, mockTemplateDao, applicationContext); }