import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
-import java.util.Collections;
import java.util.List;
import static com.google.common.collect.Lists.newArrayList;
if (source != null) {
return splitSourceByLine(source, component.getLanguage(), from, to);
} else {
- return Collections.emptyList();
+ return null;
}
} finally {
MyBatis.closeQuietly(session);
import javax.annotation.Nullable;
import java.util.Collection;
-import java.util.Collections;
import java.util.List;
public class HtmlSourceDecorator implements ServerComponent {
this.snapshotDataDao = snapshotDataDao;
}
+ @CheckForNull
public List<String> getDecoratedSourceAsHtml(String componentKey, @Nullable Integer from, @Nullable Integer to) {
SqlSession session = mybatis.openSession(false);
try {
String snapshotSource = snapshotSourceDao.selectSnapshotSourceByComponentKey(componentKey, session);
return decorate(snapshotSource, snapshotDataEntries, from, to);
}
- return Collections.emptyList();
+ return null;
} finally {
MyBatis.closeQuietly(session);
}
this.deprecatedSourceDecorator = deprecatedSourceDecorator;
}
+ @CheckForNull
public List<String> getLinesAsHtml(String fileKey) {
return getLinesAsHtml(fileKey, null, null);
}
+ @CheckForNull
public List<String> getLinesAsHtml(String fileKey, @Nullable Integer from, @Nullable Integer to) {
checkPermission(fileKey);
List<String> decoratedSource = sourceDecorator.getDecoratedSourceAsHtml(fileKey, from, to);
- if (!decoratedSource.isEmpty()) {
+ if (decoratedSource != null) {
return decoratedSource;
}
return deprecatedSourceDecorator.getSourceAsHtml(fileKey, from, to);
int to = (Integer) ObjectUtils.defaultIfNull(request.paramAsInt("to"), Integer.MAX_VALUE);
List<String> sourceHtml = sourceService.getLinesAsHtml(fileKey, from, to);
- if (sourceHtml.isEmpty()) {
+ if (sourceHtml == null) {
throw new NotFoundException("File '" + fileKey + "' has no sources");
}
}
@Test
- public void return_empty_list_if_no_source_code_on_component() throws Exception {
+ public void return_null_if_no_source_code_on_component() throws Exception {
String componentKey = "org.sonar.sample:Sample";
when(resourceDao.getResource(any(ResourceQuery.class), eq(session))).thenReturn(new ResourceDto().setKey(componentKey).setLanguage("java"));
when(snapshotSourceDao.selectSnapshotSourceByComponentKey(componentKey, session)).thenReturn(null);
- assertThat(sourceDecorator.getSourceAsHtml(componentKey)).isEmpty();
+ assertThat(sourceDecorator.getSourceAsHtml(componentKey)).isNull();
}
@Test
import org.sonar.server.measure.persistence.MeasureDao;
import org.sonar.server.user.MockUserSession;
-import java.util.Collections;
-
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
import static org.mockito.Mockito.*;
@Test
public void get_lines_from_deprecated_source_decorator_when_no_data_from_new_decorator() throws Exception {
MockUserSession.set().addComponentPermission(UserRole.CODEVIEWER, PROJECT_KEY, COMPONENT_KEY);
- when(sourceDecorator.getDecoratedSourceAsHtml(eq(COMPONENT_KEY), anyInt(), anyInt())).thenReturn(Collections.<String>emptyList());
+ when(sourceDecorator.getDecoratedSourceAsHtml(eq(COMPONENT_KEY), anyInt(), anyInt())).thenReturn(null);
service.getLinesAsHtml(COMPONENT_KEY, 1, 2);
import org.sonar.server.source.SourceService;
import org.sonar.server.ws.WsTester;
-import java.util.Collections;
-
import static com.google.common.collect.Lists.newArrayList;
import static org.fest.assertions.Assertions.assertThat;
import static org.fest.assertions.Fail.fail;
@Test
public void fail_to_show_source_if_no_source_found() throws Exception {
String componentKey = "src/Foo.java";
- when(sourceService.getLinesAsHtml(anyString(), anyInt(), anyInt())).thenReturn(Collections.<String>emptyList());
+ when(sourceService.getLinesAsHtml(anyString(), anyInt(), anyInt())).thenReturn(null);
try {
WsTester.TestRequest request = tester.newGetRequest("api/sources", "show").setParam("key", componentKey);