### Question:
ReportUnitResourceValidator extends GenericResourceValidator<T> { protected boolean isJrxmlValid(ResourceReference jrxmlReference) { boolean isValid = true; try { byte[] data = null; if (jrxmlReference.isLocal()) { data = ((FileResource) jrxmlReference.getLocalResource()).getData(); } if (data == null) { data = repositoryService.getResourceData(null, jrxmlReference.getTargetURI()).getData(); } loadJasperDesign(data); } catch (Exception e) { isValid = false; } return isValid; }    }### Answer:
@Test public void testValidate() throws Exception { final ResourceReference mainReport = report.getMainReport(); doReturn(true).when(validator).isJrxmlValid(mainReport); validator.validate(report); verify(validator).isJrxmlValid(mainReport); }
@Test public void testValidate_invalidJrxml_exception() throws Exception { doReturn(false).when(validator).isJrxmlValid(report.getMainReport()); final List<Exception> exceptions = validator.validate(report); assertNotNull(exceptions); Assert.assertFalse(exceptions.isEmpty()); }
@Test public void testValidate_noJRXML() throws Exception { report.setMainReport((FileResource) null); doThrow(new RuntimeException("Should not call isJrxmlValid()")) .when(validator).isJrxmlValid(any(ResourceReference.class)); final List<Exception> exceptions = validator.validate(report); assertNotNull(exceptions); Assert.assertFalse(exceptions.isEmpty()); }
@Test public void testValidate_noJRXMLContent() throws Exception { final FileResourceImpl fileResource = new FileResourceImpl(); fileResource.setURIString("/test/uri"); report.setMainReport(fileResource); doThrow(new RuntimeException("Should not call isJrxmlValid()")) .when(validator).isJrxmlValid(any(ResourceReference.class)); final List<Exception> exceptions = validator.validate(report); assertNotNull(exceptions); Assert.assertFalse(exceptions.isEmpty()); }
@Test public void validate_noResourceData_exception() { List<ResourceReference> resourceReferences = new ArrayList<ResourceReference>(); final FileResourceImpl localResource = new FileResourceImpl(); localResource.setURIString("/test/uri"); resourceReferences.add(new ResourceReference(localResource)); report.setResources(resourceReferences); doReturn(true).when(validator).isJrxmlValid(any(ResourceReference.class)); final List<Exception> exceptions = validator.validate(report); assertNotNull(exceptions); Assert.assertFalse(exceptions.isEmpty()); }