}
private void addToCache(Resource resource, Snapshot snapshot) {
- if (snapshot != null && !ResourceUtils.isLibrary(resource)) {
+ if (snapshot != null) {
snapshotsByResource.put(resource, snapshot);
resourceCache.add(resource);
snapshotCache.put(resource.getEffectiveKey(), snapshot);
*/
package org.sonar.batch.index;
-import com.google.common.base.Preconditions;
import com.google.common.collect.Maps;
import org.sonar.api.BatchComponent;
import org.sonar.api.database.model.Snapshot;
}
public SnapshotCache put(String componentKey, Snapshot snapshot) {
- Preconditions.checkState(!snapshots.containsKey(componentKey), "Component is already registered: " + componentKey);
snapshots.put(componentKey, snapshot);
return this;
}
import org.sonar.api.database.model.Snapshot;
import static org.fest.assertions.Assertions.assertThat;
-import static org.fest.assertions.Fail.fail;
import static org.mockito.Mockito.mock;
public class SnapshotCacheTest {
assertThat(cache.get(componentKey)).isSameAs(snapshot);
assertThat(cache.get("other")).isNull();
}
-
- @Test
- public void should_fail_if_put_twice() throws Exception {
- SnapshotCache cache = new SnapshotCache();
- String componentKey = "org.apache.struts:struts-core";
- cache.put(componentKey, snapshot);
- try {
- cache.put(componentKey, mock(Snapshot.class));
- fail();
- } catch (IllegalStateException e) {
- // success
- assertThat(e).hasMessage("Component is already registered: org.apache.struts:struts-core");
- }
- }
}