@Test
public void testFromYarnApplicationReport() {

  ApplicationId mockAppId = mock(ApplicationId.class);
  when(mockAppId.getClusterTimestamp()).thenReturn(12345L);
  when(mockAppId.getId()).thenReturn(6789);
  ApplicationReport mockReport = mock(ApplicationReport.class);
  when(mockReport.getTrackingUrl()).thenReturn("dummy-tracking-url");
  when(mockReport.getApplicationId()).thenReturn(mockAppId);
  when(mockReport.getYarnApplicationState()).thenReturn(YarnApplicationState.KILLED);
  when(mockReport.getUser()).thenReturn("dummy-user");
  when(mockReport.getQueue()).thenReturn("dummy-queue");
  when(mockReport.getPriority()).thenReturn(Priority.newInstance(4));
  String jobFile = "dummy-path/job.xml";
  try {
    JobStatus status = TypeConverter.fromYarn(mockReport, jobFile);
  } catch (NullPointerException npe) {
    Assert.fail("Type converstion from YARN fails for jobs without " +
        "ApplicationUsageReport");
  }
  ApplicationResourceUsageReport appUsageRpt = Records
      .newRecord(ApplicationResourceUsageReport.class);
  Resource r = Records.newRecord(Resource.class);
  r.setMemorySize(2048);
  appUsageRpt.setNeededResources(r);
  appUsageRpt.setNumReservedContainers(1);
  appUsageRpt.setNumUsedContainers(3);
  appUsageRpt.setReservedResources(r);
  appUsageRpt.setUsedResources(r);
  when(mockReport.getApplicationResourceUsageReport()).thenReturn(appUsageRpt);
  JobStatus status = TypeConverter.fromYarn(mockReport, jobFile);
  Assert.assertNotNull("fromYarn returned null status", status);
  Assert.assertEquals("jobFile set incorrectly", "dummy-path/job.xml", status.getJobFile());
  Assert.assertEquals("queue set incorrectly", "dummy-queue", status.getQueue());
  Assert.assertEquals("trackingUrl set incorrectly", "dummy-tracking-url", status.getTrackingUrl());
  Assert.assertEquals("user set incorrectly", "dummy-user", status.getUsername());
  Assert.assertEquals("schedulingInfo set incorrectly", "dummy-tracking-url", status.getSchedulingInfo());
  Assert.assertEquals("jobId set incorrectly", 6789, status.getJobID().getId());
  Assert.assertEquals("state set incorrectly", JobStatus.State.KILLED, status.getState());
  Assert.assertEquals("needed mem info set incorrectly", 2048, status.getNeededMem());
  Assert.assertEquals("num rsvd slots info set incorrectly", 1, status.getNumReservedSlots());
  Assert.assertEquals("num used slots info set incorrectly", 3, status.getNumUsedSlots());
  Assert.assertEquals("rsvd mem info set incorrectly", 2048, status.getReservedMem());
  Assert.assertEquals("used mem info set incorrectly", 2048, status.getUsedMem());
  Assert.assertEquals("priority set incorrectly", JobPriority.HIGH, status.getPriority());
}