JAVA-4013: Moved 2 articles to spring-testing-2
This commit is contained in:
@@ -133,18 +133,7 @@
|
||||
</configuration>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<!-- this surefire configuration allows concurrent execution;
|
||||
do not remove -->
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<version>${maven-surefire-plugin.version}</version>
|
||||
<configuration>
|
||||
<parallel>methods</parallel>
|
||||
<useUnlimitedThreads>true</useUnlimitedThreads>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
|
||||
@@ -1,52 +0,0 @@
|
||||
package com.baeldung;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.BeansException;
|
||||
import org.springframework.beans.factory.InitializingBean;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
import org.springframework.context.ApplicationContextAware;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringRunner;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@RunWith(SpringRunner.class)
|
||||
@ContextConfiguration(classes = Spring5JUnit4ConcurrentIntegrationTest.SimpleConfiguration.class)
|
||||
public class Spring5JUnit4ConcurrentIntegrationTest implements ApplicationContextAware, InitializingBean {
|
||||
|
||||
@Configuration
|
||||
public static class SimpleConfiguration {
|
||||
}
|
||||
|
||||
private ApplicationContext applicationContext;
|
||||
|
||||
private boolean beanInitialized = false;
|
||||
|
||||
@Override
|
||||
public final void afterPropertiesSet() throws Exception {
|
||||
this.beanInitialized = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void setApplicationContext(final ApplicationContext applicationContext) throws BeansException {
|
||||
this.applicationContext = applicationContext;
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void verifyApplicationContextSet() throws InterruptedException {
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
assertNotNull("The application context should have been set due to ApplicationContextAware semantics.", this.applicationContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public final void verifyBeanInitialized() throws InterruptedException {
|
||||
TimeUnit.SECONDS.sleep(2);
|
||||
assertTrue("This test bean should have been initialized due to InitializingBean semantics.", this.beanInitialized);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
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 {
|
||||
|
||||
}
|
||||
@@ -1,50 +0,0 @@
|
||||
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(Spring5EnabledAnnotationIntegrationTest.Config.class)
|
||||
@TestPropertySource(properties = { "tests.enabled=true" })
|
||||
public class Spring5EnabledAnnotationIntegrationTest {
|
||||
|
||||
@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);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user