@Before public void setUp() { MockitoAnnotations.initMocks(this); provider = new ActiveRulesProvider(); }
private static ActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) { Collection<String> qProfileKeys = getKeys(qProfiles); Set<RuleKey> loadedRulesKey = new HashSet<>(); ActiveRulesBuilder builder = new ActiveRulesBuilder(); for (String qProfileKey : qProfileKeys) { Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey); for (LoadedActiveRule r : qProfileRules) { if (!loadedRulesKey.contains(r.getRuleKey())) { loadedRulesKey.add(r.getRuleKey()); builder.addRule(transform(r, qProfileKey)); } } } return builder.build(); }
public ActiveRules provide(ActiveRulesLoader loader, QualityProfiles qProfiles) { if (singleton == null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); singleton = load(loader, qProfiles); profiler.stopInfo(); } return singleton; }
@Test public void testCombinationOfRules() { LoadedActiveRule r1 = mockRule("rule1"); LoadedActiveRule r2 = mockRule("rule2"); LoadedActiveRule r3 = mockRule("rule3"); List<LoadedActiveRule> qp1Rules = ImmutableList.of(r1, r2); List<LoadedActiveRule> qp2Rules = ImmutableList.of(r2, r3); List<LoadedActiveRule> qp3Rules = ImmutableList.of(r1, r3); when(loader.load(eq("qp1"))).thenReturn(qp1Rules); when(loader.load(eq("qp2"))).thenReturn(qp2Rules); when(loader.load(eq("qp3"))).thenReturn(qp3Rules); QualityProfiles profiles = mockProfiles("qp1", "qp2", "qp3"); ActiveRules activeRules = provider.provide(loader, profiles); assertThat(activeRules.findAll()).hasSize(3); assertThat(activeRules.findAll()).extracting("ruleKey").containsOnly( RuleKey.of("rule1", "rule1"), RuleKey.of("rule2", "rule2"), RuleKey.of("rule3", "rule3")); verify(loader).load(eq("qp1")); verify(loader).load(eq("qp2")); verify(loader).load(eq("qp3")); verifyNoMoreInteractions(loader); }
public ActiveRules provide(ActiveRulesLoader loader, QualityProfiles qProfiles) { if (singleton == null) { Profiler profiler = Profiler.create(LOG).startInfo(LOG_MSG); singleton = load(loader, qProfiles); profiler.stopInfo(); } return singleton; }
@Test public void testParamsAreTransformed() { LoadedActiveRule r1 = mockRule("rule1"); LoadedActiveRule r2 = mockRule("rule2"); r2.setParams(ImmutableMap.of("foo1", "bar1", "foo2", "bar2")); List<LoadedActiveRule> qpRules = ImmutableList.of(r1, r2); when(loader.load(eq("qp"))).thenReturn(qpRules); QualityProfiles profiles = mockProfiles("qp"); ActiveRules activeRules = provider.provide(loader, profiles); assertThat(activeRules.findAll()).hasSize(2); assertThat(activeRules.findAll()).extracting("ruleKey", "params").containsOnly( Tuple.tuple(RuleKey.of("rule1", "rule1"), ImmutableMap.of()), Tuple.tuple(RuleKey.of("rule2", "rule2"), ImmutableMap.of("foo1", "bar1", "foo2", "bar2"))); verify(loader).load(eq("qp")); verifyNoMoreInteractions(loader); }
private static ActiveRules load(ActiveRulesLoader loader, QualityProfiles qProfiles) { Collection<String> qProfileKeys = getKeys(qProfiles); Set<RuleKey> loadedRulesKey = new HashSet<>(); ActiveRulesBuilder builder = new ActiveRulesBuilder(); for (String qProfileKey : qProfileKeys) { Collection<LoadedActiveRule> qProfileRules = load(loader, qProfileKey); for (LoadedActiveRule r : qProfileRules) { if (!loadedRulesKey.contains(r.getRuleKey())) { loadedRulesKey.add(r.getRuleKey()); builder.addRule(transform(r, qProfileKey)); } } } return builder.build(); }
new ActiveRulesProvider(), new QualityProfilesProvider(), CheckFactory.class,
new ActiveRulesProvider(), new QualityProfilesProvider(), CheckFactory.class,