private static Predicate<Profiles> isMatch(Predicate<String> activeProfile) { return profiles -> profiles.matches(activeProfile); }
@Override public boolean matches(Predicate<String> activeProfiles) { for (Profiles candidate : this.parsed) { if (candidate.matches(activeProfiles)) { return true; } } return false; }
private static Profiles not(Profiles profiles) { return activeProfile -> !profiles.matches(activeProfile); }
@Override public boolean acceptsProfiles(Profiles profiles) { Assert.notNull(profiles, "Profiles must not be null"); return profiles.matches(this::isProfileActive); }
@Override public boolean acceptsProfiles(Profiles profiles) { Assert.notNull(profiles, "Profiles must not be null"); return profiles.matches(this::isProfileActive); }
private void assertComplexExpression(Profiles profiles) { assertFalse(profiles.matches(activeProfiles("spring"))); assertTrue(profiles.matches(activeProfiles("spring", "framework"))); assertTrue(profiles.matches(activeProfiles("spring", "java"))); assertFalse(profiles.matches(activeProfiles("java", "framework"))); }
private void assertOfOrExpressionWithInvertedSingleElement(Profiles profiles) { assertTrue(profiles.matches(activeProfiles("framework"))); assertTrue(profiles.matches(activeProfiles("java"))); assertTrue(profiles.matches(activeProfiles("spring", "framework"))); assertFalse(profiles.matches(activeProfiles("spring"))); }
private void assertOfAndExpressionWithInvertedSingleElement(Profiles profiles) { assertTrue(profiles.matches(activeProfiles("framework"))); assertFalse(profiles.matches(activeProfiles("java"))); assertFalse(profiles.matches(activeProfiles("spring", "framework"))); assertFalse(profiles.matches(activeProfiles("spring"))); }
private void assertOfNotOrExpression(Profiles profiles) { assertFalse(profiles.matches(activeProfiles("spring"))); assertFalse(profiles.matches(activeProfiles("framework"))); assertFalse(profiles.matches(activeProfiles("spring", "framework"))); assertTrue(profiles.matches(activeProfiles("java"))); }
@Test public void ofMultipleElementsAllInverted() { Profiles profiles = Profiles.of("!spring", "!framework"); assertTrue(profiles.matches(activeProfiles("spring"))); assertTrue(profiles.matches(activeProfiles("framework"))); assertTrue(profiles.matches(activeProfiles("java"))); assertFalse(profiles.matches(activeProfiles("spring", "framework"))); assertFalse(profiles.matches(activeProfiles("spring", "framework", "java"))); }
@Test public void ofMultipleElementsWithInverted() { Profiles profiles = Profiles.of("!spring", "framework"); assertFalse(profiles.matches(activeProfiles("spring"))); assertTrue(profiles.matches(activeProfiles("spring", "framework"))); assertTrue(profiles.matches(activeProfiles("framework"))); assertTrue(profiles.matches(activeProfiles("java"))); }