import com.google.common.collect.ArrayListMultimap;
import com.google.common.collect.Multimap;
-import java.util.Random;
-import java.util.stream.Collectors;
-import java.util.stream.IntStream;
import org.assertj.core.groups.Tuple;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
import org.sonar.server.notification.NotificationManager;
import org.sonar.server.qualityprofile.BuiltInQualityProfilesNotification.Profile;
+import static java.util.Arrays.asList;
import static org.apache.commons.lang.RandomStringUtils.randomAlphanumeric;
import static org.assertj.core.api.Java6Assertions.assertThat;
import static org.assertj.core.api.Java6Assertions.tuple;
public class BuiltInQualityProfilesUpdateListenerTest {
- private static final Random RANDOM = new Random();
private NotificationManager notificationManager = mock(NotificationManager.class);
private MapSettings settings = new MapSettings();
Multimap<QProfileName, ActiveRuleChange> profiles = ArrayListMultimap.create();
Languages languages = new Languages();
addProfile(profiles, languages, ACTIVATED);
- long startDate = RANDOM.nextInt(5000);
- long endDate = startDate + RANDOM.nextInt(5000);
+ long startDate = 10_000_000_000L;
+ long endDate = 15_000_000_000L;
BuiltInQualityProfilesUpdateListener underTest = new BuiltInQualityProfilesUpdateListener(notificationManager, languages, settings.asConfig());
underTest.onChange(profiles, startDate, endDate);
String profileName = randomLowerCaseText();
Language language = newLanguage(randomLowerCaseText(), randomLowerCaseText());
languages.add(language);
- int numberOfChanges = RANDOM.nextInt(1000);
- profiles.putAll(
- new QProfileName(language.getKey(), profileName),
- IntStream.range(0, numberOfChanges).mapToObj(i -> new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule" + i))).collect(Collectors.toSet()));
- return tuple(profileName, language.getKey(), language.getName(), numberOfChanges);
+ profiles.putAll(new QProfileName(language.getKey(), profileName),
+ asList(new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule1")), new ActiveRuleChange(type, ActiveRuleKey.parse("qp:repo:rule2"))));
+ return tuple(profileName, language.getKey(), language.getName(), 2);
}
private static String randomLowerCaseText() {