@Test public void testGetRules() { final AnalysisRule rule = mock(AnalysisRule.class); @SuppressWarnings("unchecked") final Enumeration<AnalysisRule> enumeration = mock(Enumeration.class); when(enumeration.hasMoreElements()).thenReturn(Boolean.TRUE, Boolean.FALSE); when(enumeration.nextElement()).thenReturn(rule); mockStatic(Service.class); when(Service.providers(AnalysisRule.class)).thenReturn(enumeration); final Set<AnalysisRule> rules = provider.getRules(); assertThat(rules).containsOnly(rule); assertThat(rules).isSameAs(provider.getRules()); }
@SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; }
AnalysisRuleProvider { @SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; } }
AnalysisRuleProvider { @SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; }  }
AnalysisRuleProvider { @SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; }  @SuppressWarnings("unchecked") Set<AnalysisRule> getRules(); }
AnalysisRuleProvider { @SuppressWarnings("unchecked") public Set<AnalysisRule> getRules() { if (rules == null) { rules = new HashSet<AnalysisRule>(); final Enumeration<AnalysisRule> providersEnum = Service.providers(AnalysisRule.class); while (providersEnum.hasMoreElements()) rules.add(providersEnum.nextElement()); } return rules; }  @SuppressWarnings("unchecked") Set<AnalysisRule> getRules();  }