SlingUtils extends OsgiUtil { public boolean hasRunModes(Set<String> requiredRunModes) { Iterator<String> it = requiredRunModes.iterator(); boolean hasMatchingSetOfRunModes = requiredRunModes.isEmpty(); while (!hasMatchingSetOfRunModes && it.hasNext()) { String next = it.next(); if (next == null || next.length() == 0) { throw new IllegalArgumentException("null or empty string cannot be a required runmode."); } Collection<String> collectionOfRequiredRunModes = Arrays.asList(next.split("\\.")); hasMatchingSetOfRunModes = getRunModes().containsAll(collectionOfRequiredRunModes); } return hasMatchingSetOfRunModes; }  ResourceResolver getResourceResolver(Session session); boolean hasRunModes(Set<String> requiredRunModes);  }
@Test public void testHasRunModes() { Assert.assertTrue(toTest.hasRunModes(Collections.<String>emptySet())); Assert.assertTrue(toTest.hasRunModes(ImmutableSet.of("runmode1", "runmode2"))); Assert.assertTrue(toTest.hasRunModes(ImmutableSet.of("runmode1"))); Assert.assertTrue(toTest.hasRunModes(ImmutableSet.of("runmode1", "runmode3"))); Assert.assertTrue(toTest.hasRunModes(ImmutableSet.of("runmode1.runmode2"))); Assert.assertFalse(toTest.hasRunModes(ImmutableSet.of("runmode3"))); Assert.assertFalse(toTest.hasRunModes(ImmutableSet.of("runmode1.runmode3"))); }
@Test(expected = IllegalArgumentException.class) public void testHasRunModesNull() { Set<String> nullSet = new HashSet<>(); nullSet.add(null); toTest.hasRunModes(nullSet); }
@Test(expected = IllegalArgumentException.class) public void testHasRunModesEmpty() { Set<String> nullSet = new HashSet<>(); nullSet.add(""); toTest.hasRunModes(nullSet); }