ClasspathSqlScriptProvider implements SqlScriptProvider { @Override public String getSqlScript() throws SqlScriptFileException { try { final Resource sqlResource = new ClassPathResource( this.sqlScriptFileLocation); final String sql = IOUtils.toString(sqlResource.getInputStream(), UTF_8); logger.debug("Report SQL Script:"); logger.debug(sql); return sql; } catch (final IOException e) { logger.error(e.getMessage(), e); throw new SqlScriptFileException(e); } } ClasspathSqlScriptProvider(AbstractReportConfig reportConfig); @Override String getSqlScript();  }
@Test public void testGetSqlScript() { final ReportProps reportProps = mock(ReportProps.class); final String sqlScriptFileLocation = "report/sql/testReport.sql"; when(reportProps.getSqlScriptFileLocation()).thenReturn( sqlScriptFileLocation); when(reportConfig.getReportProps()).thenReturn(reportProps); sut = new ClasspathSqlScriptProvider(reportConfig); final String sqlScript = sut.getSqlScript(); assertTrue(StringUtils.hasText(sqlScript)); }
@Test public void testGetSqlScript_Throws_SqlScriptFileException() { thrown.expect(SqlScriptFileException.class); final ReportProps reportProps = mock(ReportProps.class); final String sqlScriptFileLocation = "report/sql/invalidFile.sql"; when(reportProps.getSqlScriptFileLocation()).thenReturn( sqlScriptFileLocation); when(reportConfig.getReportProps()).thenReturn(reportProps); sut = new ClasspathSqlScriptProvider(reportConfig); final String sqlScript = sut.getSqlScript(); assertTrue(StringUtils.hasText(sqlScript)); }