BlackListFileLoader { static void overrideBlackList(List<String> originList, String overrideStr) { List<String> adds = new ArrayList<String>(); String[] overrideItems = StringUtils.splitWithCommaOrSemicolon(overrideStr); for (String overrideItem : overrideItems) { if (StringUtils.isNotBlank(overrideItem)) { if (overrideItem.startsWith("!") || overrideItem.startsWith("-")) { overrideItem = overrideItem.substring(1); if ("*".equals(overrideItem) || "default".equals(overrideItem)) { originList.clear(); } else { originList.remove(overrideItem); } } else { if (!originList.contains(overrideItem)) { adds.add(overrideItem); } } } } if (adds.size() > 0) { originList.addAll(adds); } }   static final List<String> SOFA_SERIALIZE_BLACK_LIST; }
@Test public void overrideBlackList() { List<String> origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-*"); Assert.assertTrue(origin.size() == 0); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "!*"); Assert.assertTrue(origin.size() == 0); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-default"); Assert.assertTrue(origin.size() == 0); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "!default"); Assert.assertTrue(origin.size() == 0); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-*,-com.xxx"); Assert.assertTrue(origin.size() == 0); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "aaa,-*,-com.xxx"); Assert.assertTrue(origin.size() == 1); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-*,aaa"); Assert.assertTrue(origin.size() == 1); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-com.xxx"); Assert.assertTrue(origin.size() == 2); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "-com.xxx,-com.yyy"); Assert.assertTrue(origin.size() == 1); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "com.xxx,-com.yyy"); Assert.assertTrue(origin.size() == 2); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "com.aaa,-com.yyy"); Assert.assertTrue(origin.size() == 3); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "com.aaa"); Assert.assertTrue(origin.size() == 4); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "com.xxx;com.yyy;com.zzz"); Assert.assertTrue(origin.size() == 3); origin = buildOriginList(); BlackListFileLoader.overrideBlackList(origin, "com.aaa,com.bbb,com.ccc"); Assert.assertTrue(origin.size() == 6); }