### Question:
WhiteAndBlackList implements StringFilter { public WhiteAndBlackList() { } WhiteAndBlackList(); @Override void init(Config config); @Override boolean use(String data); @Override boolean checkPrefix(String data); void init(StringList whitelist, StringList blacklist); void initBlacklist(Config blacklistConfig); void initWhitelist(Config whitelistConfig); StringList getBlacklist(); void setBlacklist(StringList blacklist); StringList getWhitelist(); void setWhitelist(StringList whitelist); boolean isOnBlacklist(String string); boolean isOnBlacklistCheckPrefix(String string); boolean isOnWhitelist(String string); boolean isOnWhitelistCheckPrefix(String string); boolean usesWhitelist(); void useWhitelist(boolean useWhitelist); boolean usesBlacklist(); void useBlacklist(boolean useBlacklist); static final String KEY_WHITELIST; static final String KEY_BLACKLIST; }### Answer:
@Test public void testWhiteAndBlacklist() throws BadConfigException, IOException { Config config = getXmlConfig("/white-and-blacklist.xml"); WhiteAndBlackList filter = config.getComponentAndInit("wbl", WhiteAndBlackList.class); assertNotNull(filter); assertTrue(filter.usesBlacklist()); assertTrue(filter.usesWhitelist()); String[] data = new String[]{"a", "", " ", "1", "abc", "Hello", "World"}; for (String s : data) { assertFalse(filter.checkPrefix(s)); assertFalse(filter.use(s)); } assertTrue(filter.use("whitelisted")); assertTrue(filter.use("test is whitelisted")); assertFalse(filter.use("test is whitelisted except for this")); assertFalse(filter.use("It works! :)")); assertTrue(filter.checkPrefix("test is whitelisted and we can write anything here")); assertFalse(filter.checkPrefix("test is whitelisted except for this")); assertFalse(filter.checkPrefix("test is whitelisted except for this :)")); }