### Question:
AbstractMessageService implements MessageService { @Override public Message createMessage(String key, Object... parameters) { MessageTemplate messageTemplate = validateMessageTemplate(key); try { return Message.of(key, messageTemplate, parameters); } catch (IllegalFormatConversionException | MissingFormatArgumentException exception) { log.debug("Internal error: Invalid message format was used", exception); messageTemplate = validateMessageTemplate(Message.INVALID_MESSAGE_TEXT_FORMAT); return Message.of(key, messageTemplate, parameters); } } AbstractMessageService(String messagesFilePath); @Override Message createMessage(String key, Object... parameters); @Override List<Message> createMessage(String key, List<Object[]> parameters);  }### Answer:
@Test public void shouldCreateMessage() { Message message = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout", "3000"); assertEquals("Message texts are different", "No response received within the allowed time: 3000", message.getConvertedText()); }
@Test public void shouldReturnInvalidMessage_IfKeyInvalid() { Message message = abstractMessageService.createMessage("invalidKey", "parameter"); String expectedMessage = "Internal error: Invalid message key 'invalidKey' provided. No default message found. Please contact support of further assistance."; assertEquals("Message texts are different", expectedMessage, message.getConvertedText()); }
@Test public void shouldReturnInvalidMessageTextFormat_IfTheFormatIsIllegal() { Message message = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout.illegalFormat", "3000"); String expectedMessageText = "Internal error: Invalid message text format. Please contact support for further assistance."; assertEquals("Message texts are different", expectedMessageText, message.getConvertedText()); message = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout.missingFormat", "3000"); assertEquals("Message texts are different", expectedMessageText, message.getConvertedText()); }
@Test public void shouldReturnInvalidMessageTextFormat_IfTheParamIsMissing() { Message message = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout.missingFormat", "3000"); String expectedMessageText = "Internal error: Invalid message text format. Please contact support for further assistance."; assertEquals("Message texts are different", expectedMessageText, message.getConvertedText()); }
@Test public void shouldCreateMessages_IfMultipleParametersArePassed() { List<Object[]> parameters = new ArrayList<>(); parameters.add(new Object[]{"2000"}); parameters.add(new Object[]{"3000"}); List<Message> messages = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout", parameters); assertEquals("Message texts are different", "No response received within the allowed time: 2000", messages.get(0).getConvertedText()); assertEquals("Message texts are different", "No response received within the allowed time: 3000", messages.get(1).getConvertedText()); }
@Test public void shouldNotCreateMessages_IfEmptyParametersArePassed() { List<Object[]> parameters = new ArrayList<>(); List<Message> messages = abstractMessageService.createMessage("org.zowe.apiml.common.serviceTimeout", parameters); assertEquals("Generated different number of messages than expected", 0, messages.size()); }
@Test public void shouldNotCreateMessages_IfEmptyParameterListIsPassed() { Message messages = abstractMessageService.createMessage("org.zowe.apiml.common.stringParamMessage", new ArrayList<String>()); assertEquals("Unexpected message format for empty parameters list", "This message has one param: []", messages.getConvertedText()); }