### Question:
MediaWikiUtil { public static WikiTemplate extractTemplate(String markup) { Validate.notNull(markup, "markup must not be null"); Map<String, String> properties = new LinkedHashMap<String, String>(); String content = markup.substring(2, markup.length() - 2); String templateName = getTemplateName(content); if (markup.toLowerCase().startsWith("{{geobox")) { content = markup.substring(markup.indexOf('|') + 1, markup.length() - 2); } int i = 0; for (String part : splitTemplateMarkup(content)) { String key = String.valueOf(i++); int equalIdx = part.indexOf('='); if (equalIdx > 0) { String potentialKey = part.substring(0, equalIdx); if (isBracketBalanced(potentialKey) && isTagBalanced(potentialKey)) { key = part.substring(0, equalIdx).trim(); } else { equalIdx = -1; } } String value = part.substring(equalIdx + 1).trim(); properties.put(key, value); } return new WikiTemplate(templateName, properties); } private  MediaWikiUtil(); static String stripMediaWikiMarkup(String markup); static String extractSentences(String text); static final WikiPage retrieveArticle(MediaWikiDescriptor descriptor, String title); static final List<WikiPageReference> retrieveArticlesForCategory(MediaWikiDescriptor descriptor,
            String categoryName); static final WikiPageReference retrieveRandomArticle(MediaWikiDescriptor descriptor); static final List<WikiPageReference> retrieveBacklinks(MediaWikiDescriptor descriptor, String pageName); static WikiTemplate extractTemplate(String markup); static List<String> getNamedMarkup(String markup, String... names); static void parseDump(File wikipediaDump, Consumer<WikiPage> action, ProgressReporter progress); static void parseDump(File wikipediaDump, Consumer<WikiPage> action); static void parseDump(InputStream inputStream, Consumer<WikiPage> action); static void main(String[] args); static final Pattern HEADING_PATTERN; static final Pattern INTERNAL_LINK_PATTERN; static final Pattern REDIRECT_PATTERN; }### Answer:
@Test public void testTemplateExtraction() throws FileNotFoundException { String quote = "{{Quote|text=Cry \"Havoc\" and let slip the dogs of war.|sign=[[William Shakespeare]]|source=''[[Julius Caesar (play)|Julius Caesar]]'', act III, scene I}}"; WikiTemplate extractedTemplate = MediaWikiUtil.extractTemplate(quote); assertEquals(3, extractedTemplate.size()); assertEquals("Cry \"Havoc\" and let slip the dogs of war.", extractedTemplate.getEntry("text")); quote = "{{Quote|Cry \"Havoc\" and let slip the dogs of war.|[[William Shakespeare]]|''[[Julius Caesar (play)|Julius Caesar]]'', act III, scene I}}"; extractedTemplate = MediaWikiUtil.extractTemplate(quote); assertEquals(3, extractedTemplate.size()); assertEquals("Cry \"Havoc\" and let slip the dogs of war.", extractedTemplate.getEntry("0")); }