*/
Component getComponentByRef(int ref);
+ /**
+ * Number of components, including root.
+ *
+ * @throws IllegalStateException if the holder is empty (ie. there is no root yet)
+ */
+ int getSize();
}
return component;
}
+ @Override
+ public int getSize() {
+ checkInitialized();
+ ensureComponentByRefIsPopulated();
+ return componentsByRef.size();
+ }
+
private void ensureComponentByRefIsPopulated() {
if (componentsByRef != null) {
return;
import javax.annotation.CheckForNull;
import javax.annotation.Nullable;
+import org.sonar.api.utils.log.Loggers;
import org.sonar.db.DbClient;
import org.sonar.db.DbSession;
import org.sonar.db.component.SnapshotDto;
treeRootHolder.setRoot(project);
analysisMetadataHolder.setBaseAnalysis(toAnalysis(baseAnalysis));
+
+ Loggers.get(getClass()).debug("components={}", treeRootHolder.getSize());
}
}
assertThat(underTest.getRoot()).isSameAs(DUMB_PROJECT);
}
+ @Test
+ public void getSize_throws_ISE_if_not_initialized() {
+ expectNotInitialized_ISE();
+
+ underTest.getSize();
+ }
+
+ @Test
+ public void getSize_counts_number_of_components() {
+ underTest.setRoot(SOME_REPORT_COMPONENT_TREE);
+ assertThat(underTest.getSize()).isEqualTo(4);
+ }
+
private void expectNotInitialized_ISE() {
expectedException.expect(IllegalStateException.class);
expectedException.expectMessage("Holder has not been initialized yet");
public Component getComponentByRef(int ref) {
return delegate.getComponentByRef(ref);
}
+
+ @Override
+ public int getSize() {
+ return delegate.getSize();
+ }
}