@Test public void sensibleToString() { assertEquals("spring & framework or java | kotlin", Profiles.of("spring & framework", "java | kotlin").toString()); }
@Test public void ofOrExpressionWithoutSpaces() { Profiles profiles = Profiles.of("(spring|framework)"); assertOrExpression(profiles); }
@Test public void ofAndExpressionWithoutParentheses() { Profiles profiles = Profiles.of("spring & framework"); assertAndExpression(profiles); }
@Test public void ofOrExpressionWithInvertedSingleElementWithoutSpaces() { Profiles profiles = Profiles.of("!spring|framework"); assertOfOrExpressionWithInvertedSingleElement(profiles); }
@Test public void ofComplexExpression() { Profiles profiles = Profiles.of("(spring & framework) | (spring & java)"); assertComplexExpression(profiles); }
@Test public void ofOrExpression() { Profiles profiles = Profiles.of("(spring | framework)"); assertOrExpression(profiles); }
@Test public void ofAndExpressionWithoutSpaces() { Profiles profiles = Profiles.of("spring&framework)"); assertAndExpression(profiles); }
@Test public void ofNotAndExpression() { Profiles profiles = Profiles.of("!(spring & framework)"); assertOfNotAndExpression(profiles); }
@Test public void ofAndExpressionWithInvertedSingleElement() { Profiles profiles = Profiles.of("!spring & framework"); assertOfAndExpressionWithInvertedSingleElement(profiles); }
@Test public void ofAndExpressionWithInBracketsInvertedSingleElement() { Profiles profiles = Profiles.of("(!spring) & framework"); assertOfAndExpressionWithInvertedSingleElement(profiles); }
@Test public void acceptsProfiles_withProfileExpression() { assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(false)); environment.addActiveProfile("p1"); assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(false)); environment.addActiveProfile("p2"); assertThat(environment.acceptsProfiles(Profiles.of("p1 & p2")), is(true)); }
@Test public void ofWhenEmptyThrowsException() { this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("Must specify at least one profile"); Profiles.of(); }
@Test public void ofEmptyElement() { this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("must contain text"); Profiles.of(" "); }
@Test public void ofNullElement() { this.thrown.expect(IllegalArgumentException.class); this.thrown.expectMessage("must contain text"); Profiles.of((String) null); }
@Test public void withSingleCustomReservedDefaultProfile() { class CustomEnvironment extends AbstractEnvironment { @Override protected Set<String> getReservedDefaultProfiles() { return Collections.singleton("rd1"); } } Environment env = new CustomEnvironment(); assertThat(env.acceptsProfiles(defaultProfile()), is(false)); assertThat(env.acceptsProfiles(Profiles.of("rd1")), is(true)); }
@Test public void ofSingleElement() { Profiles profiles = Profiles.of("spring"); assertTrue(profiles.matches(activeProfiles("spring"))); assertFalse(profiles.matches(activeProfiles("framework"))); }
@Test public void ofSingleExpression() { Profiles profiles = Profiles.of("(spring)"); assertTrue(profiles.matches(activeProfiles("spring"))); assertFalse(profiles.matches(activeProfiles("framework"))); }
@Test public void ofMultipleElements() { Profiles profiles = Profiles.of("spring", "framework"); assertTrue(profiles.matches(activeProfiles("spring"))); assertTrue(profiles.matches(activeProfiles("framework"))); assertFalse(profiles.matches(activeProfiles("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"))); }