assertEquals("http://fake-server.org/foo-bar-error-explained", demoRule1.getUrl().toString()); assertEquals("[This is <marker>fuu bah</marker>.]", demoRule1.getCorrectExamples().toString()); List<IncorrectExample> incorrectExamples = demoRule1.getIncorrectExamples(); assertEquals(1, incorrectExamples.size()); assertEquals("This is <marker>foo bar</marker>.", incorrectExamples.get(0).getExample());
private static String getExampleSentences(Rule rule, ResourceBundle messages) { StringBuilder examples = new StringBuilder(200); List<IncorrectExample> incorrectExamples = rule.getIncorrectExamples(); if (incorrectExamples.size() > 0) { String incorrectExample = incorrectExamples.iterator().next().getExample(); String sentence = incorrectExample.replace("<marker>", "<span style='background-color:#ff8080'>").replace("</marker>", "</span>"); examples.append("<br/>").append(sentence).append(" <span style='color:red;font-style:italic;font-weight:bold'>x</span>"); } List<CorrectExample> correctExamples = rule.getCorrectExamples(); if (correctExamples.size() > 0) { String correctExample = correctExamples.iterator().next().getExample(); String sentence = correctExample.replace("<marker>", "<span style='background-color:#80ff80'>").replace("</marker>", "</span>"); examples.append("<br/>").append(sentence).append(" <span style='color:green'>ā</span>"); } else if (incorrectExamples.size() > 0) { IncorrectExample incorrectExample = incorrectExamples.iterator().next(); List<String> corrections = incorrectExample.getCorrections(); if (!corrections.isEmpty()) { String incorrectSentence = incorrectExamples.iterator().next().getExample(); String correctedSentence = incorrectSentence.replaceAll("<marker>.*?</marker>", "<span style='background-color:#80ff80'>" + corrections.get(0) + "</span>"); examples.append("<br/>").append(correctedSentence).append(" <span style='color:green'>ā</span>"); } } if (examples.length() > 0) { examples.insert(0, "<br/><br/>" + messages.getString("guiExamples")); } return examples.toString(); }
g.writeEndObject(); for (IncorrectExample example : foundRule.getIncorrectExamples()) { g.writeStartObject(); g.writeStringField("status", "incorrect");