File tree Expand file tree Collapse file tree
spring-5/src/test/java/com/baeldung/jupiter Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .jupiter ;
2+
3+ import java .lang .annotation .ElementType ;
4+ import java .lang .annotation .Retention ;
5+ import java .lang .annotation .RetentionPolicy ;
6+ import java .lang .annotation .Target ;
7+
8+ import org .springframework .test .context .junit .jupiter .EnabledIf ;
9+
10+ @ Target ({ ElementType .TYPE , ElementType .METHOD })
11+ @ Retention (RetentionPolicy .RUNTIME )
12+ @ EnabledIf (
13+ expression = "#{systemProperties['java.version'].startsWith('1.8')}" ,
14+ reason = "Enabled on Java 8"
15+ )
16+ public @interface EnabledOnJava8 {
17+
18+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .jupiter ;
2+
3+ import static org .junit .jupiter .api .Assertions .assertTrue ;
4+
5+ import org .junit .jupiter .api .Test ;
6+ import org .springframework .context .annotation .Configuration ;
7+ import org .springframework .test .context .TestPropertySource ;
8+ import org .springframework .test .context .junit .jupiter .DisabledIf ;
9+ import org .springframework .test .context .junit .jupiter .EnabledIf ;
10+ import org .springframework .test .context .junit .jupiter .SpringJUnitConfig ;
11+
12+ @ SpringJUnitConfig (Spring5EnabledAnnotationTest .Config .class )
13+ @ TestPropertySource (properties = { "tests.enabled=true" })
14+ public class Spring5EnabledAnnotationTest {
15+
16+ @ Configuration
17+ static class Config {
18+ }
19+
20+ @ EnabledIf ("true" )
21+ @ Test
22+ void givenEnabledIfLiteral_WhenTrue_ThenTestExecuted () {
23+ assertTrue (true );
24+ }
25+
26+ @ EnabledIf (expression = "${tests.enabled}" , loadContext = true )
27+ @ Test
28+ void givenEnabledIfExpression_WhenTrue_ThenTestExecuted () {
29+ assertTrue (true );
30+ }
31+
32+ @ EnabledIf ("#{systemProperties['java.version'].startsWith('1.8')}" )
33+ @ Test
34+ void givenEnabledIfSpel_WhenTrue_ThenTestExecuted () {
35+ assertTrue (true );
36+ }
37+
38+ @ EnabledOnJava8
39+ @ Test
40+ void givenEnabledOnJava8_WhenTrue_ThenTestExecuted () {
41+ assertTrue (true );
42+ }
43+
44+ @ DisabledIf ("#{systemProperties['java.version'].startsWith('1.7')}" )
45+ @ Test
46+ void givenDisabledIf_WhenTrue_ThenTestNotExecuted () {
47+ assertTrue (true );
48+ }
49+
50+ }
You can’t perform that action at this time.
0 commit comments