Polish and revive disabled tests

This commit revives some previously disabled tests and converts
some usage of @Disabled to @EnabledForTestGroups(...).
This commit is contained in:
Sam Brannen 2019-09-06 15:57:27 +02:00
parent 35b967a801
commit 591995ecc8
7 changed files with 58 additions and 56 deletions

View File

@ -21,6 +21,7 @@ import java.util.ServiceLoader;
import javax.xml.parsers.DocumentBuilderFactory;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.support.DefaultListableBeanFactory;
@ -33,12 +34,15 @@ import static org.junit.jupiter.api.Assumptions.assumeTrue;
* @author Juergen Hoeller
* @author Chris Beams
*/
public class ServiceLoaderTests {
class ServiceLoaderTests {
@BeforeAll
static void assumeDocumentBuilderFactoryCanBeLoaded() {
assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext());
}
@Test
public void testServiceLoaderFactoryBean() {
assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext());
void testServiceLoaderFactoryBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(ServiceLoaderFactoryBean.class);
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
@ -49,9 +53,7 @@ public class ServiceLoaderTests {
}
@Test
public void testServiceFactoryBean() {
assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext());
void testServiceFactoryBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(ServiceFactoryBean.class);
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());
@ -61,9 +63,7 @@ public class ServiceLoaderTests {
}
@Test
public void testServiceListFactoryBean() {
assumeTrue(ServiceLoader.load(DocumentBuilderFactory.class).iterator().hasNext());
void testServiceListFactoryBean() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
RootBeanDefinition bd = new RootBeanDefinition(ServiceListFactoryBean.class);
bd.getPropertyValues().add("serviceType", DocumentBuilderFactory.class.getName());

View File

@ -18,7 +18,6 @@ package org.springframework.context.support;
import java.io.FileNotFoundException;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.MutablePropertyValues;
@ -31,6 +30,7 @@ import org.springframework.context.ApplicationContext;
import org.springframework.tests.sample.beans.TestBean;
import org.springframework.util.StringUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
/**
@ -40,6 +40,7 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
* as opposed to using only a BeanFactory during testing.
*
* @author Chris Beams
* @author Sam Brannen
* @see org.springframework.beans.factory.config.PropertyResourceConfigurerTests
*/
public class PropertyResourceConfigurerIntegrationTests {
@ -54,8 +55,8 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs.add("location", "${user.dir}/test");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
String userDir = getUserDir();
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(
ac::refresh)
assertThatExceptionOfType(BeanInitializationException.class)
.isThrownBy(ac::refresh)
.withCauseInstanceOf(FileNotFoundException.class)
.withMessageContaining(userDir);
}
@ -70,8 +71,8 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs.add("location", "${user.dir}/test/${user.dir}");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
String userDir = getUserDir();
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(
ac::refresh)
assertThatExceptionOfType(BeanInitializationException.class)
.isThrownBy(ac::refresh)
.withCauseInstanceOf(FileNotFoundException.class)
.matches(ex -> ex.getMessage().contains(userDir + "/test/" + userDir) ||
ex.getMessage().contains(userDir + "/test//" + userDir));
@ -95,8 +96,8 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs = new MutablePropertyValues();
pvs.add("location", "${myprop}/test/${myprop}");
ac.registerSingleton("configurer", PropertyPlaceholderConfigurer.class, pvs);
assertThatExceptionOfType(BeanInitializationException.class).isThrownBy(
ac::refresh)
assertThatExceptionOfType(BeanInitializationException.class)
.isThrownBy(ac::refresh)
.withMessageContaining("myprop");
}
@ -109,8 +110,7 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${var}");
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(
ac::refresh);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
}
@Test
@ -122,8 +122,7 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m}");
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(
ac::refresh);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
}
@Test
@ -135,31 +134,35 @@ public class PropertyResourceConfigurerIntegrationTests {
pvs = new MutablePropertyValues();
pvs.add("properties", "var=${m}var\nm=${var2}\nvar2=${m2}");
ac.registerSingleton("configurer1", PropertyPlaceholderConfigurer.class, pvs);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(
ac::refresh);
assertThatExceptionOfType(BeanDefinitionStoreException.class).isThrownBy(ac::refresh);
}
@Disabled // this test was breaking after the 3.0 repackaging
@Test
public void testPropertyPlaceholderConfigurerWithAutowireByType() {
// StaticApplicationContext ac = new StaticApplicationContext();
// MutablePropertyValues pvs = new MutablePropertyValues();
// pvs.addPropertyValue("touchy", "${test}");
// ac.registerSingleton("tb", TestBean.class, pvs);
// pvs = new MutablePropertyValues();
// pvs.addPropertyValue("target", new RuntimeBeanReference("tb"));
// // uncomment when fixing this test
// // ac.registerSingleton("tbProxy", org.springframework.aop.framework.ProxyFactoryBean.class, pvs);
// pvs = new MutablePropertyValues();
// Properties props = new Properties();
// props.put("test", "mytest");
// pvs.addPropertyValue("properties", new Properties(props));
// RootBeanDefinition ppcDef = new RootBeanDefinition(PropertyPlaceholderConfigurer.class, pvs);
// ppcDef.setAutowireMode(RootBeanDefinition.AUTOWIRE_BY_TYPE);
// ac.registerBeanDefinition("configurer", ppcDef);
// ac.refresh();
// TestBean tb = (TestBean) ac.getBean("tb");
// assertEquals("mytest", tb.getTouchy());
public void testPropertyPlaceholderConfigurerWithValueFromSystemProperty() {
final String propertyName = getClass().getName() + ".test";
try {
System.setProperty(propertyName, "mytest");
StaticApplicationContext context = new StaticApplicationContext();
MutablePropertyValues pvs = new MutablePropertyValues();
pvs.addPropertyValue("touchy", "${" + propertyName + "}");
context.registerSingleton("tb", TestBean.class, pvs);
pvs = new MutablePropertyValues();
pvs.addPropertyValue("target", new RuntimeBeanReference("tb"));
context.registerSingleton("tbProxy", org.springframework.aop.framework.ProxyFactoryBean.class, pvs);
context.registerSingleton("configurer", PropertyPlaceholderConfigurer.class);
context.refresh();
TestBean testBean = context.getBean("tb", TestBean.class);
assertThat(testBean.getTouchy()).isEqualTo("mytest");
}
finally {
System.clearProperty(propertyName);
}
}
}

View File

@ -20,7 +20,6 @@ import java.util.concurrent.RejectedExecutionHandler;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ThreadFactory;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.core.task.NoOpRunnable;
@ -142,8 +141,8 @@ public class ScheduledExecutorFactoryBeanTests {
verify(runnable, atLeast(2)).run();
}
@Disabled
@Test
@EnabledForTestGroups(PERFORMANCE)
public void testWithInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectly() throws Exception {
Runnable runnable = mock(Runnable.class);
@ -162,8 +161,8 @@ public class ScheduledExecutorFactoryBeanTests {
verify(runnable, never()).run();
}
@Disabled
@Test
@EnabledForTestGroups(PERFORMANCE)
public void testWithInitialDelayRepeatedExecutionIsSetUpAndFiresCorrectlyAfterException() throws Exception {
Runnable runnable = mock(Runnable.class);
willThrow(new IllegalStateException()).given(runnable).run();

View File

@ -27,13 +27,14 @@ import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.HashSet;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.tests.EnabledForTestGroups;
import org.springframework.util.FileCopyUtils;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.tests.TestGroup.CI;
/**
* Unit tests for various {@link Resource} implementations.
@ -218,10 +219,10 @@ class ResourceTests {
assertThat(relative).isEqualTo(new UrlResource("file:dir/subdir"));
}
@Disabled
@Test // this test is quite slow. TODO: re-enable with JUnit categories
@Test
@EnabledForTestGroups(CI)
void testNonFileResourceExists() throws Exception {
Resource resource = new UrlResource("https://www.springframework.org");
Resource resource = new UrlResource("https://spring.io/");
assertThat(resource.exists()).isTrue();
}

View File

@ -254,7 +254,7 @@ public class PersistenceXmlParsingTests {
assertThat(info[0].excludeUnlistedClasses()).as("Exclude unlisted should default false in 1.0.").isFalse();
}
@Disabled // not doing schema parsing anymore for JPA 2.0 compatibility
@Disabled("not doing schema parsing anymore for JPA 2.0 compatibility")
@Test
public void testInvalidPersistence() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(
@ -264,7 +264,7 @@ public class PersistenceXmlParsingTests {
reader.readPersistenceUnitInfos(resource));
}
@Disabled // not doing schema parsing anymore for JPA 2.0 compatibility
@Disabled("not doing schema parsing anymore for JPA 2.0 compatibility")
@Test
public void testNoSchemaPersistence() throws Exception {
PersistenceUnitReader reader = new PersistenceUnitReader(

View File

@ -31,7 +31,6 @@ import javax.persistence.PersistenceContextType;
import javax.persistence.PersistenceProperty;
import javax.persistence.PersistenceUnit;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.FactoryBean;
@ -337,7 +336,6 @@ public class PersistenceInjectionTests extends AbstractEntityManagerFactoryBeanT
}
@Test
@Disabled
public void testPersistenceUnitsFromJndi() {
EntityManager mockEm = mock(EntityManager.class);
given(mockEmf.createEntityManager()).willReturn(mockEm);

View File

@ -300,8 +300,9 @@ public class UrlPathHelperTests {
assertThat(helper.getLookupPathForRequest(request)).isEqualTo("/");
}
@Disabled
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
@Test @Disabled
@Test
public void tomcatCasualServletRootWithMissingSlash() throws Exception {
request.setContextPath("/test");
request.setPathInfo(null);
@ -348,8 +349,8 @@ public class UrlPathHelperTests {
tomcatCasualServletRoot();
}
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
@Disabled
// test the root mapping for /foo/* w/o a trailing slash - <host>/<context>/foo
@Test
public void wasCasualServletRootWithMissingSlash() throws Exception {
request.setContextPath("/test");