@Test
public void testMerge4DifferentApps() {

  AppsInfo apps = new AppsInfo();
  int value = 1000;
  AppInfo app1 = new AppInfo();
  app1.setAppId(APPID1.toString());
  app1.setAMHostHttpAddress("http://i_am_the_AM1:1234");
  app1.setState(YarnApplicationState.FINISHED);
  app1.setNumAMContainerPreempted(value);
  apps.add(app1);
  AppInfo app2 = new AppInfo();
  app2.setAppId(APPID2.toString());
  app2.setAMHostHttpAddress("http://i_am_the_AM2:1234");
  app2.setState(YarnApplicationState.ACCEPTED);
  app2.setAllocatedVCores(2 * value);
  apps.add(app2);
  AppInfo app3 = new AppInfo();
  app3.setAppId(APPID3.toString());
  app3.setAMHostHttpAddress("http://i_am_the_AM3:1234");
  app3.setState(YarnApplicationState.RUNNING);
  app3.setReservedMB(3 * value);
  apps.add(app3);
  AppInfo app4 = new AppInfo();
  app4.setAppId(APPID4.toString());
  app4.setAMHostHttpAddress("http://i_am_the_AM4:1234");
  app4.setState(YarnApplicationState.NEW);
  app4.setAllocatedMB(4 * value);
  apps.add(app4);
  AppsInfo result = RouterWebServiceUtil.mergeAppsInfo(apps.getApps(), false);
  Assert.assertNotNull(result);
  Assert.assertEquals(4, result.getApps().size());
  List<String> appIds = new ArrayList<String>();
  AppInfo appInfo1 = null, appInfo2 = null, appInfo3 = null, appInfo4 = null;
  for (AppInfo app : result.getApps()) {
    appIds.add(app.getAppId());
    if (app.getAppId().equals(APPID1.toString())) {
      appInfo1 = app;
    }
    if (app.getAppId().equals(APPID2.toString())) {
      appInfo2 = app;
    }
    if (app.getAppId().equals(APPID3.toString())) {
      appInfo3 = app;
    }
    if (app.getAppId().equals(APPID4.toString())) {
      appInfo4 = app;
    }
  }
  Assert.assertTrue(appIds.contains(APPID1.toString()));
  Assert.assertTrue(appIds.contains(APPID2.toString()));
  Assert.assertTrue(appIds.contains(APPID3.toString()));
  Assert.assertTrue(appIds.contains(APPID4.toString()));
  // Check preservations APP1
  Assert.assertEquals(app1.getState(), appInfo1.getState());
  Assert.assertEquals(app1.getNumAMContainerPreempted(),
      appInfo1.getNumAMContainerPreempted());
  // Check preservations APP2
  Assert.assertEquals(app2.getState(), appInfo2.getState());
  Assert.assertEquals(app3.getAllocatedVCores(),
      appInfo3.getAllocatedVCores());
  // Check preservations APP3
  Assert.assertEquals(app3.getState(), appInfo3.getState());
  Assert.assertEquals(app3.getReservedMB(), appInfo3.getReservedMB());
  // Check preservations APP3
  Assert.assertEquals(app4.getState(), appInfo4.getState());
  Assert.assertEquals(app3.getAllocatedMB(), appInfo3.getAllocatedMB());
}