ENT-3422: Upgrade DJVM to use JUnit 5. (#5131)

* Switch to JUnit 5's migration support.

* Upgrade to Gradle 5.4.1.

* Upgrade to JUnit 5 Jupiter.
This commit is contained in:
Chris Rankin 2019-05-20 09:11:21 +01:00 committed by Rick Parker
parent 0eab42b63e
commit 5ca409d139
30 changed files with 79 additions and 66 deletions

View File

@ -1,7 +1,7 @@
buildscript {
ext {
corda_djvm_version = '5.0-SNAPSHOT'
artifactory_contextUrl = 'https://ci-artifactory.corda.r3cev.com/artifactory'
artifactory_contextUrl = 'https://software.r3.com/artifactory'
}
repositories {
@ -14,7 +14,7 @@ buildscript {
}
plugins {
id 'net.corda.plugins.publish-utils' version '4.0.42' apply false
id 'net.corda.plugins.publish-utils' version '4.0.44' apply false
id 'com.github.johnrengelman.shadow' version '5.0.0' apply false
id 'com.jfrog.artifactory' version '4.7.3' apply false
id 'com.jfrog.bintray' version '1.4' apply false
@ -57,6 +57,8 @@ subprojects {
}
tasks.withType(Test) {
useJUnitPlatform()
// Prevent the project from creating temporary files outside of the build directory.
systemProperty 'java.io.tmpdir', buildDir.absolutePath
}
@ -110,7 +112,7 @@ artifactory {
}
wrapper {
gradleVersion = "5.2.1"
gradleVersion = "5.4.1"
distributionType = Wrapper.DistributionType.ALL
}

View File

@ -33,8 +33,10 @@ dependencies {
// ClassGraph: classpath scanning
shadow "io.github.classgraph:classgraph:$class_graph_version"
testCompile "junit:junit:${junit_version}"
testImplementation "org.junit.jupiter:junit-jupiter-api:$junit_jupiter_version"
testRuntimeOnly "org.junit.jupiter:junit-jupiter-engine:$junit_jupiter_version"
testRuntimeOnly "org.junit.platform:junit-platform-launcher:$junit_platform_version"
// Test utilities
testImplementation "org.assertj:assertj-core:$assertj_version"

View File

@ -2,9 +2,10 @@ package net.corda.djvm.execution;
import net.corda.djvm.TestBase;
import net.corda.djvm.WithJava;
import org.junit.jupiter.api.Test;
import static net.corda.djvm.messages.Severity.*;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.Test;
import java.util.EnumMap;
import java.util.EnumSet;

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution;
import net.corda.djvm.TestBase;
import net.corda.djvm.WithJava;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.Set;
import java.util.function.Function;

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution;
import net.corda.djvm.TestBase;
import net.corda.djvm.WithJava;
import org.junit.Test;
import org.junit.jupiter.api.Test;
import java.util.function.Function;

View File

@ -2,9 +2,9 @@ package net.corda.djvm.execution;
import net.corda.djvm.TestBase;
import net.corda.djvm.WithJava;
import static net.corda.djvm.messages.Severity.*;
import org.junit.jupiter.api.Test;
import org.junit.Test;
import static net.corda.djvm.messages.Severity.*;
import java.net.URI;
import java.net.URISyntaxException;

View File

@ -4,7 +4,7 @@ import net.corda.djvm.assertions.AssertionExtensions.assertThatDJVM
import net.corda.djvm.rewiring.SandboxClassLoadingException
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Test
import org.junit.jupiter.api.Test
import sandbox.SandboxFunction
import sandbox.Task
import java.util.*
@ -71,7 +71,7 @@ class DJVMExceptionTest : TestBase() {
assertThat(result.getArray("getStackTrace"))
.hasOnlyElementsOfType(djvm.stackTraceElementClass)
.isNotEmpty()
.isNotEmpty
}
@Test
@ -88,7 +88,7 @@ class DJVMExceptionTest : TestBase() {
assertThat(result.getArray("getStackTrace"))
.hasOnlyElementsOfType(djvm.stackTraceElementClass)
.isNotEmpty()
.isNotEmpty
assertThatExceptionOfType(ClassNotFoundException::class.java)
.isThrownBy { djvm.classFor("sandbox.java.lang.RuntimeException\$1DJVM") }
@ -108,7 +108,7 @@ class DJVMExceptionTest : TestBase() {
assertThat(result.getArray("getStackTrace"))
.hasOnlyElementsOfType(djvm.stackTraceElementClass)
.isNotEmpty()
.isNotEmpty
assertThatDJVM(djvm.classFor("sandbox.java.util.EmptyStackException\$1DJVM"))
.isAssignableFrom(RuntimeException::class.java)

View File

@ -1,8 +1,8 @@
package net.corda.djvm
import org.assertj.core.api.Assertions.*
import org.junit.Assert.*
import org.junit.Test
import org.junit.jupiter.api.Assertions.*
import org.junit.jupiter.api.Test
import sandbox.java.lang.sandbox
import java.text.DecimalFormatSymbols

View File

@ -20,10 +20,10 @@ import net.corda.djvm.source.ClassSource
import net.corda.djvm.source.SourceClassLoader
import net.corda.djvm.utilities.Discovery
import net.corda.djvm.validation.RuleValidator
import org.junit.After
import org.junit.AfterClass
import org.junit.Assert.assertEquals
import org.junit.BeforeClass
import org.junit.jupiter.api.AfterAll
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.BeforeAll
import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Type
@ -81,7 +81,7 @@ abstract class TestBase {
*/
inline fun <reified T> nameOf(prefix: String = "") = "$prefix${Type.getInternalName(T::class.java)}"
@BeforeClass
@BeforeAll
@JvmStatic
fun setupParentClassLoader() {
val rootConfiguration = AnalysisConfiguration.createRoot(
@ -105,7 +105,7 @@ abstract class TestBase {
parentClassLoader = SandboxClassLoader.createFor(parentConfiguration)
}
@AfterClass
@AfterAll
@JvmStatic
fun destroyRootContext() {
parentConfiguration.analysisConfiguration.close()
@ -126,7 +126,7 @@ abstract class TestBase {
val context: AnalysisContext
get() = AnalysisContext.fromConfiguration(configuration)
@After
@AfterEach
fun destroy() {
configuration.close()
}

View File

@ -13,7 +13,7 @@ import net.corda.djvm.code.instructions.TypeInstruction
import net.corda.djvm.references.ClassRepresentation
import net.corda.djvm.references.Member
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
@Suppress("unused")
class ClassAndMemberVisitorTest : TestBase() {

View File

@ -1,7 +1,7 @@
package net.corda.djvm.analysis
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class ClassResolverTest {

View File

@ -1,7 +1,7 @@
package net.corda.djvm.analysis
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class SourceLocationTest {

View File

@ -2,7 +2,7 @@ package net.corda.djvm.analysis
import net.corda.djvm.TestBase
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class WhitelistTest : TestBase() {

View File

@ -5,7 +5,7 @@ import net.corda.djvm.analysis.AnalysisRuntimeContext
import net.corda.djvm.references.ClassRepresentation
import net.corda.djvm.references.Member
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.Opcodes.ACC_STRICT
@Suppress("unused")

View File

@ -3,7 +3,7 @@ package net.corda.djvm.code
import net.corda.djvm.TestBase
import net.corda.djvm.analysis.ClassAndMemberVisitor
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.ClassVisitor
import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes.NEW

View File

@ -2,7 +2,7 @@ package net.corda.djvm.costing
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Test
import org.junit.jupiter.api.Test
import sandbox.net.corda.djvm.costing.ThresholdViolationError
import kotlin.concurrent.thread

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution
import net.corda.djvm.TestBase
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.*
import java.util.function.Function

View File

@ -11,7 +11,7 @@ import net.corda.djvm.assertions.AssertionExtensions.withProblem
import net.corda.djvm.rewiring.SandboxClassLoadingException
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType
import org.junit.Test
import org.junit.jupiter.api.Test
import sandbox.net.corda.djvm.costing.ThresholdViolationError
import sandbox.net.corda.djvm.rules.RuleViolationError
import java.nio.file.Files
@ -431,7 +431,7 @@ class SandboxExecutorTest : TestBase() {
override fun apply(input: Int): String? {
return synchronized(this) {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
val javaObject = this as java.lang.Object
val javaObject = this as Object
when(input) {
1 -> {
javaObject.notify()

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution
import net.corda.djvm.TestBase
import org.assertj.core.api.Assertions.*
import org.junit.Test
import org.junit.jupiter.api.Test
import java.util.function.Function
class SandboxThrowableTest : TestBase() {

View File

@ -2,7 +2,7 @@ package net.corda.djvm.formatter
import net.corda.djvm.formatting.MemberFormatter
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class MemberFormatterTest {

View File

@ -1,7 +1,7 @@
package net.corda.djvm.references
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.Opcodes
class ClassHierarchyTest {
@ -39,7 +39,7 @@ class ClassHierarchyTest {
classes.add(clazz1)
val member = classes.getMember(clazz<FirstClass>().name, "method", "()V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<FirstClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "()V")
@ -63,7 +63,7 @@ class ClassHierarchyTest {
classes.add(clazz2)
val member = classes.getMember(clazz<SecondClass>().name, "method", "()V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<FirstClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "()V")
@ -78,7 +78,7 @@ class ClassHierarchyTest {
classes.add(clazz2)
val member = classes.getMember(clazz<SecondClass>().name, "method", "()V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<SecondClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "()V")
@ -98,7 +98,7 @@ class ClassHierarchyTest {
classes.add(clazz4)
val member = classes.getMember(clazz<FourthClass>().name, "method", "()V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<SecondClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "()V")
@ -123,42 +123,42 @@ class ClassHierarchyTest {
var member = classes.getMember(clazz<FourthClass>().name, "method", "()V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<FirstClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "()V")
member = classes.getMember(clazz<FourthClass>().name, "method", "(I)V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<FirstClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "(I)V")
member = classes.getMember(clazz<FourthClass>().name, "method", "(J)V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<SecondClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "(J)V")
member = classes.getMember(clazz<FourthClass>().name, "method", "(B)V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<ThirdClass>().name)
.hasFieldOrPropertyWithValue("memberName", "method")
.hasFieldOrPropertyWithValue("signature", "(B)V")
member = classes.getMember(clazz<FourthClass>().name, "anotherMethod", "([B)V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<FourthClass>().name)
.hasFieldOrPropertyWithValue("memberName", "anotherMethod")
.hasFieldOrPropertyWithValue("signature", "([B)V")
member = classes.getMember(clazz<ThirdClass>().name, "anotherMethod", "([B)V")
assertThat(member)
.isNotNull()
.isNotNull
.hasFieldOrPropertyWithValue("className", clazz<SecondClass>().name)
.hasFieldOrPropertyWithValue("memberName", "anotherMethod")
.hasFieldOrPropertyWithValue("signature", "([B)V")
@ -183,8 +183,8 @@ class ClassHierarchyTest {
val apiVersion = Opcodes.V1_8
val access = 0
val className = classModule.getBinaryClassName(it.name)
val superClassName = TSuper::class.java.let {
classModule.getBinaryClassName(it.name)
val superClassName = TSuper::class.java.let { s ->
classModule.getBinaryClassName(s.name)
}
ClassRepresentation(apiVersion, access, className, superClassName, sourceFile = "${it.simpleName}.kt")
}

View File

@ -1,7 +1,7 @@
package net.corda.djvm.references
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class ClassModuleTest {

View File

@ -3,7 +3,7 @@ package net.corda.djvm.references
import net.corda.djvm.annotations.NonDeterministic
import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.annotations.NotNull
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.Type
class MemberModuleTest {
@ -132,7 +132,7 @@ class MemberModuleTest {
assertThat(module.isConstructor(member("<clinit>"))).isTrue()
}
private val java.lang.Class<*>.descriptor: String
private val Class<*>.descriptor: String
get() = Type.getDescriptor(this)
private fun member(member: String) =

View File

@ -5,7 +5,7 @@ import net.corda.djvm.TestBase
import net.corda.djvm.assertions.AssertionExtensions.assertThat
import net.corda.djvm.execution.ExecutionProfile
import org.assertj.core.api.Assertions.*
import org.junit.Test
import org.junit.jupiter.api.Test
import sandbox.net.corda.djvm.costing.ThresholdViolationError
import java.nio.file.Paths
import java.util.*

View File

@ -3,7 +3,7 @@ package net.corda.djvm.rules
import foo.bar.sandbox.Callable
import net.corda.djvm.TestBase
import net.corda.djvm.assertions.AssertionExtensions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.Type
import java.util.*

View File

@ -4,7 +4,7 @@ import foo.bar.sandbox.Callable
import net.corda.djvm.TestBase
import net.corda.djvm.assertions.AssertionExtensions.assertThat
import net.corda.djvm.messages.Severity
import org.junit.Test
import org.junit.jupiter.api.Test
import org.objectweb.asm.Opcodes
import sandbox.greymalkin.StringReturner

View File

@ -3,8 +3,9 @@ package net.corda.djvm.source
import net.corda.djvm.analysis.ClassResolver
import net.corda.djvm.analysis.Whitelist
import org.assertj.core.api.Assertions.assertThat
import org.junit.After
import org.junit.Test
import org.junit.jupiter.api.AfterEach
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.nio.file.Files
import java.nio.file.Path
@ -19,10 +20,12 @@ class SourceClassLoaderTest {
assertThat(clazz.simpleName).isEqualTo("Boolean")
}
@Test(expected = ClassNotFoundException::class)
@Test
fun `cannot load arbitrary class when no files are provided to the class loader`() {
val classLoader = SourceClassLoader(emptyList(), classResolver)
classLoader.loadClass("net.foo.NonExistentClass")
assertThrows<ClassNotFoundException> {
classLoader.loadClass("net.foo.NonExistentClass")
}
}
@Test
@ -34,11 +37,13 @@ class SourceClassLoaderTest {
}
}
@Test(expected = ClassNotFoundException::class)
@Test
fun `cannot load arbitrary class when JAR file is provided to the class loader`() {
useTemporaryFile("jar-with-single-class.jar") {
val classLoader = SourceClassLoader(this, classResolver)
classLoader.loadClass("net.foo.NonExistentClass")
assertThrows<ClassNotFoundException> {
classLoader.loadClass("net.foo.NonExistentClass")
}
}
}
@ -53,11 +58,13 @@ class SourceClassLoaderTest {
}
}
@Test(expected = ClassNotFoundException::class)
@Test
fun `cannot load arbitrary class when multiple JAR files are provided to the class loader`() {
useTemporaryFile("jar-with-single-class.jar", "jar-with-two-classes.jar") {
val classLoader = SourceClassLoader(this, classResolver)
classLoader.loadClass("com.somewhere.NonExistentClass")
assertThrows<ClassNotFoundException> {
classLoader.loadClass("com.somewhere.NonExistentClass")
}
}
}
@ -75,7 +82,7 @@ class SourceClassLoaderTest {
}
}
@After
@AfterEach
fun cleanup() {
openedFiles.forEach {
try {

View File

@ -5,7 +5,7 @@ import net.corda.djvm.code.DefinitionProvider
import net.corda.djvm.code.Emitter
import net.corda.djvm.rules.Rule
import org.assertj.core.api.Assertions.assertThat
import org.junit.Test
import org.junit.jupiter.api.Test
class DiscoveryTest : TestBase() {

View File

@ -6,7 +6,8 @@ assertj_version=3.12.1
class_graph_version=4.6.12
jcabi_manifests_version=1.1
jopt_simple_version=5.0.2
junit_version=4.12
junit_jupiter_version=5.4.2
junit_platform_version=1.4.2
kotlin_version=1.2.71
log4j_version=2.11.2
picocli_version=3.8.0

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-5.4.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists