### Question:
DefaultStatisticsReportService implements StatisticsReportService, InitializingBean { public StatisticsReportModel getReport(StatisticsReportCommand command, BindException errors) { StatisticsReportModel model = new StatisticsReportModel(); model.setErrors(errors); if (errors.hasErrors()) { return model; } Assert.notNull(command.getId(), "id property on command object cannot be null"); StatisticsReport report = m_statisticsReportDao.load(command.getId()); model.setReport(report); m_statisticsReportDao.initialize(report); final Set<StatisticsReportData> data = report.getData(); m_statisticsReportDao.initialize(data); for (StatisticsReportData reportDatum : data) { Datum d = new Datum(); d.setValue(reportDatum.getValue()); OnmsResource resource = m_resourceDao.getResourceById(reportDatum.getResourceId()); if (resource == null) { ThreadCategory.getInstance(getClass()).warn("Could not find resource for statistics report: " + reportDatum.getResourceId()); } else { d.setResource(resource); } model.addData(d); } return model; }  List<StatisticsReport> getStatisticsReports(); StatisticsReportModel getReport(StatisticsReportCommand command, BindException errors); @Override void afterPropertiesSet(); StatisticsReportDao getStatisticsReportDao(); void setStatisticsReportDao(StatisticsReportDao statisticsReportDao); ResourceDao getResourceDao(); void setResourceDao(ResourceDao resourceDao);  }### Answer:
@Test public void testNullCommandObjectId() { StatisticsReportCommand command = new StatisticsReportCommand(); BindException errors = new BindException(command, ""); ThrowableAnticipator ta = new ThrowableAnticipator(); ta.anticipate(new IllegalArgumentException("id property on command object cannot be null")); m_mocks.replayAll(); try { m_service.getReport(command , errors); } catch (Throwable t) { ta.throwableReceived(t); } ta.verifyAnticipated(); }
@Test public void testDatumWithNonExistentResource() { StatisticsReport report = new StatisticsReport(); report.setId(1); StatisticsReportData datum = new StatisticsReportData(); ResourceReference resourceRef = new ResourceReference(); resourceRef.setId(1); resourceRef.setResourceId("node[1].interfaceSnmp[en0]"); datum.setId(1); datum.setResource(resourceRef); datum.setReport(report); datum.setValue(0.1d); report.addData(datum); StatisticsReportCommand command = new StatisticsReportCommand(); command.setId(report.getId()); BindException errors = new BindException(command, ""); expect(m_statisticsReportDao.load(report.getId())).andReturn(report); m_statisticsReportDao.initialize(report); m_statisticsReportDao.initialize(report.getData()); expect(m_resourceDao.getResourceById(resourceRef.getResourceId())).andReturn(null); m_mocks.replayAll(); StatisticsReportModel model = m_service.getReport(command, errors); assertNotNull("model should not be null", model); assertNotNull("model.getData() should not be null", model.getData()); SortedSet<Datum> data = model.getData(); assertEquals("data size", 1, data.size()); Datum d = data.first(); assertNotNull("first datum should not be null", d); assertNull("first datum resource should be null", d.getResource()); }