}
public boolean shouldDecorateResource(Resource resource, DecoratorContext context) {
- return context.getMeasure(CoreMetrics.TESTS) == null && (ResourceUtils.isUnitTestClass(resource) || !ResourceUtils.isEntity(resource));
+ return ResourceUtils.isUnitTestClass(resource) || !ResourceUtils.isEntity(resource);
}
public void decorate(Resource resource, DecoratorContext context) {
package org.sonar.plugins.core.sensors;
import org.junit.Before;
+import org.junit.Ignore;
import org.junit.Test;
import org.sonar.api.batch.DecoratorContext;
import org.sonar.api.measures.CoreMetrics;
import static org.hamcrest.Matchers.closeTo;
import static org.mockito.Matchers.doubleThat;
import static org.mockito.Matchers.eq;
-import static org.mockito.Mockito.*;
+import static org.mockito.Mockito.atLeastOnce;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.verifyNoMoreInteractions;
+import static org.mockito.Mockito.when;
public class UnitTestDecoratorTest {
}
@Test
+ @Ignore("Hack for SONAR-5212")
public void doNotDecorateIfTestsMeasureAlreadyExists() {
Project project = mock(Project.class);
when(context.getMeasure(CoreMetrics.TESTS)).thenReturn(new Measure());
import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.ListMultimap;
import com.google.common.collect.Lists;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.MeasuresFilter;
import org.sonar.api.measures.MeasuresFilters;
if (index > -1) {
if (metricMeasures.get(index) == measure) {
add = false;
+ } else if (measure.getMetric().equals(CoreMetrics.TESTS)) {
+ // Hack for SONAR-5212
+ measuresByMetric.remove(measure.getMetric().getKey(), metricMeasures.get(index));
} else {
throw new SonarException("Can not add twice the same measure on " + resource + ": " + measure);
}
import org.sonar.api.database.model.MeasureMapper;
import org.sonar.api.database.model.MeasureModel;
import org.sonar.api.database.model.Snapshot;
+import org.sonar.api.measures.CoreMetrics;
import org.sonar.api.measures.Measure;
import org.sonar.api.measures.RuleMeasure;
import org.sonar.api.resources.Resource;
public void saveMeasure(Resource resource, Measure measure) {
if (shouldSaveLater(measure)) {
+ if (measure.getMetric().equals(CoreMetrics.TESTS) && unsavedMeasuresByResource.get(resource).contains(measure)) {
+ // Hack for SONAR-5212
+ unsavedMeasuresByResource.remove(resource, measure);
+ }
unsavedMeasuresByResource.put(resource, measure);
return;
}