@@ -60,8 +60,7 @@ public class AnalysisImplTest { | |||
assertThat(new Analysis.Builder() | |||
.setUuid(UUID) | |||
.setCreatedAt(CREATED_AT) | |||
.build().toString()) | |||
.isEqualTo("Analysis{uuid='uuid ', createdAt=123456789}"); | |||
.build()).hasToString("Analysis{uuid='uuid ', createdAt=123456789}"); | |||
} | |||
@Test |
@@ -27,7 +27,6 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class MeasureComputerDefinitionImplTest { | |||
@Test | |||
public void build_measure_computer_definition() { | |||
String inputMetric = "ncloc"; | |||
@@ -156,16 +155,14 @@ public class MeasureComputerDefinitionImplTest { | |||
.setOutputMetrics("debt") | |||
.build(); | |||
assertThat(computer).isEqualTo(computer) | |||
assertThat(computer) | |||
.isEqualTo(computer) | |||
.isEqualTo(sameComputer) | |||
.isNotEqualTo(anotherComputer) | |||
.isNotNull(); | |||
assertThat(computer) | |||
.isNotNull() | |||
.hasSameHashCodeAs(computer) | |||
.hasSameHashCodeAs(sameComputer); | |||
assertThat(computer.hashCode()).isNotEqualTo(anotherComputer.hashCode()); | |||
.hasSameHashCodeAs(sameComputer) | |||
.doesNotHaveSameHashCodeAs(anotherComputer.hashCode()); | |||
} | |||
@Test | |||
@@ -173,8 +170,8 @@ public class MeasureComputerDefinitionImplTest { | |||
assertThat(new MeasureComputerDefinitionImpl.BuilderImpl() | |||
.setInputMetrics("ncloc", "comment") | |||
.setOutputMetrics("comment_density_1", "comment_density_2") | |||
.build().toString()) | |||
.isEqualTo("MeasureComputerDefinitionImpl{inputMetricKeys=[ncloc, comment], outputMetrics=[comment_density_1, comment_density_2]}"); | |||
.build()) | |||
.hasToString("MeasureComputerDefinitionImpl{inputMetricKeys=[ncloc, comment], outputMetrics=[comment_density_1, comment_density_2]}"); | |||
} | |||
} |
@@ -144,10 +144,11 @@ public class DuplicationTest { | |||
public void equals_compares_on_original_and_duplicates() { | |||
Duplication duplication = new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1))); | |||
assertThat(duplication).isEqualTo(duplication); | |||
assertThat(duplication).isEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1)))); | |||
assertThat(duplication).isNotEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_2)))); | |||
assertThat(duplication).isNotEqualTo(new Duplication(TEXT_BLOCK_1, Arrays.asList(new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK)))); | |||
assertThat(duplication) | |||
.isEqualTo(duplication) | |||
.isEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1)))) | |||
.isNotEqualTo(new Duplication(SOME_ORIGINAL_TEXTBLOCK, Arrays.asList(new InnerDuplicate(TEXT_BLOCK_2)))) | |||
.isNotEqualTo(new Duplication(TEXT_BLOCK_1, Arrays.asList(new InnerDuplicate(SOME_ORIGINAL_TEXTBLOCK)))); | |||
} | |||
@Test | |||
@@ -165,8 +166,8 @@ public class DuplicationTest { | |||
SOME_ORIGINAL_TEXTBLOCK, | |||
Arrays.asList(new InnerDuplicate(TEXT_BLOCK_1))); | |||
assertThat(duplication.toString()) | |||
.isEqualTo("Duplication{original=TextBlock{start=1, end=2}, duplicates=[InnerDuplicate{textBlock=TextBlock{start=2, end=2}}]}"); | |||
assertThat(duplication) | |||
.hasToString("Duplication{original=TextBlock{start=1, end=2}, duplicates=[InnerDuplicate{textBlock=TextBlock{start=2, end=2}}]}"); | |||
} | |||
@SafeVarargs |
@@ -85,8 +85,8 @@ public class InProjectDuplicateTest { | |||
@Test | |||
public void verify_toString() { | |||
assertThat(new InProjectDuplicate(FILE_1, new TextBlock(1, 2)).toString()) | |||
.isEqualTo("InProjectDuplicate{file=ReportComponent{ref=1, key='key_1', type=FILE}, textBlock=TextBlock{start=1, end=2}}"); | |||
assertThat(new InProjectDuplicate(FILE_1, new TextBlock(1, 2))) | |||
.hasToString("InProjectDuplicate{file=ReportComponent{ref=1, key='key_1', type=FILE}, textBlock=TextBlock{start=1, end=2}}"); | |||
} | |||
} |
@@ -48,7 +48,7 @@ public class IntSumCounterTest { | |||
sumCounter.initialize(counterInitializationContext); | |||
assertThat(sumCounter.getValue().get()).isEqualTo(10); | |||
assertThat(sumCounter.getValue()).contains(10); | |||
} | |||
@Test | |||
@@ -68,7 +68,7 @@ public class IntSumCounterTest { | |||
sumCounter.aggregate(anotherCounter); | |||
assertThat(sumCounter.getValue().get()).isEqualTo(10); | |||
assertThat(sumCounter.getValue()).contains(10); | |||
} | |||
@Test |
@@ -49,7 +49,7 @@ public class LongSumCounterTest { | |||
sumCounter.initialize(counterInitializationContext); | |||
assertThat(sumCounter.getValue().get()).isEqualTo(MEASURE_VALUE); | |||
assertThat(sumCounter.getValue()).contains(MEASURE_VALUE); | |||
} | |||
@Test | |||
@@ -69,7 +69,7 @@ public class LongSumCounterTest { | |||
sumCounter.aggregate(anotherCounter); | |||
assertThat(sumCounter.getValue().get()).isEqualTo(MEASURE_VALUE); | |||
assertThat(sumCounter.getValue()).contains(MEASURE_VALUE); | |||
} | |||
@Test |
@@ -47,8 +47,9 @@ public class LanguageRepositoryImplTest { | |||
public void find_by_key_returns_the_same_object() { | |||
LanguageRepositoryImpl languageRepository = new LanguageRepositoryImpl(SOME_LANGUAGE); | |||
Optional<Language> language = languageRepository.find(SOME_LANGUAGE_KEY); | |||
assertThat(language).isPresent(); | |||
assertThat(language.get()).isSameAs(SOME_LANGUAGE); | |||
assertThat(language) | |||
.isPresent() | |||
.containsSame(SOME_LANGUAGE); | |||
} | |||
@Test |
@@ -212,7 +212,7 @@ public class MapBasedRawMeasureRepositoryTest { | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
underTest.update(FILE_COMPONENT, metric1, newMeasure); | |||
assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1).get()).isSameAs(newMeasure); | |||
assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1)).containsSame(newMeasure); | |||
} | |||
@Test | |||
@@ -241,8 +241,9 @@ public class MapBasedRawMeasureRepositoryTest { | |||
Optional<Measure> res = underTest.getRawMeasure(FILE_COMPONENT, metric1); | |||
assertThat(res).isPresent(); | |||
assertThat(res.get()).isSameAs(SOME_MEASURE); | |||
assertThat(res) | |||
.isPresent() | |||
.containsSame(SOME_MEASURE); | |||
// make sure we really match on the specified component and metric | |||
assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isNotPresent(); |
@@ -32,7 +32,7 @@ public class MeasureLevelTest { | |||
@Test | |||
public void verify_toLevel_supports_all_Level_values() { | |||
for (Measure.Level level : Measure.Level.values()) { | |||
assertThat(Measure.Level.toLevel(level.name()).get()).isEqualTo(level); | |||
assertThat(Measure.Level.toLevel(level.name())).contains(level); | |||
} | |||
} | |||
@@ -283,7 +283,7 @@ public class MeasureRepositoryImplTest { | |||
underTest.add(FILE_COMPONENT, metric1, SOME_MEASURE); | |||
underTest.update(FILE_COMPONENT, metric1, newMeasure); | |||
assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1).get()).isSameAs(newMeasure); | |||
assertThat(underTest.getRawMeasure(FILE_COMPONENT, metric1)).containsSame(newMeasure); | |||
} | |||
@Test | |||
@@ -312,8 +312,9 @@ public class MeasureRepositoryImplTest { | |||
Optional<Measure> res = underTest.getRawMeasure(FILE_COMPONENT, metric1); | |||
assertThat(res).isPresent(); | |||
assertThat(res.get()).isSameAs(SOME_MEASURE); | |||
assertThat(res) | |||
.isPresent() | |||
.containsSame(SOME_MEASURE); | |||
// make sure we really match on the specified component and metric | |||
assertThat(underTest.getRawMeasure(OTHER_COMPONENT, metric1)).isNotPresent(); | |||
@@ -363,8 +364,9 @@ public class MeasureRepositoryImplTest { | |||
Optional<Measure> res = underTest.getRawMeasure(FILE_COMPONENT, metric1); | |||
assertThat(res).isPresent(); | |||
assertThat(res.get()).isSameAs(addedMeasure); | |||
assertThat(res) | |||
.isPresent() | |||
.containsSame(addedMeasure); | |||
} | |||
@Test |
@@ -57,7 +57,7 @@ public class ReportAnalysisFailureNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(ReportAnalysisFailureNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(ReportAnalysisFailureNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -41,8 +41,8 @@ public class PeriodTest { | |||
@Test | |||
public void verify_to_string() { | |||
assertThat(new Period(NewCodePeriodType.PREVIOUS_VERSION.name(), "2.3", 1420034400000L).toString()) | |||
.isEqualTo("Period{mode=PREVIOUS_VERSION, modeParameter=2.3, date=1420034400000}"); | |||
assertThat(new Period(NewCodePeriodType.PREVIOUS_VERSION.name(), "2.3", 1420034400000L)) | |||
.hasToString("Period{mode=PREVIOUS_VERSION, modeParameter=2.3, date=1420034400000}"); | |||
} | |||
@Test |
@@ -73,8 +73,8 @@ public class ConditionTest { | |||
public void all_fields_are_displayed_in_toString() { | |||
when(SOME_METRIC.toString()).thenReturn("metric1"); | |||
assertThat(new Condition(SOME_METRIC, SOME_OPERATOR, "error_l").toString()) | |||
.isEqualTo("Condition{metric=metric1, operator=LESS_THAN, errorThreshold=error_l}"); | |||
assertThat(new Condition(SOME_METRIC, SOME_OPERATOR, "error_l")) | |||
.hasToString("Condition{metric=metric1, operator=LESS_THAN, errorThreshold=error_l}"); | |||
} | |||
@@ -44,7 +44,7 @@ public class EvaluationResultTest { | |||
@Test | |||
public void toString_is_defined() { | |||
assertThat(new EvaluationResult(Measure.Level.OK, "toto").toString()) | |||
.isEqualTo("EvaluationResult{level=OK, value=toto}"); | |||
assertThat(new EvaluationResult(Measure.Level.OK, "toto")) | |||
.hasToString("EvaluationResult{level=OK, value=toto}"); | |||
} | |||
} |
@@ -60,7 +60,7 @@ public class QualityGateHolderImplTest { | |||
holder.setQualityGate(QUALITY_GATE); | |||
assertThat(holder.getQualityGate().get()).isSameAs(QUALITY_GATE); | |||
assertThat(holder.getQualityGate()).containsSame(QUALITY_GATE); | |||
} | |||
@Test | |||
@@ -94,7 +94,7 @@ public class QualityGateHolderImplTest { | |||
EvaluatedQualityGate evaluation = mock(EvaluatedQualityGate.class); | |||
holder.setEvaluation(evaluation); | |||
assertThat(holder.getEvaluation().get()).isSameAs(evaluation); | |||
assertThat(holder.getEvaluation()).containsSame(evaluation); | |||
} | |||
} |
@@ -50,6 +50,6 @@ public class PublishTaskResultStepTest { | |||
underTest.execute(new TestComputationStepContext()); | |||
assertThat(taskResultHolder.getResult().getAnalysisUuid().get()).isEqualTo(AN_ANALYSIS_UUID); | |||
assertThat(taskResultHolder.getResult().getAnalysisUuid()).contains(AN_ANALYSIS_UUID); | |||
} | |||
} |
@@ -624,8 +624,9 @@ public class SendIssueNotificationsStepTest extends BaseStepTest { | |||
assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(0)).hasSize(1000); | |||
assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(1)).hasSize(1000); | |||
assertThat(newIssuesFactoryCaptor.issuesSetCaptor.get(2)).hasSize(issues.size() - 2000); | |||
assertThat(newIssuesFactoryCaptor.assigneeCacheCaptor).hasSize(3); | |||
assertThat(newIssuesFactoryCaptor.assigneeCacheCaptor).containsOnly(newIssuesFactoryCaptor.assigneeCacheCaptor.iterator().next()); | |||
assertThat(newIssuesFactoryCaptor.assigneeCacheCaptor) | |||
.hasSize(3) | |||
.containsOnly(newIssuesFactoryCaptor.assigneeCacheCaptor.iterator().next()); | |||
ArgumentCaptor<Collection> collectionCaptor = forClass(Collection.class); | |||
verify(notificationService, times(3)).deliverEmails(collectionCaptor.capture()); | |||
assertThat(collectionCaptor.getAllValues()).hasSize(3); |
@@ -123,9 +123,10 @@ public class CeTasksMBeanImplTest { | |||
public void getWorkerUuids_returns_ordered_list_of_uuids_of_worker_from_CeWorkerFactory_instance() { | |||
List<String> workerUuids = underTest.getWorkerUuids(); | |||
assertThat(workerUuids).isEqualTo(WORKERS.stream().map(CeWorker::getUUID).sorted().collect(Collectors.toList())); | |||
// ImmutableSet can not be serialized | |||
assertThat(workerUuids).isNotInstanceOf(ImmutableSet.class); | |||
assertThat(workerUuids). | |||
isEqualTo(WORKERS.stream().map(CeWorker::getUUID).sorted().collect(Collectors.toList())) | |||
// ImmutableSet can not be serialized | |||
.isNotInstanceOf(ImmutableSet.class); | |||
} | |||
@Test | |||
@@ -145,9 +146,10 @@ public class CeTasksMBeanImplTest { | |||
List<String> enabledWorkerUuids = underTest.getEnabledWorkerUuids(); | |||
assertThat(enabledWorkerUuids).isEqualTo(Stream.of(enabledWorkers).map(CeWorker::getUUID).sorted().collect(Collectors.toList())); | |||
// ImmutableSet can not be serialized | |||
assertThat(enabledWorkerUuids).isNotInstanceOf(ImmutableSet.class); | |||
assertThat(enabledWorkerUuids) | |||
.isEqualTo(Stream.of(enabledWorkers).map(CeWorker::getUUID).sorted().collect(Collectors.toList())) | |||
// ImmutableSet can not be serialized | |||
.isNotInstanceOf(ImmutableSet.class); | |||
} | |||
@Test |
@@ -87,8 +87,8 @@ public class CeTaskProcessorRepositoryImplTest { | |||
CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE); | |||
CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] {taskProcessor}); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY + "2")).get()).isSameAs(taskProcessor); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).containsSame(taskProcessor); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY + "2"))).containsSame(taskProcessor); | |||
} | |||
@Test | |||
@@ -96,7 +96,7 @@ public class CeTaskProcessorRepositoryImplTest { | |||
CeTaskProcessor taskProcessor = createCeTaskProcessor(SOME_CE_TASK_TYPE + "_1", SOME_CE_TASK_TYPE, SOME_CE_TASK_TYPE + "_3"); | |||
CeTaskProcessorRepositoryImpl underTest = new CeTaskProcessorRepositoryImpl(new CeTaskProcessor[] {taskProcessor}); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY)).get()).isSameAs(taskProcessor); | |||
assertThat(underTest.getForCeTask(createCeTask(SOME_CE_TASK_TYPE, SOME_COMPONENT_KEY))).containsSame(taskProcessor); | |||
} | |||
private CeTaskProcessor createCeTaskProcessor(final String... ceTaskTypes) { |
@@ -34,6 +34,6 @@ public class ComponentKeyNewValueTest { | |||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString()); | |||
assertThat(jsonObject.size()).isEqualTo(3); | |||
assertThat(jsonObject).hasSize(3); | |||
} | |||
} |
@@ -34,7 +34,7 @@ public class ComponentNewValueTest { | |||
JSONObject jsonObject = (JSONObject) new JSONParser().parse(newValue.toString()); | |||
assertThat(jsonObject.size()).isEqualTo(5); | |||
assertThat(jsonObject).hasSize(5); | |||
} | |||
@Test |
@@ -44,9 +44,10 @@ public class CeTaskDtoLightTest { | |||
@Test | |||
public void equals_is_based_on_created_date_and_uuid() { | |||
assertThat(task1).isEqualTo(task2); | |||
assertThat(task1).isNotEqualTo(task3); | |||
assertThat(task1).isNotEqualTo(task4); | |||
assertThat(task1) | |||
.isEqualTo(task2) | |||
.isNotEqualTo(task3) | |||
.isNotEqualTo(task4); | |||
} | |||
@Test | |||
@@ -56,8 +57,9 @@ public class CeTaskDtoLightTest { | |||
@Test | |||
public void compareTo_is_based_on_created_date_and_uuid() { | |||
assertThat(task1).isEqualByComparingTo(task2); | |||
assertThat(task1).isLessThan(task3); | |||
assertThat(task1).isLessThan(task4); | |||
assertThat(task1) | |||
.isEqualByComparingTo(task2) | |||
.isLessThan(task3) | |||
.isLessThan(task4); | |||
} | |||
} |
@@ -27,14 +27,13 @@ import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
public class AnalysisPropertyDtoTest { | |||
private AnalysisPropertyDto underTest; | |||
@Test | |||
public void null_key_should_throw_NPE() { | |||
underTest = new AnalysisPropertyDto(); | |||
assertThatThrownBy(() -> underTest.setKey(null)) | |||
assertThatThrownBy(() -> underTest.setKey(null)) | |||
.isInstanceOf(NullPointerException.class) | |||
.hasMessage("key cannot be null"); | |||
} | |||
@@ -74,40 +73,37 @@ public class AnalysisPropertyDtoTest { | |||
.setKey(randomAlphanumeric(512)) | |||
.setValue(randomAlphanumeric(10000)); | |||
assertThat(underTest).isEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())); | |||
assertThat(underTest).isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid("1" + underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())); | |||
assertThat(underTest).isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid("1" + underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())); | |||
assertThat(underTest).isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey("1" + underTest.getKey()) | |||
.setValue(underTest.getValue())); | |||
assertThat(underTest).isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue("1" + underTest.getValue())); | |||
assertThat(underTest) | |||
.isEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())) | |||
.isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid("1" + underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())) | |||
.isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid("1" + underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue(underTest.getValue())) | |||
.isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey("1" + underTest.getKey()) | |||
.setValue(underTest.getValue())) | |||
.isNotEqualTo( | |||
new AnalysisPropertyDto() | |||
.setUuid(underTest.getUuid()) | |||
.setAnalysisUuid(underTest.getAnalysisUuid()) | |||
.setKey(underTest.getKey()) | |||
.setValue("1" + underTest.getValue())); | |||
} | |||
@Test |
@@ -57,7 +57,7 @@ public class IntervalTest { | |||
); | |||
List<Interval> intervals = Interval.group(snapshots, DateUtils.parseDate("2010-01-01"), DateUtils.parseDate("2011-12-31"), Calendar.MONTH); | |||
assertThat(intervals.size()).isEqualTo(3); | |||
assertThat(intervals).hasSize(3); | |||
assertThat(intervals.get(0).count()).isOne(); | |||
assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL)); | |||
@@ -78,7 +78,7 @@ public class IntervalTest { | |||
List<Interval> intervals = Interval.group(snapshots, | |||
DateUtils.parseDateTime("2010-01-01T00:00:00+0100"), DateUtils.parseDateTime("2011-12-31T00:00:00+0100"), Calendar.MONTH); | |||
assertThat(intervals.size()).isEqualTo(2); | |||
assertThat(intervals).hasSize(2); | |||
assertThat(intervals.get(0).count()).isOne(); | |||
assertThat(calendarField(intervals.get(0), Calendar.MONTH)).isEqualTo((Calendar.APRIL)); |
@@ -35,7 +35,7 @@ public class ActiveRuleKeyTest { | |||
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey); | |||
assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); | |||
assertThat(key.getRuleKey()).isSameAs(ruleKey); | |||
assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":xoo:R1"); | |||
assertThat(key).hasToString(profile.getRulesProfileUuid() + ":xoo:R1"); | |||
} | |||
@Test | |||
@@ -45,7 +45,7 @@ public class ActiveRuleKeyTest { | |||
ActiveRuleKey key = ActiveRuleKey.of(profile, ruleKey); | |||
assertThat(key.getRuleProfileUuid()).isEqualTo(profile.getRulesProfileUuid()); | |||
assertThat(key.getRuleKey()).isSameAs(ruleKey); | |||
assertThat(key.toString()).isEqualTo(profile.getRulesProfileUuid() + ":java:Key:With:Some::Colons"); | |||
assertThat(key).hasToString(profile.getRulesProfileUuid() + ":java:Key:With:Some::Colons"); | |||
} | |||
@Test |
@@ -85,8 +85,9 @@ public class QualityProfileExportDaoTest { | |||
List<ActiveRuleDto> activeRules = activate(profile, customRule, rule); | |||
List<ExportRuleDto> results = underTest.selectRulesByProfile(dbSession, profile); | |||
assertThat(results).isNotNull(); | |||
assertThat(results).isNotEmpty(); | |||
assertThat(results) | |||
.isNotNull() | |||
.isNotEmpty(); | |||
// verify custom rule | |||
ExportRuleDto exportCustomRuleDto = results.stream().filter(ExportRuleDto::isCustomRule).findFirst().get(); |
@@ -338,7 +338,7 @@ public class JvmOptionsTest { | |||
public void toString_prints_all_jvm_options() { | |||
underTest.add("-foo").add("-bar"); | |||
assertThat(underTest.toString()).isEqualTo("[-foo, -bar]"); | |||
assertThat(underTest).hasToString("[-foo, -bar]"); | |||
} | |||
private void expectJvmOptionNotNullNPE(ThrowingCallable callback) { |
@@ -38,8 +38,8 @@ public class AppSettingsImplTest { | |||
AppSettingsImpl underTest = new AppSettingsImpl(initialProps); | |||
underTest.reload(newProps); | |||
assertThat(underTest.getValue("foo").get()).isEqualTo("baz"); | |||
assertThat(underTest.getValue("newProp").get()).isEqualTo("newVal"); | |||
assertThat(underTest.getValue("foo")).contains("baz"); | |||
assertThat(underTest.getValue("newProp")).contains("newVal"); | |||
assertThat(underTest.getProps().rawProperties()).hasSize(2); | |||
} | |||
} |
@@ -39,14 +39,15 @@ public class EsYmlSettingsTest { | |||
File yamlFile = temp.newFile(); | |||
new EsYmlSettings(new HashMap<>()).writeToYmlSettingsFile(yamlFile); | |||
assertThat(yamlFile).exists(); | |||
assertThat(yamlFile).hasContent(""" | |||
# This file has been automatically generated by SonarQube during startup. | |||
assertThat(yamlFile) | |||
.exists() | |||
.hasContent(""" | |||
# This file has been automatically generated by SonarQube during startup. | |||
# DO NOT EDIT THIS FILE | |||
# DO NOT EDIT THIS FILE | |||
{ | |||
}"""); | |||
{ | |||
}"""); | |||
} | |||
@Test |
@@ -23,6 +23,7 @@ import java.util.Calendar; | |||
import java.util.Date; | |||
import java.util.List; | |||
import java.util.Random; | |||
import java.util.function.Predicate; | |||
import org.apache.commons.lang.time.DateUtils; | |||
import org.junit.Test; | |||
import org.sonar.api.utils.Duration; |
@@ -81,7 +81,7 @@ public class ChangesOnMyIssueNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(ChangesOnMyIssueNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(ChangesOnMyIssueNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -81,7 +81,7 @@ public class FPOrWontFixNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(FPOrWontFixNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(FPOrWontFixNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -57,7 +57,7 @@ public class MyNewIssuesNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(MyNewIssuesNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(MyNewIssuesNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -55,7 +55,7 @@ public class NewIssuesNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(NewIssuesNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(NewIssuesNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -138,7 +138,7 @@ public class TransitionTest { | |||
@Test | |||
public void test_toString() { | |||
Transition t1 = Transition.create("resolve", "OPEN", "RESOLVED"); | |||
assertThat(t1.toString()).isEqualTo("OPEN->resolve->RESOLVED"); | |||
assertThat(t1).hasToString("OPEN->resolve->RESOLVED"); | |||
} | |||
@Test |
@@ -31,7 +31,7 @@ public class UnanalyzedLanguageMetricsTest { | |||
public void count_metrics() { | |||
UnanalyzedLanguageMetrics coreCustomMetrics = new UnanalyzedLanguageMetrics(); | |||
List<Metric> metrics = coreCustomMetrics.getMetrics(); | |||
assertThat(metrics.size()).isEqualTo(2); | |||
assertThat(metrics).hasSize(2); | |||
} | |||
} |
@@ -82,6 +82,6 @@ public class EmailRecipientTest { | |||
String login = randomAlphabetic(11); | |||
String email = randomAlphabetic(12); | |||
assertThat(new EmailRecipient(login, email).toString()).isEqualTo("EmailRecipient{'" + login + "':'" + email + "'}"); | |||
assertThat(new EmailRecipient(login, email)).hasToString("EmailRecipient{'" + login + "':'" + email + "'}"); | |||
} | |||
} |
@@ -64,7 +64,7 @@ public class EvaluatedConditionTest { | |||
@Test | |||
public void override_toString() { | |||
assertThat(underTest.toString()).isEqualTo("EvaluatedCondition{condition=" + | |||
assertThat(underTest).hasToString("EvaluatedCondition{condition=" + | |||
"Condition{metricKey='metricKey', operator=GREATER_THAN, errorThreshold='2'}, " + | |||
"status=ERROR, value='value'}"); | |||
} | |||
@@ -73,7 +73,7 @@ public class EvaluatedConditionTest { | |||
public void toString_does_not_quote_null_value() { | |||
EvaluatedCondition underTest = new EvaluatedCondition(CONDITION_1, ERROR, null); | |||
assertThat(underTest.toString()).isEqualTo("EvaluatedCondition{condition=" + | |||
assertThat(underTest).hasToString("EvaluatedCondition{condition=" + | |||
"Condition{metricKey='metricKey', operator=GREATER_THAN, errorThreshold='2'}, " + | |||
"status=ERROR, value=null}"); | |||
} |
@@ -89,7 +89,7 @@ public class QualityGateTest { | |||
public void toString_is_override() { | |||
QualityGate underTest = new QualityGate(QUALIGATE_ID, QUALIGATE_NAME, ImmutableSet.of(CONDITION_2)); | |||
assertThat(underTest.toString()).isEqualTo("QualityGate{id=qg_id, name='qg_name', conditions=[" + | |||
assertThat(underTest).hasToString("QualityGate{id=qg_id, name='qg_name', conditions=[" + | |||
"Condition{metricKey='m2', operator=LESS_THAN, errorThreshold='2'}" + | |||
"]}"); | |||
} |
@@ -53,7 +53,7 @@ public class QGChangeNotificationHandlerTest { | |||
@Test | |||
public void getMetadata_returns_same_instance_as_static_method() { | |||
assertThat(underTest.getMetadata().get()).isSameAs(QGChangeNotificationHandler.newMetadata()); | |||
assertThat(underTest.getMetadata()).containsSame(QGChangeNotificationHandler.newMetadata()); | |||
} | |||
@Test |
@@ -88,6 +88,6 @@ public class QualityProfileTest { | |||
@Test | |||
public void verify_toString() { | |||
assertThat(QUALITY_PROFILE.toString()).isEqualTo("QualityProfile{key=qpKey, name=qpName, language=languageKey, rulesUpdatedAt=1274194245000}"); | |||
assertThat(QUALITY_PROFILE).hasToString("QualityProfile{key=qpKey, name=qpName, language=languageKey, rulesUpdatedAt=1274194245000}"); | |||
} | |||
} |
@@ -76,12 +76,12 @@ public class ProjectAnalysisTest { | |||
@Test | |||
public void verify_getters() { | |||
assertThat(underTest.getCeTask().get()).isSameAs(ceTask); | |||
assertThat(underTest.getCeTask()).containsSame(ceTask); | |||
assertThat(underTest.getProject()).isSameAs(project); | |||
assertThat(underTest.getBranch().get()).isSameAs(branch); | |||
assertThat(underTest.getQualityGate().get()).isSameAs(qualityGate); | |||
assertThat(underTest.getBranch()).containsSame(branch); | |||
assertThat(underTest.getQualityGate()).containsSame(qualityGate); | |||
assertThat(underTest.getProperties()).isEqualTo(properties); | |||
assertThat(underTest.getAnalysis().get()).isEqualTo(analysis); | |||
assertThat(underTest.getAnalysis()).contains(analysis); | |||
ProjectAnalysis underTestWithNulls = new ProjectAnalysis(project, null, null, null, null, null, emptyMap()); | |||
assertThat(underTestWithNulls.getCeTask()).isEmpty(); | |||
@@ -111,11 +111,12 @@ public class ProjectAnalysisTest { | |||
.setQualityGate(new QualityGate("A", "B", emptySet())) | |||
.setStatus(Metric.Level.ERROR) | |||
.build(); | |||
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties)); | |||
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, null, properties)); | |||
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 2L, properties)); | |||
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, emptyMap())); | |||
assertThat(underTest).isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, ImmutableMap.of("A", "B"))); | |||
assertThat(underTest) | |||
.isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, otherQualityGate, 1L, properties)) | |||
.isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, null, properties)) | |||
.isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 2L, properties)) | |||
.isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, emptyMap())) | |||
.isNotEqualTo(new ProjectAnalysis(project, ceTask, analysis, branch, qualityGate, 1L, ImmutableMap.of("A", "B"))); | |||
} | |||
@Test | |||
@@ -151,7 +152,7 @@ public class ProjectAnalysisTest { | |||
@Test | |||
public void verify_toString() { | |||
assertThat(underTest.toString()).isEqualTo( | |||
assertThat(underTest).hasToString( | |||
"ProjectAnalysis{project=Project{uuid='uuid', key='key', name='name'}, ceTask=CeTask{id='id', status=SUCCESS}, branch=Branch{main=true, name='name', type=BRANCH}, qualityGate=EvaluatedQualityGate{qualityGate=QualityGate{id=id, name='name', conditions=[]}, status=ERROR, evaluatedConditions=[]}, updatedAt=1, properties={a=b}, analysis=Analysis{uuid='analysis_uuid', date=1500, revision=sha1}}"); | |||
} | |||
} |
@@ -70,7 +70,7 @@ public class WebhookDeliveryTest { | |||
.setError(cause) | |||
.build(); | |||
assertThat(delivery.getErrorMessage().get()).isEqualTo("fail to connect"); | |||
assertThat(delivery.getErrorMessage()).contains("fail to connect"); | |||
} | |||
private static WebhookDelivery.Builder newBuilderTemplate() { |
@@ -76,8 +76,8 @@ public class MessageTest { | |||
@Test | |||
public void to_string() { | |||
assertThat(Message.of("key1 %s", "param1").toString()).isEqualTo("key1 param1"); | |||
assertThat(Message.of("key1").toString()).isEqualTo("key1"); | |||
assertThat(Message.of("key1", (Object[])null).toString()).isEqualTo("key1"); | |||
assertThat(Message.of("key1 %s", "param1")).hasToString("key1 param1"); | |||
assertThat(Message.of("key1")).hasToString("key1"); | |||
assertThat(Message.of("key1", (Object[])null)).hasToString("key1"); | |||
} | |||
} |
@@ -89,7 +89,7 @@ public class RekeyedProjectTest { | |||
String previousKey = "E"; | |||
RekeyedProject underTest = new RekeyedProject(project, previousKey); | |||
assertThat(underTest.toString()).isEqualTo("RekeyedProject{project=Project{uuid='A', key='B', name='C', description='D'}, previousKey='E'}"); | |||
assertThat(underTest).hasToString("RekeyedProject{project=Project{uuid='A', key='B', name='C', description='D'}, previousKey='E'}"); | |||
} | |||
private static Project newRandomProject() { |
@@ -31,7 +31,7 @@ public class NotificationChannelTest { | |||
public void defaultMethods() { | |||
NotificationChannel channel = new FakeNotificationChannel(); | |||
assertThat(channel.getKey()).isEqualTo("FakeNotificationChannel"); | |||
assertThat(channel.toString()).isEqualTo("FakeNotificationChannel"); | |||
assertThat(channel).hasToString("FakeNotificationChannel"); | |||
} | |||
private static class FakeNotificationChannel extends NotificationChannel { |
@@ -71,7 +71,7 @@ public class ServerIdFactoryImplTest { | |||
ServerId serverId = underTest.create(); | |||
assertThat(serverId.getDatabaseId().get()).isEqualTo(crc32Hex(sanitizedJdbcUrl)); | |||
assertThat(serverId.getDatabaseId()).contains(crc32Hex(sanitizedJdbcUrl)); | |||
assertThat(serverId.getDatasetId()).isEqualTo(uuid); | |||
} | |||
@@ -91,7 +91,7 @@ public class ServerIdFactoryImplTest { | |||
ServerId serverId = underTest.create(currentServerId); | |||
assertThat(serverId.getDatabaseId().get()).isEqualTo(crc32Hex(sanitizedJdbcUrl)); | |||
assertThat(serverId.getDatabaseId()).contains(crc32Hex(sanitizedJdbcUrl)); | |||
assertThat(serverId.getDatasetId()).isEqualTo(currentServerId.getDatasetId()); | |||
} | |||
@@ -61,7 +61,7 @@ public class TelemetryClientTest { | |||
Buffer body = new Buffer(); | |||
request.body().writeTo(body); | |||
assertThat(body.readUtf8()).isEqualTo(JSON); | |||
assertThat(request.url().toString()).isEqualTo(TELEMETRY_URL); | |||
assertThat(request.url()).hasToString(TELEMETRY_URL); | |||
} | |||
@Test | |||
@@ -79,6 +79,6 @@ public class TelemetryClientTest { | |||
Buffer body = new Buffer(); | |||
request.body().writeTo(body); | |||
assertThat(body.readUtf8()).isEqualTo(JSON); | |||
assertThat(request.url().toString()).isEqualTo(TELEMETRY_URL); | |||
assertThat(request.url()).hasToString(TELEMETRY_URL); | |||
} | |||
} |
@@ -70,7 +70,7 @@ public class ProjectMeasuresQueryTest { | |||
public void set_quality_gate_status() { | |||
underTest.setQualityGateStatus(OK); | |||
assertThat(underTest.getQualityGateStatus().get()).isEqualTo(Level.OK); | |||
assertThat(underTest.getQualityGateStatus()).contains(Level.OK); | |||
} | |||
@Test |
@@ -223,7 +223,7 @@ public class ProjectMeasuresQueryFactoryTest { | |||
ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet()); | |||
assertThat(underTest.getQueryText().get()).isEqualTo("Sonar Qube"); | |||
assertThat(underTest.getQueryText()).contains("Sonar Qube"); | |||
} | |||
@Test | |||
@@ -232,7 +232,7 @@ public class ProjectMeasuresQueryFactoryTest { | |||
ProjectMeasuresQuery underTest = newProjectMeasuresQuery(criteria, emptySet()); | |||
assertThat(underTest.getQueryText().get()).isEqualTo("Sonar Qube"); | |||
assertThat(underTest.getQueryText()).contains("Sonar Qube"); | |||
} | |||
@Test |
@@ -103,7 +103,7 @@ public class ClusterHealthTest { | |||
ClusterHealth underTest = new ClusterHealth(health, nodeHealths); | |||
assertThat(underTest.toString()).isEqualTo("ClusterHealth{health=" + health + ", nodes=" + nodeHealths + "}"); | |||
assertThat(underTest).hasToString("ClusterHealth{health=" + health + ", nodes=" + nodeHealths + "}"); | |||
} | |||
@Test |
@@ -142,7 +142,7 @@ public class HealthTest { | |||
@Test | |||
public void verify_toString() { | |||
assertThat(Health.GREEN.toString()).isEqualTo("Health{GREEN, causes=[]}"); | |||
assertThat(Health.GREEN).hasToString("Health{GREEN, causes=[]}"); | |||
Health.Builder builder = Health.builder().setStatus(anyStatus); | |||
randomCauses.forEach(builder::addCause); | |||
@@ -17,351 +17,372 @@ | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.newcodeperiod.ws; | |||
import java.time.Instant; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.web.UserRole; | |||
import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodType; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.component.TestComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsActionTester; | |||
import org.sonarqube.ws.NewCodePeriods; | |||
import org.sonarqube.ws.NewCodePeriods.ListWSResponse; | |||
import org.sonarqube.ws.NewCodePeriods.ShowWSResponse; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
public class ListActionTest { | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private DbClient dbClient = db.getDbClient(); | |||
private ComponentFinder componentFinder = TestComponentFinder.from(db); | |||
private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance()); | |||
private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db); | |||
private ListAction underTest = new ListAction(dbClient, userSession, componentFinder, dao); | |||
private WsActionTester ws = new WsActionTester(underTest); | |||
@Test | |||
public void test_definition() { | |||
WebService.Action definition = ws.getDef(); | |||
assertThat(definition.key()).isEqualTo("list"); | |||
assertThat(definition.isInternal()).isFalse(); | |||
assertThat(definition.since()).isEqualTo("8.0"); | |||
assertThat(definition.isPost()).isFalse(); | |||
assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project"); | |||
assertThat(definition.param("project").isRequired()).isTrue(); | |||
} | |||
/* | |||
* SonarQube | |||
* Copyright (C) 2009-2023 SonarSource SA | |||
* mailto:info AT sonarsource DOT com | |||
* | |||
* This program is free software; you can redistribute it and/or | |||
* modify it under the terms of the GNU Lesser General Public | |||
* License as published by the Free Software Foundation; either | |||
* version 3 of the License, or (at your option) any later version. | |||
* | |||
* This program is distributed in the hope that it will be useful, | |||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | |||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |||
* Lesser General Public License for more details. | |||
* | |||
* You should have received a copy of the GNU Lesser General Public License | |||
* along with this program; if not, write to the Free Software Foundation, | |||
* Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. | |||
*/ | |||
package org.sonar.server.newcodeperiod.ws; | |||
import java.time.Instant; | |||
import java.util.Optional; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.sonar.api.server.ws.WebService; | |||
import org.sonar.api.utils.DateUtils; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.web.UserRole; | |||
import org.sonar.core.util.UuidFactoryFast; | |||
import org.sonar.db.DbClient; | |||
import org.sonar.db.DbTester; | |||
import org.sonar.db.component.BranchType; | |||
import org.sonar.db.component.ComponentDbTester; | |||
import org.sonar.db.component.ComponentDto; | |||
import org.sonar.db.component.SnapshotDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDao; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDbTester; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodDto; | |||
import org.sonar.db.newcodeperiod.NewCodePeriodType; | |||
import org.sonar.server.component.ComponentFinder; | |||
import org.sonar.server.component.TestComponentFinder; | |||
import org.sonar.server.exceptions.ForbiddenException; | |||
import org.sonar.server.exceptions.NotFoundException; | |||
import org.sonar.server.tester.UserSessionRule; | |||
import org.sonar.server.ws.WsActionTester; | |||
import org.sonarqube.ws.NewCodePeriods; | |||
import org.sonarqube.ws.NewCodePeriods.ListWSResponse; | |||
import org.sonarqube.ws.NewCodePeriods.ShowWSResponse; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.assertj.core.api.Assertions.assertThatThrownBy; | |||
import static org.sonar.db.component.BranchDto.DEFAULT_MAIN_BRANCH_NAME; | |||
import static org.sonar.db.component.SnapshotTesting.newAnalysis; | |||
public class ListActionTest { | |||
@Rule | |||
public UserSessionRule userSession = UserSessionRule.standalone(); | |||
@Rule | |||
public DbTester db = DbTester.create(System2.INSTANCE); | |||
private ComponentDbTester componentDb = new ComponentDbTester(db); | |||
private DbClient dbClient = db.getDbClient(); | |||
private ComponentFinder componentFinder = TestComponentFinder.from(db); | |||
private NewCodePeriodDao dao = new NewCodePeriodDao(System2.INSTANCE, UuidFactoryFast.getInstance()); | |||
private NewCodePeriodDbTester tester = new NewCodePeriodDbTester(db); | |||
private ListAction underTest = new ListAction(dbClient, userSession, componentFinder, dao); | |||
private WsActionTester ws = new WsActionTester(underTest); | |||
@Test | |||
public void test_definition() { | |||
WebService.Action definition = ws.getDef(); | |||
assertThat(definition.key()).isEqualTo("list"); | |||
assertThat(definition.isInternal()).isFalse(); | |||
assertThat(definition.since()).isEqualTo("8.0"); | |||
assertThat(definition.isPost()).isFalse(); | |||
assertThat(definition.params()).extracting(WebService.Param::key).containsOnly("project"); | |||
assertThat(definition.param("project").isRequired()).isTrue(); | |||
} | |||
@Test | |||
public void throw_NFE_if_project_not_found() { | |||
assertThatThrownBy(() -> ws.newRequest() | |||
.setParam("project", "unknown") | |||
.execute()) | |||
.isInstanceOf(NotFoundException.class) | |||
.hasMessageContaining("Project 'unknown' not found"); | |||
} | |||
@Test | |||
public void throw_NFE_if_project_not_found() { | |||
assertThatThrownBy(() -> ws.newRequest() | |||
.setParam("project", "unknown") | |||
.execute()) | |||
.isInstanceOf(NotFoundException.class) | |||
.hasMessageContaining("Project 'unknown' not found"); | |||
} | |||
@Test | |||
public void throw_FE_if_no_project_permission() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
@Test | |||
public void throw_FE_if_no_project_permission() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
assertThatThrownBy(() -> ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.execute()) | |||
.isInstanceOf(ForbiddenException.class) | |||
.hasMessageContaining("Insufficient privileges"); | |||
} | |||
assertThatThrownBy(() -> ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.execute()) | |||
.isInstanceOf(ForbiddenException.class) | |||
.hasMessageContaining("Insufficient privileges"); | |||
} | |||
@Test | |||
public void list_only_branches() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
@Test | |||
public void list_only_branches() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
createBranches(project, 5, BranchType.BRANCH); | |||
createBranches(project, 3, BranchType.PULL_REQUEST); | |||
createBranches(project, 5, BranchType.BRANCH); | |||
createBranches(project, 3, BranchType.PULL_REQUEST); | |||
logInAsProjectAdministrator(project); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION); | |||
} | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.PREVIOUS_VERSION); | |||
} | |||
@Test | |||
public void list_inherited_global_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid")); | |||
@Test | |||
public void list_inherited_global_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
tester.insert(new NewCodePeriodDto().setType(NewCodePeriodType.SPECIFIC_ANALYSIS).setValue("uuid")); | |||
createBranches(project, 5, BranchType.BRANCH); | |||
createBranches(project, 5, BranchType.BRANCH); | |||
logInAsProjectAdministrator(project); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.contains("uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.contains(true); | |||
} | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.contains("uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.contains(true); | |||
} | |||
@Test | |||
public void list_inherited_project_settings() { | |||
ComponentDto projectWithOwnSettings = componentDb.insertPublicProject(); | |||
ComponentDto projectWithGlobalSettings = componentDb.insertPublicProject(); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(projectWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("project_uuid")); | |||
createBranches(projectWithOwnSettings, 5, BranchType.BRANCH); | |||
logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", projectWithOwnSettings.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
//verify project with project level settings | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
//check if project setting is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.containsOnly("project_uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.containsOnly(true); | |||
//verify project with global level settings | |||
response = ws.newRequest() | |||
.setParam("project", projectWithGlobalSettings.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isOne(); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.containsOnly(DEFAULT_MAIN_BRANCH_NAME); | |||
//check if global setting is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.contains("global_uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.containsOnly(true); | |||
} | |||
@Test | |||
public void list_inherited_project_settings() { | |||
ComponentDto projectWithOwnSettings = componentDb.insertPublicProject(); | |||
ComponentDto projectWithGlobalSettings = componentDb.insertPublicProject(); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(projectWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("project_uuid")); | |||
createBranches(projectWithOwnSettings, 5, BranchType.BRANCH); | |||
logInAsProjectAdministrator(projectWithOwnSettings, projectWithGlobalSettings); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", projectWithOwnSettings.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
//verify project with project level settings | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(6); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "BRANCH_0", "BRANCH_1", "BRANCH_2", "BRANCH_3", "BRANCH_4"); | |||
//check if project setting is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.containsOnly("project_uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.containsOnly(true); | |||
//verify project with global level settings | |||
response = ws.newRequest() | |||
.setParam("project", projectWithGlobalSettings.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isOne(); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.containsOnly(DEFAULT_MAIN_BRANCH_NAME); | |||
//check if global setting is set | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getValue) | |||
.contains("global_uuid"); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getInherited) | |||
.containsOnly(true); | |||
} | |||
@Test | |||
public void list_branch_and_inherited_global_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branchWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("branch_uuid")); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS"); | |||
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream() | |||
.filter(s -> !s.getInherited()) | |||
.findFirst(); | |||
assertThat(ownSettings).isNotNull(); | |||
assertThat(ownSettings).isNotEmpty(); | |||
assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); | |||
assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); | |||
assertThat(ownSettings.get().getInherited()).isFalse(); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getValue) | |||
.contains("global_uuid"); | |||
} | |||
@Test | |||
public void list_branch_and_inherited_global_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("GLOBAL_SETTINGS")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branchWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("branch_uuid")); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "GLOBAL_SETTINGS"); | |||
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream() | |||
.filter(s -> !s.getInherited()) | |||
.findFirst(); | |||
assertThat(ownSettings) | |||
.isNotNull() | |||
.isNotEmpty(); | |||
assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); | |||
assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); | |||
assertThat(ownSettings.get().getInherited()).isFalse(); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getValue) | |||
.contains("global_uuid"); | |||
} | |||
@Test | |||
public void list_branch_and_inherited_project_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("project_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branchWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("branch_uuid")); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS"); | |||
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream() | |||
.filter(s -> !s.getInherited()) | |||
.findFirst(); | |||
assertThat(ownSettings).isNotNull(); | |||
assertThat(ownSettings).isNotEmpty(); | |||
assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); | |||
assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); | |||
assertThat(ownSettings.get().getInherited()).isFalse(); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getValue) | |||
.contains("project_uuid"); | |||
} | |||
@Test | |||
public void list_branch_and_inherited_project_settings() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branchWithOwnSettings = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("OWN_SETTINGS")); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_SETTINGS")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("global_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("project_uuid")); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branchWithOwnSettings.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue("branch_uuid")); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(3); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.contains(DEFAULT_MAIN_BRANCH_NAME, "OWN_SETTINGS", "PROJECT_SETTINGS"); | |||
Optional<ShowWSResponse> ownSettings = response.getNewCodePeriodsList().stream() | |||
.filter(s -> !s.getInherited()) | |||
.findFirst(); | |||
assertThat(ownSettings) | |||
.isNotNull() | |||
.isNotEmpty(); | |||
assertThat(ownSettings.get().getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(ownSettings.get().getBranchKey()).isEqualTo("OWN_SETTINGS"); | |||
assertThat(ownSettings.get().getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(ownSettings.get().getValue()).isEqualTo("branch_uuid"); | |||
assertThat(ownSettings.get().getInherited()).isFalse(); | |||
//check if global default is set | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getType) | |||
.contains(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(response.getNewCodePeriodsList()) | |||
.filteredOn(ShowWSResponse::getInherited) | |||
.extracting(ShowWSResponse::getValue) | |||
.contains("project_uuid"); | |||
} | |||
@Test | |||
public void verify_specific_analysis_effective_value() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branch = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH")); | |||
SnapshotDto analysis = componentDb.insertSnapshot(newAnalysis(project) | |||
.setUuid("A1") | |||
.setCreatedAt(Instant.now().toEpochMilli()) | |||
.setProjectVersion("1.2") | |||
.setBuildString("1.2.0.322") | |||
.setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf") | |||
); | |||
componentDb.insertSnapshot(newAnalysis(project) | |||
.setUuid("A2") | |||
.setCreatedAt(Instant.now().toEpochMilli()) | |||
.setProjectVersion("1.2") | |||
.setBuildString("1.2.0.322") | |||
.setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04") | |||
); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branch.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue(analysis.getUuid())); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(2); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH"); | |||
ShowWSResponse result = response.getNewCodePeriodsList().get(0); | |||
assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(result.getValue()).isEqualTo("A1"); | |||
assertThat(result.getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH"); | |||
assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt())); | |||
} | |||
@Test | |||
public void verify_specific_analysis_effective_value() { | |||
ComponentDto project = componentDb.insertPublicProject(); | |||
ComponentDto branch = componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey("PROJECT_BRANCH")); | |||
SnapshotDto analysis = componentDb.insertSnapshot(newAnalysis(project) | |||
.setUuid("A1") | |||
.setCreatedAt(Instant.now().toEpochMilli()) | |||
.setProjectVersion("1.2") | |||
.setBuildString("1.2.0.322") | |||
.setRevision("bfe36592eb7f9f2708b5d358b5b5f33ed535c8cf") | |||
); | |||
componentDb.insertSnapshot(newAnalysis(project) | |||
.setUuid("A2") | |||
.setCreatedAt(Instant.now().toEpochMilli()) | |||
.setProjectVersion("1.2") | |||
.setBuildString("1.2.0.322") | |||
.setRevision("2d6d5d8d5fabe2223f07aa495e794d0401ff4b04") | |||
); | |||
tester.insert(new NewCodePeriodDto() | |||
.setProjectUuid(project.uuid()) | |||
.setBranchUuid(branch.uuid()) | |||
.setType(NewCodePeriodType.SPECIFIC_ANALYSIS) | |||
.setValue(analysis.getUuid())); | |||
logInAsProjectAdministrator(project); | |||
ListWSResponse response = ws.newRequest() | |||
.setParam("project", project.getKey()) | |||
.executeProtobuf(ListWSResponse.class); | |||
assertThat(response).isNotNull(); | |||
assertThat(response.getNewCodePeriodsCount()).isEqualTo(2); | |||
assertThat(response.getNewCodePeriodsList()).extracting(ShowWSResponse::getBranchKey) | |||
.containsOnly(DEFAULT_MAIN_BRANCH_NAME, "PROJECT_BRANCH"); | |||
ShowWSResponse result = response.getNewCodePeriodsList().get(0); | |||
assertThat(result.getType()).isEqualTo(NewCodePeriods.NewCodePeriodType.SPECIFIC_ANALYSIS); | |||
assertThat(result.getValue()).isEqualTo("A1"); | |||
assertThat(result.getProjectKey()).isEqualTo(project.getKey()); | |||
assertThat(result.getBranchKey()).isEqualTo("PROJECT_BRANCH"); | |||
assertThat(result.getEffectiveValue()).isEqualTo(DateUtils.formatDateTime(analysis.getCreatedAt())); | |||
} | |||
private void createBranches(ComponentDto project, int numberOfBranches, BranchType branchType) { | |||
for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) { | |||
String branchKey = String.format("%s_%d", branchType.name(), branchCount); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType)); | |||
private void createBranches(ComponentDto project, int numberOfBranches, BranchType branchType) { | |||
for (int branchCount = 0; branchCount < numberOfBranches; branchCount++) { | |||
String branchKey = String.format("%s_%d", branchType.name(), branchCount); | |||
componentDb.insertProjectBranch(project, branchDto -> branchDto.setKey(branchKey).setBranchType(branchType)); | |||
} | |||
} | |||
} | |||
private void logInAsProjectAdministrator(ComponentDto... project) { | |||
userSession.logIn().addProjectPermission(UserRole.ADMIN, project); | |||
private void logInAsProjectAdministrator(ComponentDto... project) { | |||
userSession.logIn().addProjectPermission(UserRole.ADMIN, project); | |||
} | |||
} | |||
} |
@@ -71,10 +71,11 @@ public class PluginUpdateAggregatorTest { | |||
assertThat(aggregates).hasSize(1); | |||
Collection<PluginUpdate> releases = aggregates.iterator().next().getUpdates(); | |||
assertThat(releases).hasSize(3); | |||
assertThat(releases).contains(pluginUpdate1); | |||
assertThat(releases).contains(pluginUpdate2); | |||
assertThat(releases).contains(pluginUpdate3); | |||
assertThat(releases) | |||
.hasSize(3) | |||
.contains(pluginUpdate1) | |||
.contains(pluginUpdate2) | |||
.contains(pluginUpdate3); | |||
} | |||
private PluginUpdate createPluginUpdate(String pluginKey) { |
@@ -151,11 +151,11 @@ public class QProfileExportersTest { | |||
StringWriter writer = new StringWriter(); | |||
underTest.export(db.getSession(), profile, "standard", writer); | |||
assertThat(writer.toString()).isEqualTo("standard -> " + profile.getName() + " -> 0"); | |||
assertThat(writer).hasToString("standard -> " + profile.getName() + " -> 0"); | |||
writer = new StringWriter(); | |||
underTest.export(db.getSession(), profile, "xootool", writer); | |||
assertThat(writer.toString()).isEqualTo("xoo -> " + profile.getName() + " -> 0"); | |||
assertThat(writer).hasToString("xoo -> " + profile.getName() + " -> 0"); | |||
} | |||
@Test | |||
@@ -165,11 +165,11 @@ public class QProfileExportersTest { | |||
StringWriter writer = new StringWriter(); | |||
underTest.export(db.getSession(), profile, "standard", writer); | |||
assertThat(writer.toString()).isEqualTo("standard -> " + profile.getName() + " -> 1"); | |||
assertThat(writer).hasToString("standard -> " + profile.getName() + " -> 1"); | |||
writer = new StringWriter(); | |||
underTest.export(db.getSession(), profile, "xootool", writer); | |||
assertThat(writer.toString()).isEqualTo("xoo -> " + profile.getName() + " -> 1"); | |||
assertThat(writer).hasToString("xoo -> " + profile.getName() + " -> 1"); | |||
} | |||
@Test |
@@ -19,9 +19,8 @@ | |||
*/ | |||
package org.sonar.server.source; | |||
import org.junit.Test; | |||
import java.util.List; | |||
import org.junit.Test; | |||
import static org.assertj.core.api.Assertions.assertThat; | |||
import static org.sonar.server.source.HtmlTextDecorator.CR_END_OF_LINE; | |||
@@ -322,19 +321,19 @@ public class HtmlTextDecoratorTest { | |||
HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator(); | |||
List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javadocWithHtml, decorationData, 4, null); | |||
assertThat(htmlOutput).hasSize(9); | |||
// Begin from line 4 | |||
assertThat(htmlOutput).containsExactly( | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>", | |||
"<span class=\"cppd\"> * <ul></span>", | |||
"<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>", | |||
"<span class=\"cppd\"> * <li>...</li></span>", | |||
"<span class=\"cppd\"> * </ul></span>", | |||
"<span class=\"cppd\"> */</span>", | |||
""); | |||
assertThat(htmlOutput) | |||
.hasSize(9) | |||
// Begin from line 4 | |||
.containsExactly( | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>", | |||
"<span class=\"cppd\"> * <ul></span>", | |||
"<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>", | |||
"<span class=\"cppd\"> * <li>...</li></span>", | |||
"<span class=\"cppd\"> * </ul></span>", | |||
"<span class=\"cppd\"> */</span>", | |||
""); | |||
} | |||
@Test | |||
@@ -358,14 +357,14 @@ public class HtmlTextDecoratorTest { | |||
HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator(); | |||
List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javadocWithHtml, decorationData, null, 4); | |||
assertThat(htmlOutput).hasSize(4); | |||
// End at line 4 | |||
assertThat(htmlOutput).containsExactly( | |||
"<span class=\"cppd\">/**</span>", | |||
"<span class=\"cppd\"> * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.</span>", | |||
"<span class=\"cppd\"> * </span>", | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>"); | |||
assertThat(htmlOutput) | |||
.hasSize(4) | |||
// End at line 4 | |||
.containsExactly( | |||
"<span class=\"cppd\">/**</span>", | |||
"<span class=\"cppd\"> * Provides a basic framework to sequentially read any kind of character stream in order to feed a generic OUTPUT.</span>", | |||
"<span class=\"cppd\"> * </span>", | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>"); | |||
} | |||
@Test | |||
@@ -389,15 +388,15 @@ public class HtmlTextDecoratorTest { | |||
HtmlTextDecorator htmlTextDecorator = new HtmlTextDecorator(); | |||
List<String> htmlOutput = htmlTextDecorator.decorateTextWithHtml(javadocWithHtml, decorationData, 4, 8); | |||
assertThat(htmlOutput).hasSize(5); | |||
// Begin from line 4 and finish at line 8 | |||
assertThat(htmlOutput).containsExactly( | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>", | |||
"<span class=\"cppd\"> * <ul></span>", | |||
"<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>" | |||
); | |||
assertThat(htmlOutput) | |||
.hasSize(5) | |||
// Begin from line 4 and finish at line 8 | |||
.containsExactly( | |||
"<span class=\"cppd\"> * This framework can used for instance in order to :</span>", | |||
"<span class=\"cppd\"> * <ul></span>", | |||
"<span class=\"cppd\"> * <li>Create a lexer in charge to generate a list of tokens from a character stream</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a source code syntax highligther in charge to decorate a source code with HTML tags</li></span>", | |||
"<span class=\"cppd\"> * <li>Create a javadoc generator</li></span>" | |||
); | |||
} | |||
} |
@@ -39,11 +39,13 @@ public class OpeningHtmlTagTest { | |||
OpeningHtmlTag openingHtmlTagWithDifferentValues = new OpeningHtmlTag(5, "tag2"); | |||
OpeningHtmlTag openingHtmlTagWithNoCssClass = new OpeningHtmlTag(3, null); | |||
assertThat(openingHtmlTag).isEqualTo(openingHtmlTagWithSameValues); | |||
assertThat(openingHtmlTag).isEqualTo(openingHtmlTag); | |||
assertThat(openingHtmlTag).isNotEqualTo(openingHtmlTagWithDifferentValues); | |||
assertThat(openingHtmlTag).isNotEqualTo(openingHtmlTagWithNoCssClass); | |||
assertThat(openingHtmlTag).isNotEqualTo(new OpeningHtmlTag(3, "tag"){}); | |||
assertThat(openingHtmlTag) | |||
.isEqualTo(openingHtmlTagWithSameValues) | |||
.isEqualTo(openingHtmlTag) | |||
.isNotEqualTo(openingHtmlTagWithDifferentValues) | |||
.isNotEqualTo(openingHtmlTagWithNoCssClass) | |||
.isNotEqualTo(new OpeningHtmlTag(3, "tag") { | |||
}); | |||
} | |||
@Test |
@@ -110,7 +110,7 @@ public class ListActionTest { | |||
ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class); | |||
List<Webhooks.ListResponseElement> elements = response.getWebhooksList(); | |||
assertThat(elements.size()).isEqualTo(2); | |||
assertThat(elements).hasSize(2); | |||
assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook1.getUuid()); | |||
assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("aaa"); | |||
@@ -133,7 +133,7 @@ public class ListActionTest { | |||
ListResponse response = wsActionTester.newRequest().executeProtobuf(ListResponse.class); | |||
List<Webhooks.ListResponseElement> elements = response.getWebhooksList(); | |||
assertThat(elements.size()).isEqualTo(2); | |||
assertThat(elements).hasSize(2); | |||
assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getKey).isEqualTo(webhook1.getUuid()); | |||
assertThat(elements.get(0)).extracting(Webhooks.ListResponseElement::getName).isEqualTo("aaa"); |
@@ -40,7 +40,7 @@ public class CacheWriterTest { | |||
underTest.close(); | |||
assertThat(writer.toString()).isEqualTo("content"); | |||
assertThat(writer).hasToString("content"); | |||
} | |||
@Test |
@@ -177,11 +177,11 @@ public class ServletRequestTest { | |||
@Test | |||
public void to_string() { | |||
when(source.getRequestURL()).thenReturn(new StringBuffer("http:localhost:9000/api/issues")); | |||
assertThat(underTest.toString()).isEqualTo("http:localhost:9000/api/issues"); | |||
assertThat(underTest).hasToString("http:localhost:9000/api/issues"); | |||
when(source.getQueryString()).thenReturn("components=sonar"); | |||
assertThat(underTest.toString()).isEqualTo("http:localhost:9000/api/issues?components=sonar"); | |||
assertThat(underTest).hasToString("http:localhost:9000/api/issues?components=sonar"); | |||
} | |||
@Test |
@@ -67,7 +67,7 @@ public class WebPagesFilterTest { | |||
verify(response).setContentType("text/html"); | |||
verify(response).setCharacterEncoding("utf-8"); | |||
verify(response).setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); | |||
assertThat(outputStream.toString()).isEqualTo("test"); | |||
assertThat(outputStream).hasToString("test"); | |||
} | |||
@Test |
@@ -65,7 +65,7 @@ public class I18nClassloaderTest { | |||
@Test | |||
public void override_toString() { | |||
assertThat(i18nClassloader.toString()).isEqualTo("i18n-classloader"); | |||
assertThat(i18nClassloader).hasToString("i18n-classloader"); | |||
} | |||
private static URLClassLoader newCheckstyleClassloader() { |
@@ -287,7 +287,7 @@ public class PluginInfoTest { | |||
@Test | |||
public void test_toString() { | |||
PluginInfo pluginInfo = new PluginInfo("java").setVersion(Version.create("1.1")); | |||
assertThat(pluginInfo.toString()).isEqualTo("[java / 1.1]"); | |||
assertThat(pluginInfo).hasToString("[java / 1.1]"); | |||
pluginInfo.setImplementationBuild("SHA1"); | |||
assertThat(pluginInfo).hasToString("[java / 1.1 / SHA1]"); |
@@ -113,7 +113,7 @@ public class ServerIdTest { | |||
assertThat(serverId.getFormat()).isEqualTo(DEPRECATED); | |||
assertThat(serverId.getDatasetId()).isEqualTo(deprecated); | |||
assertThat(serverId.getDatabaseId()).isEmpty(); | |||
assertThat(serverId.toString()).isEqualTo(deprecated); | |||
assertThat(serverId).hasToString(deprecated); | |||
} | |||
@Test | |||
@@ -124,7 +124,7 @@ public class ServerIdTest { | |||
assertThat(serverId.getFormat()).isEqualTo(NO_DATABASE_ID); | |||
assertThat(serverId.getDatasetId()).isEqualTo(noDatabaseId); | |||
assertThat(serverId.getDatabaseId()).isEmpty(); | |||
assertThat(serverId.toString()).isEqualTo(noDatabaseId); | |||
assertThat(serverId).hasToString(noDatabaseId); | |||
} | |||
@DataProvider | |||
@@ -148,7 +148,7 @@ public class ServerIdTest { | |||
assertThat(serverId.getFormat()).isEqualTo(WITH_DATABASE_ID); | |||
assertThat(serverId.getDatasetId()).isEqualTo(datasetId); | |||
assertThat(serverId.getDatabaseId()).contains(databaseId); | |||
assertThat(serverId.toString()).isEqualTo(rawServerId); | |||
assertThat(serverId).hasToString(rawServerId); | |||
} | |||
@DataProvider |
@@ -28,14 +28,16 @@ public class MacAddressProviderTest { | |||
@Test | |||
public void getSecureMungedAddress() { | |||
byte[] address = MacAddressProvider.getSecureMungedAddress(); | |||
assertThat(address).isNotEmpty(); | |||
assertThat(address).hasSize(6); | |||
assertThat(address) | |||
.isNotEmpty() | |||
.hasSize(6); | |||
} | |||
@Test | |||
public void constructDummyMulticastAddress() { | |||
byte[] address = MacAddressProvider.constructDummyMulticastAddress(); | |||
assertThat(address).isNotEmpty(); | |||
assertThat(address).hasSize(6); | |||
assertThat(address) | |||
.isNotEmpty() | |||
.hasSize(6); | |||
} | |||
} |
@@ -69,19 +69,19 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleIf() { | |||
List<Statement> statements = chunk("if (a > b) { something(); }"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
statements = chunk("if (a > b) { something(); } else { somethingOther(); }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("if(a>b)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("else"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("somethingOther()"); | |||
statements = chunk("if (a > 0) { something(); } else if (a == 0) { somethingOther(); }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("if(a>$NUMBER)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("elseif(a==$NUMBER)"); | |||
@@ -91,12 +91,12 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleFor() { | |||
List<Statement> statements = chunk("for (int i = 0; i < 10; i++) { something(); }"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("for(inti=$NUMBER;i<$NUMBER;i++)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
statements = chunk("for (Item item : items) { something(); }"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("for(Itemitem:items)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
} | |||
@@ -104,7 +104,7 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleWhile() { | |||
List<Statement> statements = chunk("while (i < args.length) { something(); }"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("while(i<args.length)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
@@ -116,7 +116,7 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleDoWhile() { | |||
List<Statement> statements = chunk("do { something(); } while (true);"); | |||
assertThat(statements.size()).isEqualTo(3); | |||
assertThat(statements).hasSize(3); | |||
assertThat(statements.get(0).getValue()).isEqualTo("do"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("while(true)"); | |||
@@ -130,7 +130,7 @@ public class JavaStatementBuilderTest { | |||
" case 2 : monthString=\"February\"; break;" + | |||
" default: monthString=\"Invalid\";" + | |||
"}"); | |||
assertThat(statements.size()).isEqualTo(6); | |||
assertThat(statements).hasSize(6); | |||
assertThat(statements.get(0).getValue()).isEqualTo("switch(month)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("case$NUMBER:monthString=$CHARS"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("break"); | |||
@@ -149,7 +149,7 @@ public class JavaStatementBuilderTest { | |||
" case 'a': case 'b': case 'c': something(); break;" + | |||
" case 'd': case 'e': case 'f': somethingOther(); break;" + | |||
"}"); | |||
assertThat(statements.size()).isEqualTo(5); | |||
assertThat(statements).hasSize(5); | |||
assertThat(statements.get(0).getValue()).isEqualTo("switch(a)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("case$CHARS:case$CHARS:case$CHARS:something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("break"); | |||
@@ -160,7 +160,7 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleArray() { | |||
List<Statement> statements = chunk("new Integer[] { 1, 2, 3, 4 };"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("newInteger[]"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{$NUMBER,$NUMBER,$NUMBER,$NUMBER}"); | |||
} | |||
@@ -171,12 +171,12 @@ public class JavaStatementBuilderTest { | |||
@Test | |||
public void shouldHandleMultidimensionalArray() { | |||
List<Statement> statements = chunk("new Integer[][] { { 1, 2 }, {3, 4} };"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{{$NUMBER,$NUMBER},{$NUMBER,$NUMBER}}"); | |||
statements = chunk("new Integer[][] { null, {3, 4} };"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("newInteger[][]"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{null,{$NUMBER,$NUMBER}}"); | |||
} | |||
@@ -185,28 +185,28 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleTryCatch() { | |||
List<Statement> statements; | |||
statements = chunk("try { } catch (Exception e) { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } catch (Exception e) { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } catch (Exception e) { onException(); }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("onException()"); | |||
statements = chunk("try { something(); } catch (Exception1 e) { onException1(); } catch (Exception2 e) { onException2(); }"); | |||
assertThat(statements.size()).isEqualTo(6); | |||
assertThat(statements).hasSize(6); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1e)"); | |||
@@ -219,21 +219,21 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleTryFinnaly() { | |||
List<Statement> statements; | |||
statements = chunk("try { } finally { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("finally"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } finally { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("finally"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } finally { somethingOther(); }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("finally"); | |||
@@ -244,7 +244,7 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleTryCatchFinally() { | |||
List<Statement> statements; | |||
statements = chunk("try { } catch (Exception e) {} finally { }"); | |||
assertThat(statements.size()).isEqualTo(6); | |||
assertThat(statements).hasSize(6); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); | |||
@@ -253,7 +253,7 @@ public class JavaStatementBuilderTest { | |||
assertThat(statements.get(5).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } catch (Exception e) { onException(); } finally { somethingOther(); }"); | |||
assertThat(statements.size()).isEqualTo(6); | |||
assertThat(statements).hasSize(6); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exceptione)"); | |||
@@ -269,21 +269,21 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleMultiCatch() { | |||
List<Statement> statements; | |||
statements = chunk("try { } catch (Exception1 | Exception2 e) { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); | |||
assertThat(statements.get(3).getValue()).isEqualTo("{}"); | |||
statements = chunk("try { something(); } catch (Exception1 | Exception2 e) { onException(); }"); | |||
assertThat(statements.size()).isEqualTo(4); | |||
assertThat(statements).hasSize(4); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
assertThat(statements.get(2).getValue()).isEqualTo("catch(Exception1|Exception2e)"); | |||
@@ -297,22 +297,22 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleTryWithResource() { | |||
List<Statement> statements; | |||
statements = chunk("try (FileInputStream in = new FileInputStream()) {}"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream()) {}"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream())"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
statements = chunk("try (FileInputStream in = new FileInputStream(); FileOutputStream out = new FileOutputStream();) {}"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream();FileOutputStreamout=newFileOutputStream();)"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("{}"); | |||
statements = chunk("try (FileInputStream in = new FileInputStream()) { something(); }"); | |||
assertThat(statements.size()).isEqualTo(2); | |||
assertThat(statements).hasSize(2); | |||
assertThat(statements.get(0).getValue()).isEqualTo("try(FileInputStreamin=newFileInputStream())"); | |||
assertThat(statements.get(1).getValue()).isEqualTo("something()"); | |||
} | |||
@@ -328,7 +328,7 @@ public class JavaStatementBuilderTest { | |||
assertThat(statements).extracting(Statement::getValue).containsExactly("List<String>result=lines.stream().filter(line->!$CHARS.equals(line)).collect(Collectors.toList())"); | |||
statements = chunk("items.forEach((k,v)->{System.out.println(\"Item : \" + k + \" Count : \" + v); if(\"E\".equals(k)) { System.out.println(\"Hello E\");}});"); | |||
assertThat(statements.size()).isEqualTo(5); | |||
assertThat(statements).hasSize(5); | |||
assertThat(statements).extracting(Statement::getValue) | |||
.containsExactly("items.forEach((k,v)->", | |||
"System.out.println($CHARS+k+$CHARS+v)", | |||
@@ -344,7 +344,7 @@ public class JavaStatementBuilderTest { | |||
public void shouldHandleModuleInfo() { | |||
List<Statement> statements; | |||
statements = chunk("module com.application.infra { requires com.application.domain; exports com.application.infra.api; }"); | |||
assertThat(statements.size()).isEqualTo(3); | |||
assertThat(statements).hasSize(3); | |||
assertThat(statements).extracting(Statement::getValue) | |||
.containsExactly("modulecom.application.infra", | |||
"requirescom.application.domain", |
@@ -291,8 +291,9 @@ public class FileMetadataTest { | |||
String hash1a = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(file1a), StandardCharsets.UTF_8, file1a.getName()).hash(); | |||
String hash2 = new FileMetadata(analysisWarnings).readMetadata(new FileInputStream(file2), StandardCharsets.UTF_8, file2.getName()).hash(); | |||
assertThat(hash1).isEqualTo(hash1a); | |||
assertThat(hash1).isNotEqualTo(hash2); | |||
assertThat(hash1) | |||
.isEqualTo(hash1a) | |||
.isNotEqualTo(hash2); | |||
} | |||
@Test |
@@ -45,7 +45,7 @@ public class PathPatternTest { | |||
@Test | |||
public void match_relative_path() { | |||
PathPattern pattern = PathPattern.create("**/*Foo.java"); | |||
assertThat(pattern.toString()).isEqualTo("**/*Foo.java"); | |||
assertThat(pattern).hasToString("**/*Foo.java"); | |||
IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null); | |||
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue(); | |||
@@ -72,7 +72,7 @@ public class PathPatternTest { | |||
@Test | |||
public void match_absolute_path() { | |||
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java"); | |||
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java"); | |||
assertThat(pattern).hasToString("file:**/src/main/**Foo.java"); | |||
IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.java", null); | |||
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()))).isTrue(); | |||
@@ -88,7 +88,7 @@ public class PathPatternTest { | |||
@Test | |||
public void match_absolute_path_and_insensitive_file_extension() { | |||
PathPattern pattern = PathPattern.create("file:**/src/main/**Foo.java"); | |||
assertThat(pattern.toString()).isEqualTo("file:**/src/main/**Foo.java"); | |||
assertThat(pattern).hasToString("file:**/src/main/**Foo.java"); | |||
IndexedFile indexedFile = new DefaultIndexedFile("ABCDE", baseDir, "src/main/java/org/MyFoo.JAVA", null); | |||
assertThat(pattern.match(indexedFile.path(), Paths.get(indexedFile.relativePath()), false)).isTrue(); | |||
@@ -104,7 +104,7 @@ public class PathPatternTest { | |||
"file:**/src/main/**Bar.java" | |||
}); | |||
assertThat(patterns).hasSize(2); | |||
assertThat(patterns[0].toString()).isEqualTo("**/src/main/**Foo.java"); | |||
assertThat(patterns[1].toString()).isEqualTo("file:**/src/main/**Bar.java"); | |||
assertThat(patterns[0]).hasToString("**/src/main/**Foo.java"); | |||
assertThat(patterns[1]).hasToString("file:**/src/main/**Bar.java"); | |||
} | |||
} |
@@ -36,6 +36,6 @@ public class EnvironmentInformationTest { | |||
public void test_toString() { | |||
EnvironmentInformation env = new EnvironmentInformation("Maven Plugin", "2.0"); | |||
assertThat(env.toString()).isEqualTo("Maven Plugin/2.0"); | |||
assertThat(env).hasToString("Maven Plugin/2.0"); | |||
} | |||
} |
@@ -130,7 +130,7 @@ public class ModuleSensorExtensionDictionaryTest { | |||
ModuleSensorExtensionDictionary selector = newSelector(Marker.class, a, b); | |||
List<Object> extensions = new ArrayList<>(selector.select(Marker.class, true, null)); | |||
assertThat(extensions.size()).isEqualTo(2); | |||
assertThat(extensions).hasSize(2); | |||
assertThat(extensions.get(0)).isEqualTo(a); | |||
assertThat(extensions.get(1)).isEqualTo(b); | |||
@@ -59,7 +59,7 @@ public class IssuePatternTest { | |||
@Test | |||
public void toString_should_include_all_fields() { | |||
assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp").toString()).isEqualTo("IssuePattern{filePattern=*, rulePattern=*:Foo*IllegalRegexp}"); | |||
assertThat(new IssuePattern("*", "*:Foo*IllegalRegexp")).hasToString("IssuePattern{filePattern=*, rulePattern=*:Foo*IllegalRegexp}"); | |||
} | |||
} |
@@ -51,7 +51,7 @@ public class LineRangeTest { | |||
@Test | |||
public void testToString() { | |||
assertThat(new LineRange(12, 15).toString()).isEqualTo("[12-15]"); | |||
assertThat(new LineRange(12, 15)).hasToString("[12-15]"); | |||
} | |||
@Test |
@@ -56,7 +56,7 @@ public class IssueExclusionsLoaderTest { | |||
@Test | |||
public void testToString() { | |||
assertThat(scanner.toString()).isEqualTo("Issues Exclusions - Source Scanner"); | |||
assertThat(scanner).hasToString("Issues Exclusions - Source Scanner"); | |||
} | |||
@Test |
@@ -33,13 +33,13 @@ import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import org.sonar.api.batch.bootstrap.ProjectDefinition; | |||
import org.sonar.api.batch.fs.internal.DefaultInputModule; | |||
import org.sonar.api.utils.System2; | |||
import org.sonar.api.utils.log.LogTester; | |||
import org.sonar.api.utils.log.LoggerLevel; | |||
import org.sonar.core.platform.PluginInfo; | |||
import org.sonar.scanner.bootstrap.GlobalServerSettings; | |||
import org.sonar.scanner.bootstrap.ScannerPluginRepository; | |||
import org.sonar.api.batch.fs.internal.DefaultInputModule; | |||
import org.sonar.scanner.fs.InputModuleHierarchy; | |||
import org.sonar.scanner.protocol.output.ScannerReportWriter; | |||
import org.sonar.scanner.scan.ProjectServerSettings; | |||
@@ -115,8 +115,9 @@ public class AnalysisContextReportPublisherTest { | |||
publisher.init(writer); | |||
String content = FileUtils.readFileToString(writer.getFileStructure().analysisLog(), StandardCharsets.UTF_8); | |||
assertThat(content).containsOnlyOnce(COM_FOO); | |||
assertThat(content).containsOnlyOnce(SONAR_SKIP); | |||
assertThat(content) | |||
.containsOnlyOnce(COM_FOO) | |||
.containsOnlyOnce(SONAR_SKIP); | |||
} | |||
@Test |