Use Gradle test fixture support for spring-core
See gh-23550
This commit is contained in:
@@ -16,7 +16,7 @@
|
||||
|
||||
package example.type;
|
||||
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
|
||||
/**
|
||||
* We must use a standalone set of types to ensure that no one else is loading
|
||||
|
||||
@@ -42,10 +42,10 @@ import org.springframework.core.annotation.AnnotationUtilsTests.ExtendsBaseClass
|
||||
import org.springframework.core.annotation.AnnotationUtilsTests.ImplementsInterfaceWithGenericAnnotatedMethod;
|
||||
import org.springframework.core.annotation.AnnotationUtilsTests.WebController;
|
||||
import org.springframework.core.annotation.AnnotationUtilsTests.WebMapping;
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
import org.springframework.core.test.fixtures.stereotype.Indexed;
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Indexed;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
|
||||
@@ -39,8 +39,8 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
import org.springframework.lang.NonNullApi;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Arrays.stream;
|
||||
@@ -928,7 +928,7 @@ class AnnotationUtilsTests {
|
||||
Map<String, Object> map = Collections.singletonMap(VALUE, 42L);
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
synthesizeAnnotation(map, Component.class, null).value())
|
||||
.withMessageContaining("Attribute 'value' in annotation org.springframework.stereotype.Component "
|
||||
.withMessageContaining("Attribute 'value' in annotation org.springframework.core.test.fixtures.stereotype.Component "
|
||||
+ "should be compatible with java.lang.String but a java.lang.Long value was returned");
|
||||
}
|
||||
|
||||
|
||||
@@ -43,9 +43,9 @@ import org.springframework.core.Ordered;
|
||||
import org.springframework.core.annotation.MergedAnnotation.Adapt;
|
||||
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
|
||||
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
import org.springframework.core.test.fixtures.stereotype.Indexed;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.stereotype.Component;
|
||||
import org.springframework.stereotype.Indexed;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
import org.springframework.util.ReflectionUtils;
|
||||
@@ -1770,7 +1770,7 @@ class MergedAnnotationsTests {
|
||||
MergedAnnotation<Component> annotation = MergedAnnotation.of(Component.class, map);
|
||||
assertThatIllegalStateException().isThrownBy(() -> annotation.synthesize().value())
|
||||
.withMessage("Attribute 'value' in annotation " +
|
||||
"org.springframework.stereotype.Component should be " +
|
||||
"org.springframework.core.test.fixtures.stereotype.Component should be " +
|
||||
"compatible with java.lang.String but a java.lang.Long value was returned");
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -22,6 +22,7 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractEncoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -25,6 +25,7 @@ import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractEncoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -23,6 +23,7 @@ import org.junit.jupiter.api.Test;
|
||||
import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractEncoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static java.nio.charset.StandardCharsets.ISO_8859_1;
|
||||
|
||||
@@ -25,6 +25,7 @@ import reactor.core.publisher.Flux;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -24,6 +24,7 @@ import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractEncoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
import org.springframework.util.StreamUtils;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.InputStreamResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractEncoderTests;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
@@ -29,11 +29,11 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.core.io.support.ResourceRegion;
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.core.test.fixtures.io.buffer.DataBufferTestUtils;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
|
||||
@@ -30,6 +30,7 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferLimitException;
|
||||
import org.springframework.core.test.fixtures.codec.AbstractDecoderTests;
|
||||
import org.springframework.util.MimeType;
|
||||
import org.springframework.util.MimeTypeUtils;
|
||||
|
||||
|
||||
@@ -51,13 +51,13 @@ import org.springframework.core.convert.ConversionFailedException;
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.core.convert.TypeDescriptor;
|
||||
import org.springframework.core.convert.support.DefaultConversionService;
|
||||
import org.springframework.tests.EnabledForTestGroups;
|
||||
import org.springframework.core.test.fixtures.EnabledForTestGroups;
|
||||
import org.springframework.util.ClassUtils;
|
||||
import org.springframework.util.StopWatch;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.tests.TestGroup.PERFORMANCE;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.PERFORMANCE;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DefaultConversionService}.
|
||||
|
||||
@@ -43,8 +43,8 @@ import org.springframework.core.convert.converter.ConverterFactory;
|
||||
import org.springframework.core.convert.converter.GenericConverter;
|
||||
import org.springframework.core.io.DescriptiveResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.test.fixtures.EnabledForTestGroups;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.tests.EnabledForTestGroups;
|
||||
import org.springframework.util.StopWatch;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
@@ -54,7 +54,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.springframework.tests.TestGroup.PERFORMANCE;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.PERFORMANCE;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link GenericConversionService}.
|
||||
|
||||
@@ -1,87 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.env;
|
||||
|
||||
public class DummyEnvironment implements Environment {
|
||||
|
||||
@Override
|
||||
public boolean containsProperty(String key) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getProperty(String key, String defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getProperty(String key, Class<T> targetType) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getProperty(String key, Class<T> targetType, T defaultValue) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getRequiredProperty(String key) throws IllegalStateException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T getRequiredProperty(String key, Class<T> targetType) throws IllegalStateException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolvePlaceholders(String text) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String resolveRequiredPlaceholders(String text) throws IllegalArgumentException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getActiveProfiles() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getDefaultProfiles() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
@Override
|
||||
public boolean acceptsProfiles(String... profiles) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsProfiles(Profiles profiles) {
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,7 +20,7 @@ import java.util.Iterator;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.core.test.fixtures.env.MockPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@@ -24,7 +24,7 @@ import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.convert.ConverterNotFoundException;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.core.test.fixtures.env.MockPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
|
||||
@@ -16,17 +16,16 @@
|
||||
|
||||
package org.springframework.core.env;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.security.AccessControlException;
|
||||
import java.security.Permission;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.SpringProperties;
|
||||
import org.springframework.mock.env.MockPropertySource;
|
||||
import org.springframework.core.test.fixtures.env.EnvironmentTestUtils;
|
||||
import org.springframework.core.test.fixtures.env.MockPropertySource;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
@@ -465,8 +464,8 @@ public class StandardEnvironmentTests {
|
||||
|
||||
@Test
|
||||
void getSystemEnvironment_withAndWithoutSecurityManager() {
|
||||
getModifiableSystemEnvironment().put(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);
|
||||
getModifiableSystemEnvironment().put(DISALLOWED_PROPERTY_NAME, DISALLOWED_PROPERTY_VALUE);
|
||||
EnvironmentTestUtils.getModifiableSystemEnvironment().put(ALLOWED_PROPERTY_NAME, ALLOWED_PROPERTY_VALUE);
|
||||
EnvironmentTestUtils.getModifiableSystemEnvironment().put(DISALLOWED_PROPERTY_NAME, DISALLOWED_PROPERTY_VALUE);
|
||||
|
||||
{
|
||||
Map<String, Object> systemEnvironment = environment.getSystemEnvironment();
|
||||
@@ -500,68 +499,8 @@ public class StandardEnvironmentTests {
|
||||
}
|
||||
|
||||
System.setSecurityManager(oldSecurityManager);
|
||||
getModifiableSystemEnvironment().remove(ALLOWED_PROPERTY_NAME);
|
||||
getModifiableSystemEnvironment().remove(DISALLOWED_PROPERTY_NAME);
|
||||
}
|
||||
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, String> getModifiableSystemEnvironment() {
|
||||
// for os x / linux
|
||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||
Map<String, String> env = System.getenv();
|
||||
for (Class<?> cl : classes) {
|
||||
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
||||
try {
|
||||
Field field = cl.getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
Object obj = field.get(env);
|
||||
if (obj != null && obj.getClass().getName().equals("java.lang.ProcessEnvironment$StringEnvironment")) {
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for windows
|
||||
Class<?> processEnvironmentClass;
|
||||
try {
|
||||
processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||
Object obj = theCaseInsensitiveEnvironmentField.get(null);
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
catch (NoSuchFieldException ex) {
|
||||
// do nothing
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||
theEnvironmentField.setAccessible(true);
|
||||
Object obj = theEnvironmentField.get(null);
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
catch (NoSuchFieldException ex) {
|
||||
// do nothing
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
throw new IllegalStateException();
|
||||
EnvironmentTestUtils.getModifiableSystemEnvironment().remove(ALLOWED_PROPERTY_NAME);
|
||||
EnvironmentTestUtils.getModifiableSystemEnvironment().remove(DISALLOWED_PROPERTY_NAME);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -22,6 +22,8 @@ import java.nio.ByteBuffer;
|
||||
import java.nio.charset.StandardCharsets;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractDataBufferAllocatingTests;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
@@ -45,7 +45,8 @@ import reactor.test.StepVerifier;
|
||||
import org.springframework.core.io.ByteArrayResource;
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractDataBufferAllocatingTests;
|
||||
import org.springframework.core.test.fixtures.io.buffer.DataBufferTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
||||
@@ -18,6 +18,8 @@ package org.springframework.core.io.buffer;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.test.fixtures.io.buffer.LeakAwareDataBufferFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.springframework.core.io.buffer.DataBufferUtils.release;
|
||||
|
||||
|
||||
@@ -18,9 +18,10 @@ package org.springframework.core.io.buffer.support;
|
||||
|
||||
import java.nio.charset.StandardCharsets;
|
||||
|
||||
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTests;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractDataBufferAllocatingTests;
|
||||
import org.springframework.core.test.fixtures.io.buffer.DataBufferTestUtils;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -26,12 +26,12 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
|
||||
/**
|
||||
* Tests for {@link TestGroup}.
|
||||
* Tests for {@link TestGroup} parsing.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
class TestGroupTests {
|
||||
class TestGroupParsingTests {
|
||||
|
||||
@Test
|
||||
void parseNull() {
|
||||
@@ -14,9 +14,10 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Set;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
@@ -28,17 +29,20 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatCode;
|
||||
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
import static org.springframework.tests.Assume.TEST_GROUPS_SYSTEM_PROPERTY;
|
||||
import static org.springframework.tests.TestGroup.LONG_RUNNING;
|
||||
import static org.springframework.tests.TestGroup.PERFORMANCE;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.LONG_RUNNING;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.PERFORMANCE;
|
||||
|
||||
/**
|
||||
* Tests for {@link Assume}.
|
||||
* Tests for {@link TestGroup}.
|
||||
*
|
||||
* @author Sam Brannen
|
||||
* @since 5.0
|
||||
*/
|
||||
class AssumeTests {
|
||||
class TestGroupTests {
|
||||
|
||||
private static final String TEST_GROUPS_SYSTEM_PROPERTY = "testGroups";
|
||||
|
||||
|
||||
private String originalTestGroups;
|
||||
|
||||
@@ -59,25 +63,22 @@ class AssumeTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void assumeGroupWithNoActiveTestGroups() {
|
||||
setTestGroups("");
|
||||
|
||||
assertThatExceptionOfType(TestAbortedException.class).isThrownBy(() -> Assume.group(LONG_RUNNING));
|
||||
assertThatExceptionOfType(TestAbortedException.class).isThrownBy(() -> assumeGroup(LONG_RUNNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void assumeGroupWithNoMatchingActiveTestGroup() {
|
||||
setTestGroups(PERFORMANCE);
|
||||
assertThatExceptionOfType(TestAbortedException.class).isThrownBy(() -> Assume.group(LONG_RUNNING));
|
||||
assertThatExceptionOfType(TestAbortedException.class).isThrownBy(() -> assumeGroup(LONG_RUNNING));
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings("deprecation")
|
||||
void assumeGroupWithMatchingActiveTestGroup() {
|
||||
setTestGroups(LONG_RUNNING);
|
||||
assertThatCode(() -> Assume.group(LONG_RUNNING))
|
||||
assertThatCode(() -> assumeGroup(LONG_RUNNING))
|
||||
.as("assumption should NOT have failed")
|
||||
.doesNotThrowAnyException();
|
||||
}
|
||||
@@ -92,7 +93,6 @@ class AssumeTests {
|
||||
assertBogusActiveTestGroupBehavior("all-bogus");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
private void assertBogusActiveTestGroupBehavior(String testGroups) {
|
||||
// Should result in something similar to the following:
|
||||
//
|
||||
@@ -102,7 +102,7 @@ class AssumeTests {
|
||||
|
||||
setTestGroups(testGroups);
|
||||
assertThatIllegalStateException()
|
||||
.isThrownBy(() -> Assume.group(LONG_RUNNING))
|
||||
.isThrownBy(() -> assumeGroup(LONG_RUNNING))
|
||||
.withMessageStartingWith("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY + "' system property: ")
|
||||
.withCauseInstanceOf(IllegalArgumentException.class)
|
||||
.satisfies(ex ->
|
||||
@@ -119,4 +119,15 @@ class AssumeTests {
|
||||
System.setProperty(TEST_GROUPS_SYSTEM_PROPERTY, testGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume that a particular {@link TestGroup} is active.
|
||||
* @param group the group that must be active
|
||||
* @throws org.opentest4j.TestAbortedException if the assumption fails
|
||||
*/
|
||||
private static void assumeGroup(TestGroup group) {
|
||||
Set<TestGroup> testGroups = TestGroup.loadTestGroups();
|
||||
assumeTrue(testGroups.contains(group),
|
||||
() -> "Requires inactive test group " + group + "; active test groups: " + testGroups);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -33,10 +33,10 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
import org.springframework.core.annotation.AnnotationAttributes;
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -21,11 +21,11 @@ import example.type.InheritedAnnotation;
|
||||
import example.type.NonInheritedAnnotation;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.test.fixtures.stereotype.Component;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.SimpleMetadataReaderFactory;
|
||||
import org.springframework.core.type.filter.AnnotationTypeFilter;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -88,7 +88,7 @@ class AspectJTypeFilterTests {
|
||||
@Test
|
||||
void annotationPatternMatches() throws Exception {
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *..*");
|
||||
"@org.springframework.core.test.fixtures.stereotype.Component *..*");
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
"@* *..*");
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
@@ -96,9 +96,9 @@ class AspectJTypeFilterTests {
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
"@*..*Component *..*");
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *..*Component");
|
||||
"@org.springframework.core.test.fixtures.stereotype.Component *..*Component");
|
||||
assertMatch("example.type.AspectJTypeFilterTestsTypes$SomeClassAnnotatedWithComponent",
|
||||
"@org.springframework.stereotype.Component *");
|
||||
"@org.springframework.core.test.fixtures.stereotype.Component *");
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -22,13 +22,13 @@ import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.UrlResource;
|
||||
import org.springframework.core.test.fixtures.EnabledForTestGroups;
|
||||
import org.springframework.core.type.classreading.CachingMetadataReaderFactory;
|
||||
import org.springframework.core.type.classreading.MetadataReader;
|
||||
import org.springframework.core.type.classreading.MetadataReaderFactory;
|
||||
import org.springframework.tests.EnabledForTestGroups;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.springframework.tests.TestGroup.LONG_RUNNING;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.LONG_RUNNING;
|
||||
|
||||
/**
|
||||
* Unit tests for checking the behaviour of {@link CachingMetadataReaderFactory} under
|
||||
|
||||
@@ -16,21 +16,18 @@
|
||||
|
||||
package org.springframework.core.type;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
@Target({ElementType.TYPE, ElementType.METHOD})
|
||||
/**
|
||||
* Copy of the {@code @Scope} annotation for testing purposes.
|
||||
*/
|
||||
@Target({ ElementType.TYPE, ElementType.METHOD })
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Documented
|
||||
public @interface Scope {
|
||||
|
||||
/**
|
||||
* Specifies the scope to use for instances of the annotated class.
|
||||
* @return the desired scope
|
||||
*/
|
||||
String value() default "singleton";
|
||||
|
||||
}
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
import static org.junit.jupiter.api.Assumptions.assumeTrue;
|
||||
|
||||
/**
|
||||
* Provides utility methods that allow JUnit tests to assume certain conditions
|
||||
* hold {@code true}. If the assumption fails, it means the test should be
|
||||
* aborted.
|
||||
*
|
||||
* <p>Tests can be categorized into {@link TestGroup}s. Active groups are enabled using
|
||||
* the 'testGroups' system property, usually activated from the gradle command line:
|
||||
*
|
||||
* <pre class="code">
|
||||
* gradle test -PtestGroups="performance"
|
||||
* </pre>
|
||||
*
|
||||
* <p>Groups can be activated as a comma separated list of values, or using the
|
||||
* pseudo group 'all'. See {@link TestGroup} for a list of valid groups.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see EnabledForTestGroups @EnabledForTestGroups
|
||||
* @see #notLogging(Log)
|
||||
* @see TestGroup
|
||||
*/
|
||||
public abstract class Assume {
|
||||
|
||||
static final String TEST_GROUPS_SYSTEM_PROPERTY = "testGroups";
|
||||
|
||||
|
||||
/**
|
||||
* Assume that a particular {@link TestGroup} is active.
|
||||
* @param group the group that must be active
|
||||
* @throws org.opentest4j.TestAbortedException if the assumption fails
|
||||
* @deprecated as of Spring Framework 5.2 in favor of {@link EnabledForTestGroups}
|
||||
*/
|
||||
@Deprecated
|
||||
public static void group(TestGroup group) {
|
||||
Set<TestGroup> testGroups = TestGroup.loadTestGroups();
|
||||
assumeTrue(testGroups.contains(group),
|
||||
() -> "Requires inactive test group " + group + "; active test groups: " + testGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
* Assume that the specified log is not set to Trace or Debug.
|
||||
* @param log the log to test
|
||||
* @throws org.opentest4j.TestAbortedException if the assumption fails
|
||||
*/
|
||||
public static void notLogging(Log log) {
|
||||
assumeFalse(log.isTraceEnabled());
|
||||
assumeFalse(log.isDebugEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -20,6 +20,7 @@ import java.util.LinkedList;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.test.fixtures.io.SerializationTestUtils;
|
||||
import org.springframework.tests.sample.objects.TestObject;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -27,12 +27,12 @@ import java.util.List;
|
||||
import org.junit.jupiter.api.Disabled;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.tests.EnabledForTestGroups;
|
||||
import org.springframework.core.test.fixtures.EnabledForTestGroups;
|
||||
import org.springframework.tests.sample.objects.TestObject;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
|
||||
import static org.springframework.tests.TestGroup.PERFORMANCE;
|
||||
import static org.springframework.core.test.fixtures.TestGroup.PERFORMANCE;
|
||||
|
||||
/**
|
||||
* @author Rob Harrop
|
||||
|
||||
@@ -25,14 +25,14 @@ import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException
|
||||
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;
|
||||
|
||||
/**
|
||||
* Test for static utility to help with serialization.
|
||||
* Unit tests for {@link SerializationUtils}.
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @since 3.0.5
|
||||
*/
|
||||
class SerializationUtilsTests {
|
||||
|
||||
private static BigInteger FOO = new BigInteger(
|
||||
private static final BigInteger FOO = new BigInteger(
|
||||
"-9702942423549012526722364838327831379660941553432801565505143675386108883970811292563757558516603356009681061" +
|
||||
"5697574744209306031461371833798723505120163874786203211176873686513374052845353833564048");
|
||||
|
||||
@@ -44,21 +44,17 @@ class SerializationUtilsTests {
|
||||
|
||||
@Test
|
||||
void deserializeUndefined() throws Exception {
|
||||
byte[] bytes = FOO.toByteArray();
|
||||
assertThatIllegalStateException().isThrownBy(() ->
|
||||
SerializationUtils.deserialize(bytes));
|
||||
assertThatIllegalStateException().isThrownBy(() -> SerializationUtils.deserialize(FOO.toByteArray()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void serializeNonSerializable() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
SerializationUtils.serialize(new Object()));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> SerializationUtils.serialize(new Object()));
|
||||
}
|
||||
|
||||
@Test
|
||||
void deserializeNonSerializable() throws Exception {
|
||||
assertThatIllegalArgumentException().isThrownBy(() ->
|
||||
SerializationUtils.deserialize("foo".getBytes()));
|
||||
assertThatIllegalArgumentException().isThrownBy(() -> SerializationUtils.deserialize("foo".getBytes()));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.w3c.dom.Element;
|
||||
import org.xml.sax.InputSource;
|
||||
import org.xml.sax.XMLReader;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -30,7 +30,7 @@ import javax.xml.stream.events.XMLEvent;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static javax.xml.stream.XMLStreamConstants.END_DOCUMENT;
|
||||
import static javax.xml.stream.XMLStreamConstants.END_ELEMENT;
|
||||
|
||||
@@ -31,7 +31,7 @@ import javax.xml.transform.stream.StreamSource;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.w3c.dom.Document;
|
||||
import org.xml.sax.InputSource;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -31,7 +31,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.w3c.dom.Node;
|
||||
import org.xmlunit.util.Predicate;
|
||||
|
||||
import org.springframework.tests.XmlContent;
|
||||
import org.springframework.core.test.fixtures.xml.XmlContent;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
|
||||
46
spring-core/src/testFixtures/java/org/springframework/core/test/fixtures/Assume.java
vendored
Normal file
46
spring-core/src/testFixtures/java/org/springframework/core/test/fixtures/Assume.java
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import static org.junit.jupiter.api.Assumptions.assumeFalse;
|
||||
|
||||
/**
|
||||
* Utility methods that allow JUnit tests to assume certain conditions hold
|
||||
* {@code true}. If an assumption fails, it means the test should be aborted.
|
||||
*
|
||||
* @author Rob Winch
|
||||
* @author Phillip Webb
|
||||
* @author Sam Brannen
|
||||
* @since 3.2
|
||||
* @see #notLogging(Log)
|
||||
* @see EnabledForTestGroups @EnabledForTestGroups
|
||||
*/
|
||||
public abstract class Assume {
|
||||
|
||||
/**
|
||||
* Assume that the specified log is not set to Trace or Debug.
|
||||
* @param log the log to test
|
||||
* @throws org.opentest4j.TestAbortedException if the assumption fails
|
||||
*/
|
||||
public static void notLogging(Log log) {
|
||||
assumeFalse(log.isTraceEnabled());
|
||||
assumeFalse(log.isDebugEnabled());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.EnumSet;
|
||||
@@ -29,7 +29,6 @@ import static java.lang.String.format;
|
||||
* A test group used to limit when certain tests are run.
|
||||
*
|
||||
* @see EnabledForTestGroups @EnabledForTestGroups
|
||||
* @see Assume#group(TestGroup)
|
||||
* @author Phillip Webb
|
||||
* @author Chris Beams
|
||||
* @author Sam Brannen
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures;
|
||||
|
||||
/**
|
||||
* This interface can be implemented by cacheable objects or cache entries,
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.codec;
|
||||
package org.springframework.core.test.fixtures.codec;
|
||||
|
||||
import java.time.Duration;
|
||||
import java.util.Map;
|
||||
@@ -27,8 +27,9 @@ import reactor.core.publisher.Mono;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.core.codec.Decoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MimeType;
|
||||
@@ -43,7 +44,6 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.1.3
|
||||
*/
|
||||
@SuppressWarnings("ProtectedField")
|
||||
public abstract class AbstractDecoderTests<D extends Decoder<?>> extends AbstractLeakCheckingTests {
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.codec;
|
||||
package org.springframework.core.test.fixtures.codec;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.function.Consumer;
|
||||
@@ -25,9 +25,10 @@ import reactor.core.publisher.Flux;
|
||||
import reactor.test.StepVerifier;
|
||||
|
||||
import org.springframework.core.ResolvableType;
|
||||
import org.springframework.core.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.core.codec.Encoder;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.test.fixtures.io.buffer.AbstractLeakCheckingTests;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.MimeType;
|
||||
@@ -44,7 +45,6 @@ import static org.springframework.core.io.buffer.DataBufferUtils.release;
|
||||
* @author Arjen Poutsma
|
||||
* @since 5.1.3
|
||||
*/
|
||||
@SuppressWarnings("ProtectedField")
|
||||
public abstract class AbstractEncoderTests<E extends Encoder<?>> extends AbstractLeakCheckingTests {
|
||||
|
||||
/**
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.test.fixtures.env;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.util.Collections;
|
||||
import java.util.Map;
|
||||
|
||||
import org.springframework.core.env.StandardEnvironment;
|
||||
|
||||
/**
|
||||
* Test utilities for {@link StandardEnvironment}.
|
||||
*
|
||||
* @author Chris Beams
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class EnvironmentTestUtils {
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public static Map<String, String> getModifiableSystemEnvironment() {
|
||||
// for os x / linux
|
||||
Class<?>[] classes = Collections.class.getDeclaredClasses();
|
||||
Map<String, String> env = System.getenv();
|
||||
for (Class<?> cl : classes) {
|
||||
if ("java.util.Collections$UnmodifiableMap".equals(cl.getName())) {
|
||||
try {
|
||||
Field field = cl.getDeclaredField("m");
|
||||
field.setAccessible(true);
|
||||
Object obj = field.get(env);
|
||||
if (obj != null && obj.getClass().getName().equals("java.lang.ProcessEnvironment$StringEnvironment")) {
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new RuntimeException(ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// for windows
|
||||
Class<?> processEnvironmentClass;
|
||||
try {
|
||||
processEnvironmentClass = Class.forName("java.lang.ProcessEnvironment");
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
Field theCaseInsensitiveEnvironmentField = processEnvironmentClass.getDeclaredField("theCaseInsensitiveEnvironment");
|
||||
theCaseInsensitiveEnvironmentField.setAccessible(true);
|
||||
Object obj = theCaseInsensitiveEnvironmentField.get(null);
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
catch (NoSuchFieldException ex) {
|
||||
// do nothing
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
try {
|
||||
Field theEnvironmentField = processEnvironmentClass.getDeclaredField("theEnvironment");
|
||||
theEnvironmentField.setAccessible(true);
|
||||
Object obj = theEnvironmentField.get(null);
|
||||
return (Map<String, String>) obj;
|
||||
}
|
||||
catch (NoSuchFieldException ex) {
|
||||
// do nothing
|
||||
}
|
||||
catch (Exception ex) {
|
||||
throw new IllegalStateException(ex);
|
||||
}
|
||||
|
||||
throw new IllegalStateException();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.mock.env;
|
||||
package org.springframework.core.test.fixtures.env;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2016 the original author or authors.
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures.io;
|
||||
|
||||
import org.springframework.core.io.ClassPathResource;
|
||||
|
||||
@@ -23,7 +23,7 @@ import org.springframework.core.io.ClassPathResource;
|
||||
*
|
||||
* @author Chris Beams
|
||||
*/
|
||||
public abstract class TestResourceUtils {
|
||||
public abstract class ResourceTestUtils {
|
||||
|
||||
/**
|
||||
* Load a {@link ClassPathResource} qualified by the simple name of clazz,
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.util;
|
||||
package org.springframework.core.test.fixtures.io;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.ByteArrayOutputStream;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.io.buffer;
|
||||
package org.springframework.core.test.fixtures.io.buffer;
|
||||
|
||||
import java.lang.annotation.ElementType;
|
||||
import java.lang.annotation.Retention;
|
||||
@@ -40,7 +40,11 @@ import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import reactor.core.publisher.Mono;
|
||||
|
||||
import org.springframework.core.io.buffer.support.DataBufferTestUtils;
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DataBufferUtils;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
import static org.junit.jupiter.params.provider.Arguments.arguments;
|
||||
@@ -144,7 +148,7 @@ public abstract class AbstractDataBufferAllocatingTests {
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.METHOD)
|
||||
@ParameterizedTest(name = "[{index}] {0}")
|
||||
@MethodSource("org.springframework.core.io.buffer.AbstractDataBufferAllocatingTests#dataBufferFactories()")
|
||||
@MethodSource("org.springframework.core.test.fixtures.io.buffer.AbstractDataBufferAllocatingTests#dataBufferFactories()")
|
||||
public @interface ParameterizedDataBufferAllocatingTest {
|
||||
}
|
||||
|
||||
@@ -14,10 +14,12 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.io.buffer;
|
||||
package org.springframework.core.test.fixtures.io.buffer;
|
||||
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
|
||||
/**
|
||||
* Abstract base class for unit tests that allocate data buffers via a {@link DataBufferFactory}.
|
||||
* After each unit test, this base class checks whether all created buffers have been released,
|
||||
@@ -32,7 +34,6 @@ public abstract class AbstractLeakCheckingTests {
|
||||
/**
|
||||
* The data buffer factory.
|
||||
*/
|
||||
@SuppressWarnings("ProtectedField")
|
||||
protected final LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.io.buffer.support;
|
||||
package org.springframework.core.test.fixtures.io.buffer;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
@@ -14,8 +14,11 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.io.buffer;
|
||||
package org.springframework.core.test.fixtures.io.buffer;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferWrapper;
|
||||
import org.springframework.core.io.buffer.PooledDataBuffer;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.core.io.buffer;
|
||||
package org.springframework.core.test.fixtures.io.buffer;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
import java.time.Duration;
|
||||
@@ -28,6 +28,10 @@ import io.netty.buffer.PooledByteBufAllocator;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.core.io.buffer.DataBuffer;
|
||||
import org.springframework.core.io.buffer.DataBufferFactory;
|
||||
import org.springframework.core.io.buffer.DefaultDataBufferFactory;
|
||||
import org.springframework.core.io.buffer.NettyDataBufferFactory;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
/**
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.stereotype;
|
||||
package org.springframework.core.test.fixtures.stereotype;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -23,9 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Indicates that an annotated class is a "component".
|
||||
* Such classes are considered as candidates for auto-detection
|
||||
* when using annotation-based configuration and classpath scanning.
|
||||
* Copy of the standard {@code Component} annotation for testing purposes.
|
||||
*
|
||||
* @author Mark Fisher
|
||||
* @since 2.5
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.stereotype;
|
||||
package org.springframework.core.test.fixtures.stereotype;
|
||||
|
||||
import java.lang.annotation.Documented;
|
||||
import java.lang.annotation.ElementType;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures.xml;
|
||||
|
||||
import java.io.StringWriter;
|
||||
|
||||
@@ -29,7 +29,7 @@ import org.xmlunit.assertj.XmlAssert;
|
||||
*/
|
||||
public class XmlContent implements AssertProvider<XmlContentAssert> {
|
||||
|
||||
private Object source;
|
||||
private final Object source;
|
||||
|
||||
private XmlContent(Object source) {
|
||||
this.source = source;
|
||||
@@ -14,7 +14,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.tests;
|
||||
package org.springframework.core.test.fixtures.xml;
|
||||
|
||||
import org.assertj.core.api.AbstractAssert;
|
||||
import org.w3c.dom.Node;
|
||||
@@ -35,30 +35,30 @@ public class XmlContentAssert extends AbstractAssert<XmlContentAssert, Object> {
|
||||
}
|
||||
|
||||
public XmlContentAssert isSimilarTo(Object control) {
|
||||
XmlAssert.assertThat(actual).and(control).areSimilar();
|
||||
XmlAssert.assertThat(super.actual).and(control).areSimilar();
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlContentAssert isSimilarTo(Object control, Predicate<Node> nodeFilter) {
|
||||
XmlAssert.assertThat(actual).and(control).withNodeFilter(nodeFilter).areSimilar();
|
||||
XmlAssert.assertThat(super.actual).and(control).withNodeFilter(nodeFilter).areSimilar();
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlContentAssert isSimilarTo(String control,
|
||||
DifferenceEvaluator differenceEvaluator) {
|
||||
XmlAssert.assertThat(actual).and(control).withDifferenceEvaluator(
|
||||
XmlAssert.assertThat(super.actual).and(control).withDifferenceEvaluator(
|
||||
differenceEvaluator).areSimilar();
|
||||
return this;
|
||||
}
|
||||
|
||||
public XmlContentAssert isSimilarToIgnoringWhitespace(Object control) {
|
||||
XmlAssert.assertThat(actual).and(control).ignoreWhitespace().areSimilar();
|
||||
XmlAssert.assertThat(super.actual).and(control).ignoreWhitespace().areSimilar();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public XmlContentAssert isSimilarToIgnoringWhitespace(String control, NodeMatcher nodeMatcher) {
|
||||
XmlAssert.assertThat(actual).and(control).ignoreWhitespace().withNodeMatcher(nodeMatcher).areSimilar();
|
||||
XmlAssert.assertThat(super.actual).and(control).ignoreWhitespace().withNodeMatcher(nodeMatcher).areSimilar();
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user