@Override public CloseableIterator<ScannerReport.ContextProperty> readContextProperties() { return CloseableIterator.from(contextProperties.iterator()); }
@Override public CloseableIterator<String> readScannerLogs() { if (scannerLogs == null) { throw new IllegalStateException("Scanner logs are missing"); } return CloseableIterator.from(scannerLogs.iterator()); }
@Override public CloseableIterator<ScannerReport.ActiveRule> readActiveRules() { if (activeRules == null) { throw new IllegalStateException("Active rules are not set"); } return CloseableIterator.from(activeRules.iterator()); }
private static CloseableIterator<String> scannerContextInputStreamOf(String data) { return CloseableIterator.from(singleton(data).iterator()); }
@Override public Optional<CloseableIterator<String>> readFileSource(int fileRef) { List<String> lines = fileSources.get(fileRef); if (lines == null) { return Optional.empty(); } return Optional.of(CloseableIterator.from(lines.iterator())); }
@Override public Optional<CloseableIterator<LineSgnificantCode>> readComponentSignificantCode(int fileRef) { List<LineSgnificantCode> list = significantCode.get(fileRef); return list == null ? Optional.empty() : Optional.of(CloseableIterator.from(list.iterator())); }
@Test(expected = NullPointerException.class) public void from_iterator_throws_early_NPE_if_arg_is_null() { CloseableIterator.from(null); }
private static LogsIteratorInputStream create(String... lines) { return new LogsIteratorInputStream(CloseableIterator.from(Arrays.asList(lines).iterator()), UTF_8); }
@Test public void verify_has_next_from_iterator_with_empty_iterator() { assertThat(CloseableIterator.from(Collections.<String>emptyList().iterator()).hasNext()).isFalse(); }
@Override public CloseableIterator<String> readLines(Component component) { checkNotNull(component, "Component should not be bull"); if (!component.getType().equals(Component.Type.FILE)) { throw new IllegalArgumentException(String.format("Component '%s' is not a file", component)); } Collection<String> componentLines = lines.get(component.getReportAttributes().getRef()); checkState(!componentLines.isEmpty(), String.format("File '%s' has no source code", component)); return CloseableIterator.from(componentLines.iterator()); }
@Test(expected = NoSuchElementException.class) public void verify_next_from_iterator_with_empty_iterator() { CloseableIterator.from(Collections.<String>emptyList().iterator()).next(); }
@Test public void getRawSourceHash_reads_lines_from_SourceLinesRepository_only_the_first_time() { when(mockedSourceLinesRepository.readLines(FILE_COMPONENT)).thenReturn(CloseableIterator.from(Arrays.asList(SOME_LINES).iterator())); String rawSourceHash = mockedUnderTest.getRawSourceHash(FILE_COMPONENT); String rawSourceHash1 = mockedUnderTest.getRawSourceHash(FILE_COMPONENT); assertThat(rawSourceHash).isSameAs(rawSourceHash1); verify(mockedSourceLinesRepository, times(1)).readLines(FILE_COMPONENT); }
@Test(expected = IllegalArgumentException.class) public void from_iterator_throws_IAE_if_arg_is_a_AutoCloseable() { CloseableIterator.from(new CloseableIt()); }
@Test(expected = IllegalArgumentException.class) public void from_iterator_throws_IAE_if_arg_is_a_CloseableIterator() { CloseableIterator.from(new SimpleCloseableIterator()); }
private void insertCeScannerContext(String uuid) { dbClient.ceScannerContextDao().insert(dbSession, uuid, CloseableIterator.from(Arrays.asList("a", "b", "c").iterator())); dbSession.commit(); }
private void insertScannerContext(String taskUuid) { db.getDbClient().ceScannerContextDao().insert(dbSession, taskUuid, CloseableIterator.from(singletonList("scanner context of " + taskUuid).iterator())); dbSession.commit(); }
@Test public void constructor_throws_IAE_when_ClosableIterator_has_already_been_read() { CloseableIterator<String> iterator = CloseableIterator.from(Arrays.asList("line1").iterator()); // read iterator to the end iterator.next(); expectedException.expect(IllegalArgumentException.class); expectedException.expectMessage("LogsIterator can't be empty or already read"); new LogsIteratorInputStream(iterator, UTF_8); }
@Test public void persist_filtering_of_properties_is_case_sensitive() { when(analysisMetadataHolder.getScmRevisionId()).thenReturn(Optional.of(SCM_REV_ID)); when(batchReportReader.readContextProperties()).thenReturn(CloseableIterator.from(ImmutableList.of( newContextProperty("sonar.ANALYSIS.foo", "foo"), newContextProperty("sonar.anaLysis.bar", "bar"), newContextProperty("sonar.anaLYSIS.doo", "doh"), newContextProperty("sonar.PULLREQUEST.foo", "foo"), newContextProperty("sonar.pullRequest.bar", "bar"), newContextProperty("sonar.pullREQUEST.doo", "doh")).iterator())); when(analysisMetadataHolder.getUuid()).thenReturn(SNAPSHOT_UUID); underTest.execute(new TestComputationStepContext()); assertThat(dbTester.countRowsOfTable("analysis_properties")).isEqualTo(1); }
private void persistScannerContext(String taskUuid, String scannerContext) { db.getDbClient().ceScannerContextDao().insert(db.getSession(), taskUuid, CloseableIterator.from(singleton(scannerContext).iterator())); db.commit(); }
/** * SONAR-8306 */ @Test public void execute_does_not_fail_if_scanner_context_has_already_been_persisted() { dbClient.ceScannerContextDao().insert(dbTester.getSession(), ANALYSIS_UUID, CloseableIterator.from(Arrays.asList("a", "b", "c").iterator())); dbTester.commit(); reportReader.setScannerLogs(asList("1", "2", "3")); when(ceTask.getUuid()).thenReturn(ANALYSIS_UUID); underTest.execute(new TestComputationStepContext()); assertThat(dbClient.ceScannerContextDao().selectScannerContext(dbTester.getSession(), ANALYSIS_UUID)) .contains("1" + '\n' + "2" + '\n' + "3"); } }