### Question:
ReferringUndefinedPagesPlugin extends AbstractReferralPlugin { @Override public String execute( final Context context, final Map<String, String> params) throws PluginException { final ResourceBundle rb = Preferences.getBundle(context, Plugin.CORE_PLUGINS_RESOURCEBUNDLE); final ReferenceManager referenceManager = context.getEngine().getManager( ReferenceManager.class ); final int items = TextUtil.parseIntParameter(params.get(PARAM_MAX), ALL_ITEMS); String extras = params.get(PARAM_EXTRAS); if (extras == null) { extras = rb.getString("referringundefinedpagesplugin.more"); } final Collection< String > uncreatedPages = referenceManager.findUncreated(); super.initialize( context, params ); Collection< String > result = null; final TreeMap< String, String > sortedMap = new TreeMap<>(); if( uncreatedPages != null ) { for( final String uncreatedPageName : uncreatedPages ) { final Collection< String > referrers = referenceManager.findReferrers( uncreatedPageName ); if( referrers != null ) { for( final String referringPage : referrers ) { sortedMap.put( referringPage, "" ); } } } result = sortedMap.keySet(); } result = super.filterAndSortCollection( result ); final String wikitext = wikitizeCollection( result, m_separator, items ); final StringBuilder resultHTML = new StringBuilder(); resultHTML.append( makeHTML( context, wikitext ) ); if( items < result.size() && items > 0 ) { final Object[] args = { "" + ( result.size() - items ) }; extras = MessageFormat.format( extras, args ); resultHTML.append( "<br/>" + extras + "<br/>" ); } return resultHTML.toString(); }  @Override String execute( final Context context, final Map<String, String> params); static final String PARAM_MAX; static final String PARAM_EXTRAS; }### Answer:
@Test public void testSimple() throws Exception { final String res = manager.execute(context, "{INSERT ReferringUndefinedPagesPlugin}"); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage01\"")); }
@Test public void testParmInClude() throws Exception { final String res = manager.execute(context, "{INSERT ReferringUndefinedPagesPlugin} include='TestPage02*'}"); Assertions.assertFalse(res.contains("href=\"/test/Wiki.jsp?page=TestPage01\"")); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage02\"")); Assertions.assertFalse(res.contains("href=\"/test/Wiki.jsp?page=TestPage03\"")); }
@Test public void testParmExClude() throws Exception { final String res = manager.execute(context,"{INSERT ReferringUndefinedPagesPlugin} exclude='TestPage02*'}"); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage01\"")); Assertions.assertFalse(res.contains("href=\"/test/Wiki.jsp?page=TestPage02\"")); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage03\"")); }
@Test public void testParmMax() throws Exception { final String res = manager.execute(context,"{INSERT ReferringUndefinedPagesPlugin} max='2'}"); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage01\"")); Assertions.assertTrue(res.contains("href=\"/test/Wiki.jsp?page=TestPage02\"")); Assertions.assertFalse(res.contains("href=\"/test/Wiki.jsp?page=TestPage03\"")); Assertions.assertTrue(res.contains("...and 1 more")); }