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

View File

@ -34,7 +34,9 @@ dependencies {
// ClassGraph: classpath scanning // ClassGraph: classpath scanning
shadow "io.github.classgraph:classgraph:$class_graph_version" 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 // Test utilities
testImplementation "org.assertj:assertj-core:$assertj_version" 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.TestBase;
import net.corda.djvm.WithJava; import net.corda.djvm.WithJava;
import org.junit.jupiter.api.Test;
import static net.corda.djvm.messages.Severity.*; import static net.corda.djvm.messages.Severity.*;
import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThat;
import org.junit.Test;
import java.util.EnumMap; import java.util.EnumMap;
import java.util.EnumSet; import java.util.EnumSet;

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution;
import net.corda.djvm.TestBase; import net.corda.djvm.TestBase;
import net.corda.djvm.WithJava; import net.corda.djvm.WithJava;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.Set; import java.util.Set;
import java.util.function.Function; 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.TestBase;
import net.corda.djvm.WithJava; import net.corda.djvm.WithJava;
import org.junit.Test; import org.junit.jupiter.api.Test;
import java.util.function.Function; 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.TestBase;
import net.corda.djvm.WithJava; 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.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;

View File

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

View File

@ -1,8 +1,8 @@
package net.corda.djvm package net.corda.djvm
import org.assertj.core.api.Assertions.* import org.assertj.core.api.Assertions.*
import org.junit.Assert.* import org.junit.jupiter.api.Assertions.*
import org.junit.Test import org.junit.jupiter.api.Test
import sandbox.java.lang.sandbox import sandbox.java.lang.sandbox
import java.text.DecimalFormatSymbols 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.source.SourceClassLoader
import net.corda.djvm.utilities.Discovery import net.corda.djvm.utilities.Discovery
import net.corda.djvm.validation.RuleValidator import net.corda.djvm.validation.RuleValidator
import org.junit.After import org.junit.jupiter.api.AfterAll
import org.junit.AfterClass import org.junit.jupiter.api.AfterEach
import org.junit.Assert.assertEquals import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.BeforeClass import org.junit.jupiter.api.BeforeAll
import org.objectweb.asm.ClassReader import org.objectweb.asm.ClassReader
import org.objectweb.asm.ClassWriter import org.objectweb.asm.ClassWriter
import org.objectweb.asm.Type 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)}" inline fun <reified T> nameOf(prefix: String = "") = "$prefix${Type.getInternalName(T::class.java)}"
@BeforeClass @BeforeAll
@JvmStatic @JvmStatic
fun setupParentClassLoader() { fun setupParentClassLoader() {
val rootConfiguration = AnalysisConfiguration.createRoot( val rootConfiguration = AnalysisConfiguration.createRoot(
@ -105,7 +105,7 @@ abstract class TestBase {
parentClassLoader = SandboxClassLoader.createFor(parentConfiguration) parentClassLoader = SandboxClassLoader.createFor(parentConfiguration)
} }
@AfterClass @AfterAll
@JvmStatic @JvmStatic
fun destroyRootContext() { fun destroyRootContext() {
parentConfiguration.analysisConfiguration.close() parentConfiguration.analysisConfiguration.close()
@ -126,7 +126,7 @@ abstract class TestBase {
val context: AnalysisContext val context: AnalysisContext
get() = AnalysisContext.fromConfiguration(configuration) get() = AnalysisContext.fromConfiguration(configuration)
@After @AfterEach
fun destroy() { fun destroy() {
configuration.close() 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.ClassRepresentation
import net.corda.djvm.references.Member import net.corda.djvm.references.Member
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.jupiter.api.Test
@Suppress("unused") @Suppress("unused")
class ClassAndMemberVisitorTest : TestBase() { class ClassAndMemberVisitorTest : TestBase() {

View File

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

View File

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

View File

@ -2,7 +2,7 @@ package net.corda.djvm.analysis
import net.corda.djvm.TestBase import net.corda.djvm.TestBase
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.jupiter.api.Test
class WhitelistTest : TestBase() { 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.ClassRepresentation
import net.corda.djvm.references.Member import net.corda.djvm.references.Member
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.jupiter.api.Test
import org.objectweb.asm.Opcodes.ACC_STRICT import org.objectweb.asm.Opcodes.ACC_STRICT
@Suppress("unused") @Suppress("unused")

View File

@ -3,7 +3,7 @@ package net.corda.djvm.code
import net.corda.djvm.TestBase import net.corda.djvm.TestBase
import net.corda.djvm.analysis.ClassAndMemberVisitor import net.corda.djvm.analysis.ClassAndMemberVisitor
import org.assertj.core.api.Assertions.assertThat 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.ClassVisitor
import org.objectweb.asm.MethodVisitor import org.objectweb.asm.MethodVisitor
import org.objectweb.asm.Opcodes.NEW 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.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType 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.costing.ThresholdViolationError
import kotlin.concurrent.thread import kotlin.concurrent.thread

View File

@ -2,7 +2,7 @@ package net.corda.djvm.execution
import net.corda.djvm.TestBase import net.corda.djvm.TestBase
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.Test import org.junit.jupiter.api.Test
import java.util.* import java.util.*
import java.util.function.Function 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 net.corda.djvm.rewiring.SandboxClassLoadingException
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatExceptionOfType 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.costing.ThresholdViolationError
import sandbox.net.corda.djvm.rules.RuleViolationError import sandbox.net.corda.djvm.rules.RuleViolationError
import java.nio.file.Files import java.nio.file.Files
@ -431,7 +431,7 @@ class SandboxExecutorTest : TestBase() {
override fun apply(input: Int): String? { override fun apply(input: Int): String? {
return synchronized(this) { return synchronized(this) {
@Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN") @Suppress("PLATFORM_CLASS_MAPPED_TO_KOTLIN")
val javaObject = this as java.lang.Object val javaObject = this as Object
when(input) { when(input) {
1 -> { 1 -> {
javaObject.notify() javaObject.notify()

View File

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

View File

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

View File

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

View File

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

View File

@ -3,7 +3,7 @@ package net.corda.djvm.references
import net.corda.djvm.annotations.NonDeterministic import net.corda.djvm.annotations.NonDeterministic
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.jetbrains.annotations.NotNull import org.jetbrains.annotations.NotNull
import org.junit.Test import org.junit.jupiter.api.Test
import org.objectweb.asm.Type import org.objectweb.asm.Type
class MemberModuleTest { class MemberModuleTest {
@ -132,7 +132,7 @@ class MemberModuleTest {
assertThat(module.isConstructor(member("<clinit>"))).isTrue() assertThat(module.isConstructor(member("<clinit>"))).isTrue()
} }
private val java.lang.Class<*>.descriptor: String private val Class<*>.descriptor: String
get() = Type.getDescriptor(this) get() = Type.getDescriptor(this)
private fun member(member: String) = 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.assertions.AssertionExtensions.assertThat
import net.corda.djvm.execution.ExecutionProfile import net.corda.djvm.execution.ExecutionProfile
import org.assertj.core.api.Assertions.* import org.assertj.core.api.Assertions.*
import org.junit.Test import org.junit.jupiter.api.Test
import sandbox.net.corda.djvm.costing.ThresholdViolationError import sandbox.net.corda.djvm.costing.ThresholdViolationError
import java.nio.file.Paths import java.nio.file.Paths
import java.util.* import java.util.*

View File

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

View File

@ -4,7 +4,7 @@ import foo.bar.sandbox.Callable
import net.corda.djvm.TestBase import net.corda.djvm.TestBase
import net.corda.djvm.assertions.AssertionExtensions.assertThat import net.corda.djvm.assertions.AssertionExtensions.assertThat
import net.corda.djvm.messages.Severity import net.corda.djvm.messages.Severity
import org.junit.Test import org.junit.jupiter.api.Test
import org.objectweb.asm.Opcodes import org.objectweb.asm.Opcodes
import sandbox.greymalkin.StringReturner 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.ClassResolver
import net.corda.djvm.analysis.Whitelist import net.corda.djvm.analysis.Whitelist
import org.assertj.core.api.Assertions.assertThat import org.assertj.core.api.Assertions.assertThat
import org.junit.After import org.junit.jupiter.api.AfterEach
import org.junit.Test import org.junit.jupiter.api.Test
import org.junit.jupiter.api.assertThrows
import java.nio.file.Files import java.nio.file.Files
import java.nio.file.Path import java.nio.file.Path
@ -19,11 +20,13 @@ class SourceClassLoaderTest {
assertThat(clazz.simpleName).isEqualTo("Boolean") assertThat(clazz.simpleName).isEqualTo("Boolean")
} }
@Test(expected = ClassNotFoundException::class) @Test
fun `cannot load arbitrary class when no files are provided to the class loader`() { fun `cannot load arbitrary class when no files are provided to the class loader`() {
val classLoader = SourceClassLoader(emptyList(), classResolver) val classLoader = SourceClassLoader(emptyList(), classResolver)
assertThrows<ClassNotFoundException> {
classLoader.loadClass("net.foo.NonExistentClass") classLoader.loadClass("net.foo.NonExistentClass")
} }
}
@Test @Test
fun `can load class when JAR file is provided to the class loader`() { fun `can load class when JAR file is provided to the class loader`() {
@ -34,13 +37,15 @@ class SourceClassLoaderTest {
} }
} }
@Test(expected = ClassNotFoundException::class) @Test
fun `cannot load arbitrary class when JAR file is provided to the class loader`() { fun `cannot load arbitrary class when JAR file is provided to the class loader`() {
useTemporaryFile("jar-with-single-class.jar") { useTemporaryFile("jar-with-single-class.jar") {
val classLoader = SourceClassLoader(this, classResolver) val classLoader = SourceClassLoader(this, classResolver)
assertThrows<ClassNotFoundException> {
classLoader.loadClass("net.foo.NonExistentClass") classLoader.loadClass("net.foo.NonExistentClass")
} }
} }
}
@Test @Test
fun `can load classes when multiple JAR files are provided to the class loader`() { fun `can load classes when multiple JAR files are provided to the class loader`() {
@ -53,13 +58,15 @@ class SourceClassLoaderTest {
} }
} }
@Test(expected = ClassNotFoundException::class) @Test
fun `cannot load arbitrary class when multiple JAR files are provided to the class loader`() { 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") { useTemporaryFile("jar-with-single-class.jar", "jar-with-two-classes.jar") {
val classLoader = SourceClassLoader(this, classResolver) val classLoader = SourceClassLoader(this, classResolver)
assertThrows<ClassNotFoundException> {
classLoader.loadClass("com.somewhere.NonExistentClass") classLoader.loadClass("com.somewhere.NonExistentClass")
} }
} }
}
@Test @Test
fun `can load class when folder containing JAR file is provided to the class loader`() { fun `can load class when folder containing JAR file is provided to the class loader`() {
@ -75,7 +82,7 @@ class SourceClassLoaderTest {
} }
} }
@After @AfterEach
fun cleanup() { fun cleanup() {
openedFiles.forEach { openedFiles.forEach {
try { try {

View File

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

View File

@ -6,7 +6,8 @@ assertj_version=3.12.1
class_graph_version=4.6.12 class_graph_version=4.6.12
jcabi_manifests_version=1.1 jcabi_manifests_version=1.1
jopt_simple_version=5.0.2 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 kotlin_version=1.2.71
log4j_version=2.11.2 log4j_version=2.11.2
picocli_version=3.8.0 picocli_version=3.8.0

View File

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists 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 zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists