ProviderHelper { public static void compareProviders(List<ProviderInfo> oldList, List<ProviderInfo> newList, List<ProviderInfo> add, List<ProviderInfo> remove) { if (CommonUtils.isEmpty(oldList)) { if (CommonUtils.isNotEmpty(newList)) { add.addAll(newList); } } else { if (CommonUtils.isEmpty(newList)) { remove.addAll(oldList); } else { if (CommonUtils.isNotEmpty(oldList)) { List<ProviderInfo> tmpList = new ArrayList<ProviderInfo>(newList); for (ProviderInfo oldProvider : oldList) { if (tmpList.contains(oldProvider)) { tmpList.remove(oldProvider); } else { remove.add(oldProvider); } } add.addAll(tmpList); } } } }  static void compareGroup(ProviderGroup oldGroup, ProviderGroup newGroup,
                                    List<ProviderInfo> add, List<ProviderInfo> remove); static void compareProviders(List<ProviderInfo> oldList, List<ProviderInfo> newList,
                                        List<ProviderInfo> add, List<ProviderInfo> remove); static void compareGroups(List<ProviderGroup> oldGroups, List<ProviderGroup> newGroups,
                                     List<ProviderInfo> add,
                                     List<ProviderInfo> remove); static boolean isEmpty(ProviderGroup group); static String toUrl(ProviderInfo providerInfo); static ProviderInfo toProviderInfo(String url);  }
@Test public void compareProviders() throws Exception { ProviderGroup group1 = new ProviderGroup("a"); ProviderGroup group2 = new ProviderGroup("a"); List<ProviderInfo> oldList = new ArrayList<ProviderInfo>(); List<ProviderInfo> newList = new ArrayList<ProviderInfo>(); List<ProviderInfo> add = new ArrayList<ProviderInfo>(); List<ProviderInfo> remove = new ArrayList<ProviderInfo>(); group1.setProviderInfos(oldList); group2.setProviderInfos(newList); { ProviderHelper.compareGroup(group1, group2, add, remove); Assert.assertEquals(add.size(), 0); Assert.assertEquals(remove.size(), 0); } { oldList.clear(); newList.clear(); add.clear(); remove.clear(); oldList.add(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0")); oldList.add(ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0")); oldList.add(ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0")); ProviderHelper.compareGroup(group1, group2, add, remove); Assert.assertEquals(add.size(), 0); Assert.assertEquals(remove.size(), 3); } { oldList.clear(); newList.clear(); add.clear(); remove.clear(); newList.add(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0")); newList.add(ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0")); newList.add(ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0")); ProviderHelper.compareGroup(group1, group2, add, remove); Assert.assertEquals(add.size(), 3); Assert.assertEquals(remove.size(), 0); } { oldList.clear(); newList.clear(); add.clear(); remove.clear(); oldList.add(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0")); oldList.add(ProviderHelper.toProviderInfo("127.0.0.2:12200?p=11&v=4.0")); oldList.add(ProviderHelper.toProviderInfo("127.0.0.3:12200?p=11&v=4.0")); newList.add(ProviderHelper.toProviderInfo("127.0.0.1:12200?p=11&v=4.0")); newList.add(ProviderHelper.toProviderInfo("127.0.0.4:12200?p=11&v=4.0")); newList.add(ProviderHelper.toProviderInfo("127.0.0.5:12200?p=11&v=4.0")); ProviderHelper.compareGroup(group1, group2, add, remove); Assert.assertEquals(add.size(), 2); Assert.assertEquals(remove.size(), 2); } }