BAEL-1233 - Enabled Annotation in Spring 5 Testing (#3031)
* tests with enabled annotations * rollback pom * formatting
This commit is contained in:
		
							parent
							
								
									d076823051
								
							
						
					
					
						commit
						1c543f8f86
					
				| @ -0,0 +1,18 @@ | ||||
| package com.baeldung.jupiter; | ||||
| 
 | ||||
| import java.lang.annotation.ElementType; | ||||
| import java.lang.annotation.Retention; | ||||
| import java.lang.annotation.RetentionPolicy; | ||||
| import java.lang.annotation.Target; | ||||
| 
 | ||||
| import org.springframework.test.context.junit.jupiter.EnabledIf; | ||||
| 
 | ||||
| @Target({ ElementType.TYPE, ElementType.METHOD }) | ||||
| @Retention(RetentionPolicy.RUNTIME) | ||||
| @EnabledIf( | ||||
|     expression = "#{systemProperties['java.version'].startsWith('1.8')}", | ||||
|     reason = "Enabled on Java 8" | ||||
| ) | ||||
| public @interface EnabledOnJava8 { | ||||
| 
 | ||||
| } | ||||
| @ -0,0 +1,50 @@ | ||||
| package com.baeldung.jupiter; | ||||
| 
 | ||||
| import static org.junit.jupiter.api.Assertions.assertTrue; | ||||
| 
 | ||||
| import org.junit.jupiter.api.Test; | ||||
| import org.springframework.context.annotation.Configuration; | ||||
| import org.springframework.test.context.TestPropertySource; | ||||
| import org.springframework.test.context.junit.jupiter.DisabledIf; | ||||
| import org.springframework.test.context.junit.jupiter.EnabledIf; | ||||
| import org.springframework.test.context.junit.jupiter.SpringJUnitConfig; | ||||
| 
 | ||||
| @SpringJUnitConfig(Spring5EnabledAnnotationTest.Config.class) | ||||
| @TestPropertySource(properties = { "tests.enabled=true" }) | ||||
| public class Spring5EnabledAnnotationTest { | ||||
|      | ||||
|     @Configuration | ||||
|     static class Config { | ||||
|     } | ||||
| 
 | ||||
|     @EnabledIf("true") | ||||
|     @Test | ||||
|     void givenEnabledIfLiteral_WhenTrue_ThenTestExecuted() { | ||||
|         assertTrue(true); | ||||
|     } | ||||
| 
 | ||||
|     @EnabledIf(expression = "${tests.enabled}", loadContext = true) | ||||
|     @Test | ||||
|     void givenEnabledIfExpression_WhenTrue_ThenTestExecuted() { | ||||
|         assertTrue(true); | ||||
|     } | ||||
| 
 | ||||
|     @EnabledIf("#{systemProperties['java.version'].startsWith('1.8')}") | ||||
|     @Test | ||||
|     void givenEnabledIfSpel_WhenTrue_ThenTestExecuted() { | ||||
|         assertTrue(true); | ||||
|     } | ||||
| 
 | ||||
|     @EnabledOnJava8 | ||||
|     @Test | ||||
|     void givenEnabledOnJava8_WhenTrue_ThenTestExecuted() { | ||||
|         assertTrue(true); | ||||
|     } | ||||
| 
 | ||||
|     @DisabledIf("#{systemProperties['java.version'].startsWith('1.7')}") | ||||
|     @Test | ||||
|     void givenDisabledIf_WhenTrue_ThenTestNotExecuted() { | ||||
|         assertTrue(true); | ||||
|     } | ||||
| 
 | ||||
| } | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user