Migrate test suite from JUnit 4 to JUnit Jupiter

This first commit for this issue:

- allows JUnit Jupiter to be used for all tests
- adds a dependency on mockito-junit-jupiter
- migrates tests in spring-core to JUnit Jupiter, except parameterized
  tests

The following script was developed in order to semi-automate the
migration process.

https://github.com/sbrannen/junit-converters/blob/master/junit4ToJUnitJupiter.zsh

See gh-23451
This commit is contained in:
Sam Brannen 2019-08-12 11:32:26 +02:00
parent bb8fd1c6bd
commit 32cc32f9a7
175 changed files with 494 additions and 410 deletions

View File

@ -136,18 +136,21 @@ configure(allprojects) { project ->
}
dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api")
testCompile("org.junit.jupiter:junit-jupiter-params")
testCompile("junit:junit:4.13-beta-3") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
testCompile("org.mockito:mockito-core:3.0.0") {
exclude group: "org.hamcrest", module: "hamcrest-core"
}
testCompile("org.mockito:mockito-junit-jupiter:3.0.0")
testCompile("io.mockk:mockk:1.9.3")
testCompile("org.hamcrest:hamcrest-all:1.3")
testCompile("org.assertj:assertj-core:3.13.1")
// Pull in the latest JUnit 5 Launcher API and the Vintage engine as well
// so that we can run JUnit 4 tests in IDEs.
// Pull in the latest JUnit 5 Launcher API to ensure proper support in IDEs.
testRuntime("org.junit.platform:junit-platform-launcher")
testRuntime("org.junit.jupiter:junit-jupiter-engine")
testRuntime("org.junit.vintage:junit-vintage-engine")
testRuntime("org.apache.logging.log4j:log4j-core:${log4jVersion}")
testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")

View File

@ -18,7 +18,7 @@ package org.springframework.core;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -28,7 +28,7 @@ import java.util.Map;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;

View File

@ -35,7 +35,7 @@ import java.util.TreeMap;
import java.util.TreeSet;
import org.assertj.core.api.Assertions;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;

View File

@ -19,7 +19,7 @@ package org.springframework.core;
import java.util.Locale;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@ -25,7 +25,7 @@ import java.util.Set;
import io.reactivex.Observable;
import io.reactivex.Single;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@ -18,7 +18,7 @@ package org.springframework.core;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -25,7 +25,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.GenericTypeResolver.getTypeVariableMap;

View File

@ -23,7 +23,7 @@ import java.lang.reflect.Method;
import java.util.Date;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.tests.sample.objects.TestObject;

View File

@ -25,8 +25,8 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.concurrent.Callable;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;
@ -50,7 +50,7 @@ public class MethodParameterTests {
private MethodParameter intReturnType;
@Before
@BeforeEach
public void setup() throws NoSuchMethodException {
method = getClass().getMethod("method", String.class, Long.TYPE);
stringParameter = new MethodParameter(method, 0);

View File

@ -19,7 +19,7 @@ package org.springframework.core;
import java.io.ByteArrayOutputStream;
import java.io.PrintWriter;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -18,7 +18,7 @@ package org.springframework.core;
import java.util.Comparator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.lang.reflect.Type;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.util.Arrays;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.tests.sample.objects.TestObject;

View File

@ -24,7 +24,7 @@ import java.util.concurrent.CompletableFuture;
import io.reactivex.Flowable;
import io.reactivex.Maybe;
import kotlinx.coroutines.Deferred;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.FluxProcessor;

View File

@ -43,11 +43,11 @@ import java.util.TreeSet;
import java.util.concurrent.Callable;
import org.assertj.core.api.AbstractAssert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.ArgumentCaptor;
import org.mockito.Captor;
import org.mockito.junit.MockitoJUnitRunner;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.core.ResolvableType.VariableResolver;
import org.springframework.util.MultiValueMap;
@ -68,7 +68,7 @@ import static org.mockito.Mockito.verify;
* @author Sebastien Deleuze
*/
@SuppressWarnings("rawtypes")
@RunWith(MockitoJUnitRunner.class)
@ExtendWith(MockitoExtension.class)
public class ResolvableTypeTests {
@Captor

View File

@ -29,7 +29,7 @@ import java.lang.reflect.TypeVariable;
import java.lang.reflect.WildcardType;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -16,7 +16,7 @@
package org.springframework.core;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -23,7 +23,7 @@ import java.nio.charset.StandardCharsets;
import java.util.Collections;
import java.util.Properties;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static java.util.Arrays.stream;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -17,8 +17,8 @@ package org.springframework.core;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.util.ReflectionUtils;
@ -33,7 +33,7 @@ import static org.assertj.core.api.Assertions.assertThat;
public class StandardReflectionParameterNameDiscoverTests {
private ParameterNameDiscoverer parameterNameDiscoverer;
@Before
@BeforeEach
public void setup() {
parameterNameDiscoverer = new StandardReflectionParameterNameDiscoverer();
}

View File

@ -34,8 +34,8 @@ import javax.annotation.ParametersAreNonnullByDefault;
import javax.annotation.Resource;
import javax.annotation.meta.When;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotationUtilsTests.ExtendsBaseClassWithGenericAnnotatedMethod;
import org.springframework.core.annotation.AnnotationUtilsTests.ImplementsInterfaceWithGenericAnnotatedMethod;
@ -384,7 +384,7 @@ public class AnnotatedElementUtilsTests {
* the first test class or the second one (with different exceptions), depending
* on the order in which the JVM returns the attribute methods via reflection.
*/
@Ignore("Permanently disabled but left in place for illustrative purposes")
@Disabled("Permanently disabled but left in place for illustrative purposes")
@Test
public void getMergedAnnotationAttributesWithHalfConventionBasedAndHalfAliasedComposedAnnotation() {
for (Class<?> clazz : asList(HalfConventionBasedAndHalfAliasedComposedContextConfigClassV1.class,

View File

@ -21,7 +21,7 @@ import java.lang.annotation.RetentionPolicy;
import java.util.Arrays;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotationUtilsTests.ImplicitAliasesContextConfig;

View File

@ -20,7 +20,7 @@ import java.util.ArrayList;
import java.util.List;
import javax.annotation.Priority;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -19,7 +19,7 @@ package org.springframework.core.annotation;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import javax.annotation.Nonnull;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.lang.Nullable;
import org.springframework.util.ObjectUtils;

View File

@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.OverridingClassLoader;
import org.springframework.util.ClassUtils;

View File

@ -30,7 +30,7 @@ import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets;
import org.springframework.core.annotation.AnnotationTypeMapping.MirrorSets.MirrorSet;

View File

@ -32,8 +32,8 @@ import java.util.Set;
import javax.annotation.Nonnull;
import javax.annotation.ParametersAreNonnullByDefault;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.subpackage.NonPublicAnnotatedClass;
@ -74,7 +74,7 @@ import static org.springframework.core.annotation.AnnotationUtils.synthesizeAnno
@SuppressWarnings("deprecation")
public class AnnotationUtilsTests {
@Before
@BeforeEach
public void clearCacheBeforeTests() {
AnnotationUtils.clearCache();
}

View File

@ -28,7 +28,7 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.lang.Nullable;

View File

@ -24,7 +24,7 @@ import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalStateException;

View File

@ -27,7 +27,7 @@ import java.util.Iterator;
import java.util.Set;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@ -21,7 +21,7 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Method;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.OverridingClassLoader;

View File

@ -25,7 +25,7 @@ import java.util.LinkedHashSet;
import java.util.Set;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotation.Adapt;
import org.springframework.util.MultiValueMap;

View File

@ -24,7 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@ -24,7 +24,7 @@ import java.util.Collections;
import java.util.List;
import java.util.Spliterator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@ -27,7 +27,7 @@ import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;
import org.springframework.util.ReflectionUtils;

View File

@ -27,7 +27,7 @@ import java.lang.reflect.AnnotatedElement;
import java.util.Set;
import org.assertj.core.api.ThrowableTypeAssert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotations.SearchStrategy;

View File

@ -36,7 +36,7 @@ import java.util.stream.Collectors;
import java.util.stream.Stream;
import javax.annotation.Resource;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.MergedAnnotation.Adapt;

View File

@ -23,7 +23,7 @@ import java.util.Map;
import java.util.NoSuchElementException;
import org.assertj.core.api.ThrowableTypeAssert;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ConcurrentReferenceHashMap;

View File

@ -26,8 +26,8 @@ import java.lang.reflect.Method;
import java.util.Iterator;
import java.util.Set;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.core.annotation.AnnotatedElementUtils.findAllMergedAnnotations;
@ -105,7 +105,7 @@ public class MultipleComposedAnnotationsOnSingleAnnotatedElementTests {
}
@Test
@Ignore("Disabled since some Java 8 updates handle the bridge method differently")
@Disabled("Disabled since some Java 8 updates handle the bridge method differently")
public void getMultipleComposedAnnotationsOnBridgeMethod() throws Exception {
Set<Cacheable> cacheables = getAllMergedAnnotations(getBridgeMethod(), Cacheable.class);
assertThat(cacheables).isNotNull();

View File

@ -21,7 +21,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.Ordered;

View File

@ -18,7 +18,7 @@ package org.springframework.core.annotation;
import javax.annotation.Priority;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -16,7 +16,7 @@
package org.springframework.core.annotation;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@ -21,7 +21,7 @@ import java.lang.annotation.Repeatable;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@ -18,8 +18,8 @@ package org.springframework.core.annotation;
import java.lang.reflect.Method;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
@ -41,7 +41,7 @@ public class SynthesizingMethodParameterTests {
private SynthesizingMethodParameter intReturnType;
@Before
@BeforeEach
public void setUp() throws NoSuchMethodException {
method = getClass().getMethod("method", String.class, Long.TYPE);
stringParameter = new SynthesizingMethodParameter(method, 0);

View File

@ -24,7 +24,7 @@ import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.time.Duration;
import java.util.Map;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@ -19,7 +19,7 @@ package org.springframework.core.codec;
import java.util.Map;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

View File

@ -19,7 +19,7 @@ package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -18,7 +18,7 @@ package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -20,7 +20,7 @@ import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -19,7 +19,7 @@ package org.springframework.core.codec;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -19,7 +19,7 @@ package org.springframework.core.codec;
import java.nio.charset.Charset;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -19,7 +19,7 @@ package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import java.util.function.Consumer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -18,7 +18,7 @@ package org.springframework.core.codec;
import java.nio.charset.StandardCharsets;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

View File

@ -20,7 +20,7 @@ import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import org.springframework.core.ResolvableType;

View File

@ -18,7 +18,7 @@ package org.springframework.core.codec;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Publisher;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

View File

@ -19,8 +19,8 @@ package org.springframework.core.codec;
import java.util.Collections;
import java.util.function.Consumer;
import org.junit.After;
import org.junit.Test;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
import org.reactivestreams.Subscription;
import reactor.core.publisher.BaseSubscriber;
import reactor.core.publisher.Flux;
@ -52,7 +52,7 @@ public class ResourceRegionEncoderTests {
private LeakAwareDataBufferFactory bufferFactory = new LeakAwareDataBufferFactory();
@After
@AfterEach
public void tearDown() throws Exception {
this.bufferFactory.checkForLeaks();
}

View File

@ -23,7 +23,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import reactor.core.publisher.Flux;
import reactor.test.StepVerifier;

View File

@ -36,7 +36,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.util.LinkedMultiValueMap;

View File

@ -23,7 +23,7 @@ import java.util.LinkedHashMap;
import java.util.Map;
import java.util.Map.Entry;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionService;
import org.springframework.core.convert.support.DefaultConversionService;

View File

@ -44,7 +44,7 @@ import java.util.TimeZone;
import java.util.UUID;
import java.util.stream.Stream;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.core.convert.ConversionFailedException;

View File

@ -18,8 +18,8 @@ package org.springframework.core.convert.support;
import java.nio.ByteBuffer;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.converter.Converter;
@ -40,7 +40,7 @@ public class ByteBufferConverterTests {
private GenericConversionService conversionService;
@Before
@BeforeEach
public void setup() {
this.conversionService = new DefaultConversionService();
this.conversionService.addConverter(new ByteArrayToOtherTypeConverter());

View File

@ -30,8 +30,8 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Vector;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
@ -53,7 +53,7 @@ public class CollectionToCollectionConverterTests {
private GenericConversionService conversionService = new GenericConversionService();
@Before
@BeforeEach
public void setUp() {
conversionService.addConverter(new CollectionToCollectionConverter(conversionService));
}

View File

@ -32,7 +32,7 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;

View File

@ -24,8 +24,8 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
@ -46,7 +46,7 @@ public class MapToMapConverterTests {
private final GenericConversionService conversionService = new GenericConversionService();
@Before
@BeforeEach
public void setUp() {
conversionService.addConverter(new MapToMapConverter(conversionService));
}

View File

@ -20,8 +20,8 @@ import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConversionFailedException;
import org.springframework.core.convert.ConverterNotFoundException;
@ -45,7 +45,7 @@ public class StreamConverterTests {
private final StreamConverter streamConverter = new StreamConverter(this.conversionService);
@Before
@BeforeEach
public void setup() {
this.conversionService.addConverter(new CollectionToCollectionConverter(this.conversionService));
this.conversionService.addConverter(new ArrayToCollectionConverter(this.conversionService));

View File

@ -18,7 +18,7 @@ package org.springframework.core.env;
import java.util.Collections;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,7 +20,7 @@ import java.util.Arrays;
import joptsimple.OptionParser;
import joptsimple.OptionSet;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -18,7 +18,7 @@ package org.springframework.core.env;
import java.util.Iterator;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.mock.env.MockPropertySource;

View File

@ -21,7 +21,7 @@ import java.util.List;
import java.util.function.Predicate;
import java.util.function.Supplier;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.StringUtils;

View File

@ -22,7 +22,7 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -20,8 +20,8 @@ import java.util.HashMap;
import java.util.Map;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.core.convert.ConverterNotFoundException;
import org.springframework.mock.env.MockPropertySource;
@ -44,7 +44,7 @@ public class PropertySourcesPropertyResolverTests {
private ConfigurablePropertyResolver propertyResolver;
@Before
@BeforeEach
public void setUp() {
propertySources = new MutablePropertySources();
propertyResolver = new PropertySourcesPropertyResolver(propertySources);

View File

@ -19,7 +19,7 @@ package org.springframework.core.env;
import java.util.Collections;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@ -18,7 +18,7 @@ package org.springframework.core.env;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -23,7 +23,7 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.SpringProperties;
import org.springframework.mock.env.MockPropertySource;

View File

@ -21,8 +21,8 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
@ -41,7 +41,7 @@ public class SystemEnvironmentPropertySourceTests {
private PropertySource<?> ps;
@Before
@BeforeEach
public void setUp() {
envMap = new HashMap<>();
ps = new SystemEnvironmentPropertySource("sysEnv", envMap);

View File

@ -20,7 +20,7 @@ import java.io.FileNotFoundException;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;

View File

@ -25,12 +25,12 @@ import java.nio.channels.ReadableByteChannel;
import java.nio.channels.WritableByteChannel;
import java.nio.charset.StandardCharsets;
import java.nio.file.AccessDeniedException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.io.TempDir;
import org.springframework.util.FileCopyUtils;
@ -68,10 +68,6 @@ public class PathResourceTests {
}
@Rule
public TemporaryFolder temporaryFolder = new TemporaryFolder();
@Test
public void nullPath() {
assertThatIllegalArgumentException().isThrownBy(() ->
@ -270,15 +266,15 @@ public class PathResourceTests {
}
@Test
public void outputStream() throws IOException {
PathResource resource = new PathResource(temporaryFolder.newFile("test").toPath());
public void outputStream(@TempDir Path temporaryFolder) throws IOException {
PathResource resource = new PathResource(temporaryFolder.resolve("test"));
FileCopyUtils.copy("test".getBytes(StandardCharsets.UTF_8), resource.getOutputStream());
assertThat(resource.contentLength()).isEqualTo(4L);
}
@Test
public void doesNotExistOutputStream() throws IOException {
File file = temporaryFolder.newFile("test");
public void doesNotExistOutputStream(@TempDir Path temporaryFolder) throws IOException {
File file = temporaryFolder.resolve("test").toFile();
file.delete();
PathResource resource = new PathResource(file.toPath());
FileCopyUtils.copy("test".getBytes(), resource.getOutputStream());
@ -329,8 +325,10 @@ public class PathResourceTests {
}
@Test
public void getWritableChannel() throws IOException {
PathResource resource = new PathResource(temporaryFolder.newFile("test").toPath());
public void getWritableChannel(@TempDir Path temporaryFolder) throws IOException {
Path testPath = temporaryFolder.resolve("test");
Files.createFile(testPath);
PathResource resource = new PathResource(testPath);
ByteBuffer buffer = ByteBuffer.wrap("test".getBytes(StandardCharsets.UTF_8));
WritableByteChannel channel = null;
try {

View File

@ -18,7 +18,7 @@ package org.springframework.core.io;
import java.beans.PropertyEditor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.StandardEnvironment;

View File

@ -28,7 +28,7 @@ import java.nio.file.Paths;
import java.util.HashSet;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.FileCopyUtils;

View File

@ -16,7 +16,7 @@
package org.springframework.core.io.buffer;
import org.junit.After;
import org.junit.jupiter.api.AfterEach;
/**
* Abstract base class for unit tests that allocate data buffers via a {@link DataBufferFactory}.
@ -39,7 +39,7 @@ public abstract class AbstractLeakCheckingTestCase {
* Checks whether any of the data buffers created by {@link #bufferFactory} have not been
* released, throwing an assertion error if so.
*/
@After
@AfterEach
public final void checkForLeaks() {
this.bufferFactory.checkForLeaks();
}

View File

@ -27,16 +27,16 @@ import io.netty.buffer.PooledByteBufAllocator;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jetbrains.annotations.NotNull;
import org.junit.After;
import org.springframework.util.Assert;
/**
* Implementation of the {@code DataBufferFactory} interface that keep track of memory leaks.
* Useful for unit tests that handle data buffers. Simply inherit from
* Implementation of the {@code DataBufferFactory} interface that keeps track of
* memory leaks.
* <p>Useful for unit tests that handle data buffers. Simply inherit from
* {@link AbstractLeakCheckingTestCase} or call {@link #checkForLeaks()} in
* a JUnit {@link After} method yourself, and any buffers have not been released will result in an
* {@link AssertionError}.
* a JUnit <em>after</em> method yourself, and any buffers that have not been
* released will result in an {@link AssertionError}.
*
* @author Arjen Poutsma
* @see LeakAwareDataBufferFactory
@ -71,7 +71,7 @@ public class LeakAwareDataBufferFactory implements DataBufferFactory {
/**
* Checks whether all of the data buffers allocated by this factory have also been released.
* If not, then an {@link AssertionError} is thrown. Typically used from a JUnit {@link After}
* If not, then an {@link AssertionError} is thrown. Typically used from a JUnit <em>after</em>
* method.
*/
public void checkForLeaks() {

View File

@ -16,7 +16,7 @@
package org.springframework.core.io.buffer;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.springframework.core.io.buffer.DataBufferUtils.release;

View File

@ -18,7 +18,7 @@ package org.springframework.core.io.support;
import java.nio.charset.Charset;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.DescriptiveResource;
import org.springframework.core.io.Resource;

View File

@ -22,8 +22,8 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.Resource;
import org.springframework.util.StringUtils;
@ -79,7 +79,7 @@ public class PathMatchingResourcePatternResolverTests {
assertProtocolAndFilenames(resources, "jar", "Publisher.class");
}
@Ignore // passes under Eclipse, fails under Ant
@Disabled
@Test
public void classpathStarWithPatternOnFileSystem() throws IOException {
Resource[] resources = resolver.getResources("classpath*:org/springframework/core/io/sup*/*.class");

View File

@ -18,7 +18,7 @@ package org.springframework.core.io.support;
import java.beans.PropertyEditor;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.StandardEnvironment;
import org.springframework.core.io.Resource;

View File

@ -18,7 +18,7 @@ package org.springframework.core.io.support;
import java.io.IOException;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.env.PropertySource;
import org.springframework.core.io.ByteArrayResource;

View File

@ -16,7 +16,7 @@
package org.springframework.core.io.support;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.io.Resource;

View File

@ -19,7 +19,7 @@ package org.springframework.core.io.support;
import java.lang.reflect.Modifier;
import java.util.List;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatIllegalArgumentException;

View File

@ -16,7 +16,7 @@
package org.springframework.core.log;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -19,7 +19,7 @@ package org.springframework.core.serializer;
import java.io.NotSerializableException;
import java.io.Serializable;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.serializer.support.DeserializingConverter;
import org.springframework.core.serializer.support.SerializationFailedException;

View File

@ -24,7 +24,7 @@ import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -23,8 +23,8 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.util.ObjectUtils;
@ -38,7 +38,7 @@ public class ToStringCreatorTests {
private SomeObject s1, s2, s3;
@Before
@BeforeEach
public void setUp() throws Exception {
s1 = new SomeObject() {
@Override

View File

@ -18,7 +18,7 @@ package org.springframework.core.task;
import java.util.concurrent.ThreadFactory;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.util.ConcurrencyThrottleSupport;

View File

@ -19,7 +19,7 @@ package org.springframework.core.type;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.core.type.AbstractAnnotationMetadataTests.TestMemberClass.TestMemberClassInnerClass;

View File

@ -16,7 +16,7 @@
package org.springframework.core.type;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import static org.assertj.core.api.Assertions.assertThat;

View File

@ -19,7 +19,7 @@ package org.springframework.core.type;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.MergedAnnotation;
import org.springframework.util.MultiValueMap;

View File

@ -29,7 +29,7 @@ import java.util.HashSet;
import java.util.List;
import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import org.springframework.core.annotation.AliasFor;
import org.springframework.core.annotation.AnnotationAttributes;

Some files were not shown because too many files have changed in this diff Show More