@Test public void testCustomMessageWithParametersNegative() throws Exception { final DefaultConfiguration config = createModuleConfig(emptyCheck.getClass()); config.addMessage("msgKey", "This is a custom message {0."); emptyCheck.configure(config); try { emptyCheck.log(1, "msgKey", "TestParam"); fail("exception expected"); } catch (IllegalArgumentException ex) { assertEquals("Error message is unexpected", "Unmatched braces in the pattern.", ex.getMessage()); } }
@Test public void testCustomMessage() throws Exception { final DefaultConfiguration config = createModuleConfig(emptyCheck.getClass()); config.addMessage("msgKey", "This is a custom message."); emptyCheck.configure(config); emptyCheck.log(1, "msgKey"); final SortedSet<LocalizedMessage> messages = emptyCheck.getMessages(); assertEquals("Amount of messages differs from expected", 1, messages.size()); assertEquals("Message differs from expected", "This is a custom message.", messages.first() .getMessage()); }
@Test public void testCustomMessageWithParameters() throws Exception { final DefaultConfiguration config = createModuleConfig(emptyCheck.getClass()); config.addMessage("msgKey", "This is a custom message with {0}."); emptyCheck.configure(config); emptyCheck.log(1, "msgKey", "TestParam"); final SortedSet<LocalizedMessage> messages = emptyCheck.getMessages(); assertEquals("Amount of messages differs from expected", 1, messages.size()); assertEquals("Message differs from expected", "This is a custom message with TestParam.", messages.first().getMessage()); }
@Override public void setupChild(Configuration childConf) throws CheckstyleException { ModuleFactory moduleFactory = createModuleFactory(); String name = childConf.getName(); Object module = moduleFactory.createModule(name); if (!(module instanceof AbstractCheck)) { throw new CheckstyleException("OptionalCheck is not allowed as a parent of " + name + " Please review 'Parent Module' section for this Check."); } if (this.check != null) { throw new CheckstyleException("Can only make a single check optional"); } AbstractCheck check = (AbstractCheck) module; check.contextualize(this.childContext); check.configure(childConf); check.init(); this.check = check; }