DataFilesProxy { public DataFilesReport getDataFiles(ProxyDocument proxyDocument) { return getServiceForType(extractDocumentType(proxyDocument.getName())).getDataFiles(createDataFilesDocument(proxyDocument)); }  DataFilesReport getDataFiles(ProxyDocument proxyDocument); @Autowired void setApplicationContext(ApplicationContext applicationContext);  }
@Test public void applicationContextHasNoBeanWithGivenNameThrowsException() throws Exception { given(applicationContext.getBean(anyString())).willThrow(new NoSuchBeanDefinitionException("Bean not loaded")); exception.expect(DataFilesServiceNotFoundException.class); exception.expectMessage("BDOCDataFilesService not found"); ProxyDocument proxyDocument = mockProxyDocumentWithDocument("filename.bdoc"); dataFilesProxy.getDataFiles(proxyDocument); verify(applicationContext).getBean(anyString()); }
@Test public void ProxyDocumentWithDDOCDocumentTypeShouldReturnDataFilesReport() throws Exception { when(applicationContext.getBean(DDOCDataFilesService.class.getSimpleName())).thenReturn(dataFilesServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithDocument("filename.ddoc"); DataFilesReport report = dataFilesProxy.getDataFiles(proxyDocument); assertEquals(dataFilesServiceSpy.dataFilesReport, report); }
@Test public void dataFilesProxyDoesNotDependOnRequestReportTypeAndAlwaysReturnsDataFilesReport() { when(applicationContext.getBean(DDOCDataFilesService.class.getSimpleName())).thenReturn(dataFilesServiceSpy); ProxyDocument proxyDocument = mockProxyDocumentWithDocument("filename.ddoc"); for (ReportType reportType : ReportType.values()) { proxyDocument.setReportType(reportType); DataFilesReport report = dataFilesProxy.getDataFiles(proxyDocument); assertTrue(report instanceof DataFilesReport); } }