Remove JUnit 4 dependency from all modules except spring-test

This commit removes the JUnit 4 dependency from all modules except
spring-test which provides explicit JUnit 4 support.

This commit also includes the following.

- migration from JUnit 4 assertions to JUnit Jupiter assertions in all
  Kotlin tests
- migration from JUnit 4 assumptions in Spring's TestGroup support to
  JUnit Jupiter assumptions, based on org.opentest4j.TestAbortedException
- introduction of a new TestGroups utility class than can be used from
  existing JUnit 4 tests in the spring-test module in order to perform
  assumptions using JUnit 4's Assume class

See gh-23451
This commit is contained in:
Sam Brannen 2019-08-15 11:52:19 +02:00
parent 3f3e41923f
commit 979508a7f3
43 changed files with 159 additions and 111 deletions

View File

@ -138,9 +138,6 @@ configure(allprojects) { project ->
dependencies { dependencies {
testCompile("org.junit.jupiter:junit-jupiter-api") testCompile("org.junit.jupiter:junit-jupiter-api")
testCompile("org.junit.jupiter:junit-jupiter-params") 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") { testCompile("org.mockito:mockito-core:3.0.0") {
exclude group: "org.hamcrest", module: "hamcrest-core" exclude group: "org.hamcrest", module: "hamcrest-core"
} }
@ -151,7 +148,6 @@ configure(allprojects) { project ->
// Pull in the latest JUnit 5 Launcher API to ensure proper support 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.platform:junit-platform-launcher")
testRuntime("org.junit.jupiter:junit-jupiter-engine") 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-core:${log4jVersion}")
testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}") testRuntime("org.apache.logging.log4j:log4j-slf4j-impl:${log4jVersion}")
testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}") testRuntime("org.apache.logging.log4j:log4j-jul:${log4jVersion}")

View File

@ -26,7 +26,7 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory;
import org.springframework.beans.factory.support.RootBeanDefinition; import org.springframework.beans.factory.support.RootBeanDefinition;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* @author Juergen Hoeller * @author Juergen Hoeller

View File

@ -16,7 +16,7 @@
package org.springframework.beans package org.springframework.beans
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
/** /**

View File

@ -22,7 +22,8 @@ import org.springframework.beans.factory.support.DefaultListableBeanFactory
import org.springframework.beans.factory.support.RootBeanDefinition import org.springframework.beans.factory.support.RootBeanDefinition
import org.springframework.tests.sample.beans.TestBean import org.springframework.tests.sample.beans.TestBean
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import org.springframework.beans.factory.BeanCreationException import org.springframework.beans.factory.BeanCreationException
import org.springframework.tests.sample.beans.Colour import org.springframework.tests.sample.beans.Colour

View File

@ -16,7 +16,7 @@
package org.springframework.context.annotation package org.springframework.context.annotation
import org.junit.Assert.assertNotNull import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.getBean import org.springframework.beans.factory.getBean
import org.springframework.context.support.registerBean import org.springframework.context.support.registerBean

View File

@ -16,7 +16,8 @@
package org.springframework.context.annotation package org.springframework.context.annotation
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.getBean import org.springframework.beans.factory.getBean
import org.springframework.beans.factory.parsing.BeanDefinitionParsingException import org.springframework.beans.factory.parsing.BeanDefinitionParsingException

View File

@ -16,7 +16,7 @@
package org.springframework.context.annotation package org.springframework.context.annotation
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.BeanFactory import org.springframework.beans.factory.BeanFactory
import org.springframework.beans.factory.getBean import org.springframework.beans.factory.getBean

View File

@ -16,7 +16,10 @@
package org.springframework.context.support package org.springframework.context.support
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.NoSuchBeanDefinitionException import org.springframework.beans.factory.NoSuchBeanDefinitionException
import org.springframework.beans.factory.getBean import org.springframework.beans.factory.getBean
@ -28,7 +31,7 @@ import java.util.stream.Collectors
@Suppress("UNUSED_EXPRESSION") @Suppress("UNUSED_EXPRESSION")
class BeanDefinitionDslTests { class BeanDefinitionDslTests {
@Test @Test
fun `Declare beans with the functional Kotlin DSL`() { fun `Declare beans with the functional Kotlin DSL`() {
val beans = beans { val beans = beans {
@ -193,12 +196,12 @@ class BeanDefinitionDslTests {
try { try {
context.getBean<Foo>() context.getBean<Foo>()
fail() fail("should have thrown an Exception")
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
try { try {
context.getBean<FooFoo>() context.getBean<FooFoo>()
fail() fail("should have thrown an Exception")
} catch (ignored: Exception) { } catch (ignored: Exception) {
} }
} }

View File

@ -16,7 +16,7 @@
package org.springframework.context.support package org.springframework.context.support
import org.junit.Assert.assertNotNull import org.junit.jupiter.api.Assertions.assertNotNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.beans.factory.getBean import org.springframework.beans.factory.getBean

View File

@ -16,8 +16,8 @@
package org.springframework.ui package org.springframework.ui
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
/** /**

View File

@ -16,8 +16,8 @@
package org.springframework.ui package org.springframework.ui
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
/** /**

View File

@ -27,7 +27,7 @@ import java.nio.file.Path;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.util.HashSet; import java.util.HashSet;
import org.junit.Ignore; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.springframework.util.FileCopyUtils; import org.springframework.util.FileCopyUtils;
@ -218,7 +218,8 @@ public class ResourceTests {
assertThat(relative).isEqualTo(new UrlResource("file:dir/subdir")); assertThat(relative).isEqualTo(new UrlResource("file:dir/subdir"));
} }
@Ignore @Test // this test is quite slow. TODO: re-enable with JUnit categories @Disabled
@Test // this test is quite slow. TODO: re-enable with JUnit categories
public void testNonFileResourceExists() throws Exception { public void testNonFileResourceExists() throws Exception {
Resource resource = new UrlResource("https://www.springframework.org"); Resource resource = new UrlResource("https://www.springframework.org");
assertThat(resource.exists()).isTrue(); assertThat(resource.exists()).isTrue();

View File

@ -19,14 +19,14 @@ package org.springframework.tests;
import java.util.Set; import java.util.Set;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.junit.AssumptionViolatedException;
import static org.junit.Assume.assumeFalse; import static org.junit.jupiter.api.Assumptions.assumeFalse;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* Provides utility methods that allow JUnit tests to {@link org.junit.Assume} certain * Provides utility methods that allow JUnit tests to assume certain conditions
* conditions hold {@code true}. If the assumption fails, it means the test should be * hold {@code true}. If the assumption fails, it means the test should be
* skipped. * aborted.
* *
* <p>Tests can be categorized into {@link TestGroup}s. Active groups are enabled using * <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: * the 'testGroups' system property, usually activated from the gradle command line:
@ -35,8 +35,8 @@ import static org.junit.Assume.assumeFalse;
* gradle test -PtestGroups="performance" * gradle test -PtestGroups="performance"
* </pre> * </pre>
* *
* <p>Groups can be specified as a comma separated list of values, or using the pseudo group * <p>Groups can be activated as a comma separated list of values, or using the
* 'all'. See {@link TestGroup} for a list of valid groups. * pseudo group 'all'. See {@link TestGroup} for a list of valid groups.
* *
* @author Rob Winch * @author Rob Winch
* @author Phillip Webb * @author Phillip Webb
@ -44,6 +44,8 @@ import static org.junit.Assume.assumeFalse;
* @since 3.2 * @since 3.2
* @see #group(TestGroup) * @see #group(TestGroup)
* @see #group(TestGroup, Executable) * @see #group(TestGroup, Executable)
* @see TestGroup
* @see TestGroups
*/ */
public abstract class Assume { public abstract class Assume {
@ -51,29 +53,27 @@ public abstract class Assume {
/** /**
* Assume that a particular {@link TestGroup} has been specified. * Assume that a particular {@link TestGroup} is active.
* @param group the group that must be specified * @param group the group that must be active
* @throws AssumptionViolatedException if the assumption fails * @throws org.opentest4j.TestAbortedException if the assumption fails
*/ */
public static void group(TestGroup group) { public static void group(TestGroup group) {
Set<TestGroup> testGroups = loadTestGroups(); Set<TestGroup> testGroups = TestGroups.loadTestGroups();
if (!testGroups.contains(group)) { assumeTrue(testGroups.contains(group),
throw new AssumptionViolatedException("Requires unspecified group " + group + " from " + testGroups); () -> "Requires inactive test group " + group + "; active test groups: " + testGroups);
}
} }
/** /**
* Assume that a particular {@link TestGroup} has been specified before * Assume that a particular {@link TestGroup} is active before executing the
* executing the supplied {@link Executable}. * supplied {@link Executable}.
* <p>If the assumption fails, the executable will not be executed, but * <p>If the assumption fails, the executable will not be executed, but
* no {@link AssumptionViolatedException} will be thrown. * no {@link org.opentest4j.TestAbortedException} will be thrown.
* @param group the group that must be specified * @param group the group that must be active
* @param executable the executable to execute if the test group is active * @param executable the executable to execute if the test group is active
* @since 4.2 * @since 4.2
*/ */
public static void group(TestGroup group, Executable executable) throws Exception { public static void group(TestGroup group, Executable executable) throws Exception {
Set<TestGroup> testGroups = loadTestGroups(); if (TestGroups.loadTestGroups().contains(group)) {
if (testGroups.contains(group)) {
executable.execute(); executable.execute();
} }
} }
@ -81,28 +81,13 @@ public abstract class Assume {
/** /**
* Assume that the specified log is not set to Trace or Debug. * Assume that the specified log is not set to Trace or Debug.
* @param log the log to test * @param log the log to test
* @throws AssumptionViolatedException if the assumption fails * @throws org.opentest4j.TestAbortedException if the assumption fails
*/ */
public static void notLogging(Log log) { public static void notLogging(Log log) {
assumeFalse(log.isTraceEnabled()); assumeFalse(log.isTraceEnabled());
assumeFalse(log.isDebugEnabled()); assumeFalse(log.isDebugEnabled());
} }
/**
* Load test groups dynamically instead of during static
* initialization in order to avoid a {@link NoClassDefFoundError}
* being thrown while attempting to load the {@code Assume} class.
*/
private static Set<TestGroup> loadTestGroups() {
try {
return TestGroup.parse(System.getProperty(TEST_GROUPS_SYSTEM_PROPERTY));
}
catch (Exception ex) {
throw new IllegalStateException("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY
+ "' system property: " + ex.getMessage(), ex);
}
}
/** /**
* @since 4.2 * @since 4.2

View File

@ -18,10 +18,10 @@ package org.springframework.tests;
import java.util.Arrays; import java.util.Arrays;
import org.junit.AssumptionViolatedException;
import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.opentest4j.TestAbortedException;
import static java.util.stream.Collectors.joining; import static java.util.stream.Collectors.joining;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -77,7 +77,7 @@ public class AssumeTests {
try { try {
Assume.group(LONG_RUNNING); Assume.group(LONG_RUNNING);
} }
catch (AssumptionViolatedException ex) { catch (TestAbortedException ex) {
fail("assumption should NOT have failed"); fail("assumption should NOT have failed");
} }
} }

View File

@ -0,0 +1,58 @@
/*
* 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;
/**
* Utility methods for working with {@link TestGroup}s.
*
* @author Sam Brannen
* @author Rob Winch
* @author Phillip Webb
* @since 5.2
*/
public abstract class TestGroups {
static final String TEST_GROUPS_SYSTEM_PROPERTY = "testGroups";
/**
* Determine if the provided {@link TestGroup} is active.
* @param group the group to check
* @since 5.2
*/
public static boolean isGroupActive(TestGroup group) {
return loadTestGroups().contains(group);
}
/**
* Load test groups dynamically instead of during static initialization in
* order to avoid a {@link NoClassDefFoundError} being thrown while attempting
* to load the {@link Assume} class.
*/
static Set<TestGroup> loadTestGroups() {
try {
return TestGroup.parse(System.getProperty(TEST_GROUPS_SYSTEM_PROPERTY));
}
catch (Exception ex) {
throw new IllegalStateException("Failed to parse '" + TEST_GROUPS_SYSTEM_PROPERTY
+ "' system property: " + ex.getMessage(), ex);
}
}
}

View File

@ -16,7 +16,7 @@
package org.springframework.core package org.springframework.core
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
class KotlinDefaultParameterNameDiscovererTests { class KotlinDefaultParameterNameDiscovererTests {

View File

@ -16,7 +16,7 @@
package org.springframework.core package org.springframework.core
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.GenericTypeResolver.resolveReturnTypeArgument import org.springframework.core.GenericTypeResolver.resolveReturnTypeArgument
import java.lang.reflect.Method import java.lang.reflect.Method

View File

@ -16,9 +16,9 @@
package org.springframework.core package org.springframework.core
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertFalse import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.Assert.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import java.lang.reflect.Method import java.lang.reflect.Method
import java.lang.reflect.TypeVariable import java.lang.reflect.TypeVariable

View File

@ -24,9 +24,9 @@ import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.Assert.fail import org.junit.jupiter.api.Assertions.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import reactor.core.publisher.Flux import reactor.core.publisher.Flux
@ -44,7 +44,7 @@ class KotlinReactiveAdapterRegistryTests {
fun deferredToPublisher() { fun deferredToPublisher() {
val source = GlobalScope.async { 1 } val source = GlobalScope.async { 1 }
val target: Publisher<Int> = getAdapter(Deferred::class).toPublisher(source) val target: Publisher<Int> = getAdapter(Deferred::class).toPublisher(source)
assertTrue("Expected Mono Publisher: " + target.javaClass.name, target is Mono<*>) assertTrue(target is Mono<*>, "Expected Mono Publisher: " + target.javaClass.name)
assertEquals(1, (target as Mono<Int>).block(Duration.ofMillis(1000))) assertEquals(1, (target as Mono<Int>).block(Duration.ofMillis(1000)))
} }
@ -54,7 +54,6 @@ class KotlinReactiveAdapterRegistryTests {
val target = getAdapter(Deferred::class).fromPublisher(source) val target = getAdapter(Deferred::class).fromPublisher(source)
assertTrue(target is Deferred<*>) assertTrue(target is Deferred<*>)
assertEquals(1, runBlocking { (target as Deferred<*>).await() }) assertEquals(1, runBlocking { (target as Deferred<*>).await() })
} }
@Test @Test
@ -65,7 +64,7 @@ class KotlinReactiveAdapterRegistryTests {
emit(3) emit(3)
} }
val target: Publisher<Int> = getAdapter(Flow::class).toPublisher(source) val target: Publisher<Int> = getAdapter(Flow::class).toPublisher(source)
assertTrue("Expected Flux Publisher: " + target.javaClass.name, target is Flux<*>) assertTrue(target is Flux<*>, "Expected Flux Publisher: " + target.javaClass.name)
StepVerifier.create(target) StepVerifier.create(target)
.expectNext(1) .expectNext(1)
.expectNext(2) .expectNext(2)

View File

@ -21,8 +21,8 @@ import java.sql.*
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertNull import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
/** /**

View File

@ -18,7 +18,7 @@ package org.springframework.jdbc.core.namedparam
import java.sql.JDBCType import java.sql.JDBCType
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
/** /**

View File

@ -6,7 +6,7 @@ import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.toList import kotlinx.coroutines.flow.toList
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.mockito.ArgumentMatchers.anyInt import org.mockito.ArgumentMatchers.anyInt
import org.reactivestreams.Publisher import org.reactivestreams.Publisher

View File

@ -36,7 +36,7 @@ import org.springframework.messaging.simp.SimpMessagingTemplate
import org.springframework.messaging.support.MessageBuilder import org.springframework.messaging.support.MessageBuilder
import org.springframework.stereotype.Controller import org.springframework.stereotype.Controller
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.springframework.messaging.MessageHandlingException import org.springframework.messaging.MessageHandlingException
import org.springframework.messaging.handler.annotation.MessageExceptionHandler import org.springframework.messaging.handler.annotation.MessageExceptionHandler

View File

@ -79,6 +79,7 @@ dependencies {
testCompile("io.projectreactor.netty:reactor-netty") testCompile("io.projectreactor.netty:reactor-netty")
testCompile("de.bechte.junit:junit-hierarchicalcontextrunner:4.12.1") testCompile("de.bechte.junit:junit-hierarchicalcontextrunner:4.12.1")
testRuntime("org.junit.jupiter:junit-jupiter-engine") testRuntime("org.junit.jupiter:junit-jupiter-engine")
testRuntime("org.junit.vintage:junit-vintage-engine")
testRuntime("org.glassfish:javax.el:3.0.1-b08") testRuntime("org.glassfish:javax.el:3.0.1-b08")
testRuntime("com.sun.xml.bind:jaxb-core:2.3.0.1") testRuntime("com.sun.xml.bind:jaxb-core:2.3.0.1")
testRuntime("com.sun.xml.bind:jaxb-impl:2.3.0.1") testRuntime("com.sun.xml.bind:jaxb-impl:2.3.0.1")

View File

@ -40,10 +40,11 @@ import org.springframework.test.context.web.socket.WebSocketServletServerContain
import org.springframework.test.web.client.samples.SampleTests; import org.springframework.test.web.client.samples.SampleTests;
import org.springframework.test.web.servlet.samples.context.JavaConfigTests; import org.springframework.test.web.servlet.samples.context.JavaConfigTests;
import org.springframework.test.web.servlet.samples.context.WebAppResourceTests; import org.springframework.test.web.servlet.samples.context.WebAppResourceTests;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.tests.TestGroups;
import org.springframework.util.ReflectionUtils; import org.springframework.util.ReflectionUtils;
import static org.junit.Assume.assumeTrue;
import static org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation; import static org.springframework.core.annotation.AnnotatedElementUtils.hasAnnotation;
import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters; import static org.springframework.test.context.junit4.JUnitTestingUtils.runTestsAndAssertCounters;
@ -97,7 +98,8 @@ public class SpringJUnit4ConcurrencyTests {
@BeforeClass @BeforeClass
public static void abortIfLongRunningTestGroupIsNotEnabled() { public static void abortIfLongRunningTestGroupIsNotEnabled() {
Assume.group(TestGroup.LONG_RUNNING); assumeTrue("TestGroup " + TestGroup.LONG_RUNNING + " is not active.",
TestGroups.isGroupActive(TestGroup.LONG_RUNNING));
} }
@Test @Test

View File

@ -36,10 +36,11 @@ import org.springframework.stereotype.Controller;
import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection; import org.springframework.test.web.servlet.htmlunit.DelegatingWebConnection.DelegateWebConnection;
import org.springframework.test.web.servlet.setup.MockMvcBuilders; import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import org.springframework.tests.Assume;
import org.springframework.tests.TestGroup; import org.springframework.tests.TestGroup;
import org.springframework.tests.TestGroups;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.Assume.assumeTrue;
import static org.mockito.BDDMockito.given; import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions; import static org.mockito.Mockito.verifyNoMoreInteractions;
@ -125,7 +126,8 @@ public class DelegatingWebConnectionTests {
@Test @Test
public void verifyExampleInClassLevelJavadoc() throws Exception { public void verifyExampleInClassLevelJavadoc() throws Exception {
Assume.group(TestGroup.PERFORMANCE); assumeTrue("TestGroup " + TestGroup.PERFORMANCE + " is not active.",
TestGroups.isGroupActive(TestGroup.PERFORMANCE));
WebClient webClient = new WebClient(); WebClient webClient = new WebClient();

View File

@ -20,7 +20,7 @@ import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Test import org.junit.Test
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference

View File

@ -17,8 +17,8 @@
package org.springframework.test.web.servlet package org.springframework.test.web.servlet
import org.hamcrest.CoreMatchers import org.hamcrest.CoreMatchers
import org.junit.Assert import org.junit.jupiter.api.Assertions.*
import org.junit.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows import org.junit.jupiter.api.assertThrows
import org.springframework.http.HttpMethod import org.springframework.http.HttpMethod
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus
@ -81,8 +81,8 @@ class MockMvcExtensionsTests {
}.andDo { }.andDo {
handle(handler) handle(handler)
} }
Assert.assertTrue(matcherInvoked) assertTrue(matcherInvoked)
Assert.assertTrue(handlerInvoked) assertTrue(handlerInvoked)
} }
@Test @Test

View File

@ -19,8 +19,7 @@ package org.springframework.web.client
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import org.junit.Assert import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.* import org.springframework.http.*
@ -277,9 +276,9 @@ class RestOperationsExtensionsTests {
if (method.parameterTypes.contains(kClass.java)) { if (method.parameterTypes.contains(kClass.java)) {
val parameters = mutableListOf<Class<*>>(RestOperations::class.java).apply { addAll(method.parameterTypes.filter { it != kClass.java }) } val parameters = mutableListOf<Class<*>>(RestOperations::class.java).apply { addAll(method.parameterTypes.filter { it != kClass.java }) }
val f = extensions.getDeclaredMethod(method.name, *parameters.toTypedArray()).kotlinFunction!! val f = extensions.getDeclaredMethod(method.name, *parameters.toTypedArray()).kotlinFunction!!
Assert.assertEquals(1, f.typeParameters.size) assertEquals(1, f.typeParameters.size)
System.out.println(method.name + f.typeParameters) System.out.println(method.name + f.typeParameters)
Assert.assertEquals("Failed: " + method.name, listOf(Any::class.createType(nullable = true)), f.typeParameters[0].upperBounds) assertEquals(listOf(Any::class.createType(nullable = true)), f.typeParameters[0].upperBounds, "Failed: " + method.name)
} }
} }
} }

View File

@ -16,9 +16,9 @@
package org.springframework.web.method.annotation package org.springframework.web.method.annotation
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertNull import org.junit.jupiter.api.Assertions.assertNull
import org.junit.Assert.fail import org.junit.jupiter.api.fail
import org.junit.jupiter.api.BeforeEach import org.junit.jupiter.api.BeforeEach
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.MethodParameter import org.springframework.core.MethodParameter

View File

@ -21,8 +21,8 @@ import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertNull import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus

View File

@ -22,7 +22,7 @@ import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference

View File

@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server package org.springframework.web.reactive.function.server
import org.junit.Assert.fail import org.junit.jupiter.api.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.io.ClassPathResource import org.springframework.core.io.ClassPathResource
import org.springframework.http.HttpHeaders.* import org.springframework.http.HttpHeaders.*

View File

@ -16,7 +16,7 @@
package org.springframework.web.reactive.function.server package org.springframework.web.reactive.function.server
import org.junit.Assert.fail import org.junit.jupiter.api.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.io.ClassPathResource import org.springframework.core.io.ClassPathResource
import org.springframework.http.HttpHeaders.* import org.springframework.http.HttpHeaders.*

View File

@ -21,8 +21,8 @@ import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertNull import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.codec.multipart.Part import org.springframework.http.codec.multipart.Part

View File

@ -23,7 +23,7 @@ import io.reactivex.Flowable
import kotlinx.coroutines.ExperimentalCoroutinesApi import kotlinx.coroutines.ExperimentalCoroutinesApi
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.runBlocking import kotlinx.coroutines.runBlocking
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.reactivestreams.Publisher import org.reactivestreams.Publisher
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference

View File

@ -21,7 +21,7 @@ import io.mockk.mockk
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import org.hamcrest.CoreMatchers.`is` import org.hamcrest.CoreMatchers.`is`
import org.hamcrest.MatcherAssert.assertThat import org.hamcrest.MatcherAssert.assertThat
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.http.HttpStatus import org.springframework.http.HttpStatus
import org.springframework.http.server.reactive.ServerHttpResponse import org.springframework.http.server.reactive.ServerHttpResponse

View File

@ -23,8 +23,8 @@ import kotlinx.coroutines.async
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow import kotlinx.coroutines.flow.flow
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.fail import org.junit.jupiter.api.fail
import org.springframework.context.ApplicationContext import org.springframework.context.ApplicationContext
import org.springframework.context.annotation.AnnotationConfigApplicationContext import org.springframework.context.annotation.AnnotationConfigApplicationContext
import org.springframework.context.annotation.ComponentScan import org.springframework.context.annotation.ComponentScan

View File

@ -34,7 +34,7 @@ import org.springframework.web.servlet.View;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
import static org.junit.Assume.assumeTrue; import static org.junit.jupiter.api.Assumptions.assumeTrue;
/** /**
* @author Rod Johnson * @author Rod Johnson

View File

@ -16,9 +16,9 @@
package org.springframework.web.servlet.function package org.springframework.web.servlet.function
import org.junit.Assert.assertFalse import org.junit.jupiter.api.Assertions.assertFalse
import org.junit.Assert.assertTrue import org.junit.jupiter.api.Assertions.assertTrue
import org.junit.Assert.fail import org.junit.jupiter.api.fail
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.io.ClassPathResource import org.springframework.core.io.ClassPathResource
import org.springframework.http.HttpHeaders.* import org.springframework.http.HttpHeaders.*

View File

@ -19,8 +19,8 @@ package org.springframework.web.servlet.function
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.Assert.assertNull import org.junit.jupiter.api.Assertions.assertNull
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import org.springframework.http.MediaType import org.springframework.http.MediaType

View File

@ -19,10 +19,10 @@ package org.springframework.web.servlet.function
import io.mockk.every import io.mockk.every
import io.mockk.mockk import io.mockk.mockk
import io.mockk.verify import io.mockk.verify
import org.junit.Assert
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.core.ParameterizedTypeReference import org.springframework.core.ParameterizedTypeReference
import java.util.* import java.util.*
import org.junit.jupiter.api.Assertions.assertEquals
/** /**
* Tests for WebMvc.fn [ServerResponse] extensions. * Tests for WebMvc.fn [ServerResponse] extensions.
@ -38,7 +38,7 @@ class ServerResponseExtensionsTests {
val body = Arrays.asList("foo", "bar") val body = Arrays.asList("foo", "bar")
val typeReference = object: ParameterizedTypeReference<List<String>>() {} val typeReference = object: ParameterizedTypeReference<List<String>>() {}
every { builder.body(body, typeReference) } returns response every { builder.body(body, typeReference) } returns response
Assert.assertEquals(response, builder.bodyWithType<List<String>>(body)) assertEquals(response, builder.bodyWithType<List<String>>(body))
verify { builder.body(body, typeReference) } verify { builder.body(body, typeReference) }
} }
} }

View File

@ -16,7 +16,7 @@
package org.springframework.web.servlet.mvc.method.annotation package org.springframework.web.servlet.mvc.method.annotation
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test import org.junit.jupiter.api.Test
import org.springframework.mock.web.test.MockHttpServletRequest import org.springframework.mock.web.test.MockHttpServletRequest
import org.springframework.mock.web.test.MockHttpServletResponse import org.springframework.mock.web.test.MockHttpServletResponse