diff --git a/common/configuration-parsing/src/test/kotlin/net/corda/common/configuration/parsing/internal/SpecificationTest.kt b/common/configuration-parsing/src/test/kotlin/net/corda/common/configuration/parsing/internal/SpecificationTest.kt index 96a9f181ef..9b0535df90 100644 --- a/common/configuration-parsing/src/test/kotlin/net/corda/common/configuration/parsing/internal/SpecificationTest.kt +++ b/common/configuration-parsing/src/test/kotlin/net/corda/common/configuration/parsing/internal/SpecificationTest.kt @@ -61,7 +61,7 @@ class SpecificationTest { override fun parseValid(configuration: Config, options: Configuration.Options): Valid { val config = configuration.withOptions(options) - return valid(AtomicLong(config[maxElement]!!)) + return valid(AtomicLong(config[maxElement])) } } @@ -103,7 +103,7 @@ class SpecificationTest { if (elements.any { element -> element <= 1 }) { return invalid(Configuration.Validation.Error.BadValue.of("elements cannot be less than or equal to 1")) } - return valid(elements.max()!!) + return valid(elements.max()) } val spec = object : Configuration.Specification("AtomicLong") { diff --git a/core-tests/src/test/kotlin/net/corda/coretests/contracts/AmountTests.kt b/core-tests/src/test/kotlin/net/corda/coretests/contracts/AmountTests.kt index e382969aa0..07dcbcdb70 100644 --- a/core-tests/src/test/kotlin/net/corda/coretests/contracts/AmountTests.kt +++ b/core-tests/src/test/kotlin/net/corda/coretests/contracts/AmountTests.kt @@ -56,8 +56,8 @@ class AmountTests { val splits = baseAmount.splitEvenly(partitionCount) assertEquals(partitionCount, splits.size) assertEquals(baseAmount, splits.sumOrZero(baseAmount.token)) - val min = splits.min()!! - val max = splits.max()!! + val min = splits.min() + val max = splits.max() assertTrue(max.quantity - min.quantity <= 1L, "Amount quantities should differ by at most one token") } } diff --git a/core-tests/src/test/kotlin/net/corda/coretests/transactions/CompatibleTransactionTests.kt b/core-tests/src/test/kotlin/net/corda/coretests/transactions/CompatibleTransactionTests.kt index 10ea1e949c..651aa2d8f7 100644 --- a/core-tests/src/test/kotlin/net/corda/coretests/transactions/CompatibleTransactionTests.kt +++ b/core-tests/src/test/kotlin/net/corda/coretests/transactions/CompatibleTransactionTests.kt @@ -292,7 +292,7 @@ class CompatibleTransactionTests { ftxCompatibleNoInputs.verify() assertFailsWith { ftxCompatibleNoInputs.checkAllComponentsVisible(INPUTS_GROUP) } assertEquals(wireTransactionCompatibleA.componentGroups.size - 1, ftxCompatibleNoInputs.filteredComponentGroups.size) - assertEquals(wireTransactionCompatibleA.componentGroups.map { it.groupIndex }.max()!!, ftxCompatibleNoInputs.groupHashes.size - 1) + assertEquals(wireTransactionCompatibleA.componentGroups.map { it.groupIndex }.max(), ftxCompatibleNoInputs.groupHashes.size - 1) } @Test(timeout=300_000) diff --git a/core-tests/src/test/kotlin/net/corda/coretests/utilities/KotlinUtilsTest.kt b/core-tests/src/test/kotlin/net/corda/coretests/utilities/KotlinUtilsTest.kt index 4318da12e1..105752de31 100644 --- a/core-tests/src/test/kotlin/net/corda/coretests/utilities/KotlinUtilsTest.kt +++ b/core-tests/src/test/kotlin/net/corda/coretests/utilities/KotlinUtilsTest.kt @@ -13,7 +13,8 @@ import net.corda.testing.core.SerializationEnvironmentRule import org.assertj.core.api.Assertions.assertThat import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException +import org.junit.jupiter.api.assertThrows +import kotlin.test.assertTrue object EmptyWhitelist : ClassWhitelist { override fun hasListed(type: Class<*>): Boolean = false @@ -23,9 +24,6 @@ class KotlinUtilsTest { @Rule @JvmField val testSerialization = SerializationEnvironmentRule() - @JvmField - @Rule - val expectedEx: ExpectedException = ExpectedException.none() private val KRYO_CHECKPOINT_NOWHITELIST_CONTEXT = CheckpointSerializationContextImpl( javaClass.classLoader, @@ -54,10 +52,11 @@ class KotlinUtilsTest { @Test(timeout=300_000) fun `deserialise transient property with non-capturing lambda`() { - expectedEx.expect(KryoException::class.java) - expectedEx.expectMessage("is not annotated or on the whitelist, so cannot be used in serialization") - val original = NonCapturingTransientProperty() - original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT) + val anException = assertThrows { + val original = NonCapturingTransientProperty() + original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT) + } + anException.message?.let { assertTrue(it.contains("is not annotated or on the whitelist, so cannot be used in serialization")) } } @Test(timeout=300_000) @@ -73,12 +72,11 @@ class KotlinUtilsTest { @Test(timeout=300_000) fun `deserialise transient property with capturing lambda`() { - expectedEx.expect(KryoException::class.java) - expectedEx.expectMessage("is not annotated or on the whitelist, so cannot be used in serialization") - - val original = CapturingTransientProperty("Hello") - - original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT) + val anException = assertThrows { + val original = CapturingTransientProperty("Hello") + original.checkpointSerialize(context = KRYO_CHECKPOINT_CONTEXT).checkpointDeserialize(context = KRYO_CHECKPOINT_NOWHITELIST_CONTEXT) + } + anException.message?.let { assertTrue(it.contains("is not annotated or on the whitelist, so cannot be used in serialization")) } } private class NullTransientProperty { diff --git a/core/src/test/kotlin/net/corda/core/utilities/LazyMappedListTest.kt b/core/src/test/kotlin/net/corda/core/utilities/LazyMappedListTest.kt index 82920cef91..a152bfcf32 100644 --- a/core/src/test/kotlin/net/corda/core/utilities/LazyMappedListTest.kt +++ b/core/src/test/kotlin/net/corda/core/utilities/LazyMappedListTest.kt @@ -5,16 +5,12 @@ import net.corda.core.internal.lazyMapped import net.corda.core.internal.TransactionDeserialisationException import net.corda.core.internal.eagerDeserialise import net.corda.core.serialization.MissingAttachmentsException -import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException +import org.junit.jupiter.api.assertThrows import kotlin.test.assertEquals class LazyMappedListTest { - @get:Rule - val exception: ExpectedException = ExpectedException.none() - @Test(timeout=300_000) fun `LazyMappedList works`() { val originalList = (1 until 10).toList() @@ -44,14 +40,13 @@ class LazyMappedListTest { @Test(timeout=300_000) fun testMissingAttachments() { - exception.expect(MissingAttachmentsException::class.java) - exception.expectMessage("Uncatchable!") - - val lazyList = (0 until 5).toList().lazyMapped { _, _ -> - throw MissingAttachmentsException(emptyList(), "Uncatchable!") + val anException = assertThrows { + val lazyList = (0 until 5).toList().lazyMapped { _, _ -> + throw MissingAttachmentsException(emptyList(), "Uncatchable!") + } + lazyList.eagerDeserialise { _, _ -> -999 } } - - lazyList.eagerDeserialise { _, _ -> -999 } + assertEquals("Uncatchable!", anException.message) } @Test(timeout=300_000) diff --git a/node-api-tests/src/test/kotlin/net/corda/nodeapitests/internal/network/NetworkBootstrapperTest.kt b/node-api-tests/src/test/kotlin/net/corda/nodeapitests/internal/network/NetworkBootstrapperTest.kt index 2a52435b8f..0607d971f5 100644 --- a/node-api-tests/src/test/kotlin/net/corda/nodeapitests/internal/network/NetworkBootstrapperTest.kt +++ b/node-api-tests/src/test/kotlin/net/corda/nodeapitests/internal/network/NetworkBootstrapperTest.kt @@ -40,7 +40,7 @@ import org.junit.After import org.junit.AfterClass import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException +import org.junit.jupiter.api.assertThrows import org.junit.rules.TemporaryFolder import java.nio.file.Files import java.nio.file.Path @@ -54,16 +54,13 @@ import kotlin.io.path.readBytes import kotlin.io.path.useDirectoryEntries import kotlin.io.path.writeBytes import kotlin.io.path.writeText +import kotlin.test.assertEquals class NetworkBootstrapperTest { @Rule @JvmField val tempFolder = TemporaryFolder() - @Rule - @JvmField - val expectedEx: ExpectedException = ExpectedException.none() - @Rule @JvmField val testSerialization = SerializationEnvironmentRule() @@ -304,9 +301,10 @@ class NetworkBootstrapperTest { assertContainsPackageOwner("alice", mapOf(Pair(greedyNamespace, alice.publicKey))) // register overlapping package name createNodeConfFile("bob", bobConfig) - expectedEx.expect(IllegalArgumentException::class.java) - expectedEx.expectMessage("Multiple packages added to the packageOwnership overlap.") - bootstrap(packageOwnership = mapOf(Pair(greedyNamespace, alice.publicKey), Pair(bobPackageName, bob.publicKey))) + val anException = assertThrows { + bootstrap(packageOwnership = mapOf(Pair(greedyNamespace, alice.publicKey), Pair(bobPackageName, bob.publicKey))) + } + assertEquals("Multiple packages added to the packageOwnership overlap.", anException.message) } @Test(timeout=300_000) diff --git a/node/src/integration-test-slow/kotlin/net/corda/node/persistence/NodeStatePersistenceTests.kt b/node/src/integration-test-slow/kotlin/net/corda/node/persistence/NodeStatePersistenceTests.kt index 5eba97c9db..63b8b9942d 100644 --- a/node/src/integration-test-slow/kotlin/net/corda/node/persistence/NodeStatePersistenceTests.kt +++ b/node/src/integration-test-slow/kotlin/net/corda/node/persistence/NodeStatePersistenceTests.kt @@ -60,7 +60,7 @@ class NodeStatePersistenceTests { result } assertNotNull(stateAndRef) - val retrievedMessage = stateAndRef!!.state.data.message + val retrievedMessage = stateAndRef.state.data.message assertEquals(message, retrievedMessage) } @@ -96,7 +96,7 @@ class NodeStatePersistenceTests { result } assertNotNull(stateAndRef) - val retrievedMessage = stateAndRef!!.state.data.message + val retrievedMessage = stateAndRef.state.data.message assertEquals(message, retrievedMessage) } } diff --git a/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt b/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt index fe5bfbf63f..f472870a5f 100644 --- a/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt +++ b/node/src/integration-test-slow/kotlin/net/corda/node/utilities/registration/NodeRegistrationTest.kt @@ -65,7 +65,7 @@ class NodeRegistrationTest { pollInterval = 1.seconds, hostAndPort = portAllocation.nextHostAndPort(), myHostNameValue = "localhost", - additionalServices = *arrayOf(registrationHandler)) + additionalServices = arrayOf(registrationHandler)) serverHostAndPort = server.start() } diff --git a/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt b/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt index b4fd7c4dd4..ebeacb33c7 100644 --- a/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt +++ b/node/src/main/kotlin/net/corda/node/services/statemachine/StaffedFlowHospital.kt @@ -306,11 +306,11 @@ class StaffedFlowHospital(private val flowMessaging: FlowMessaging, log.info("Error ${index + 1} of ${errors.size}:", error) val diagnoses: Map> = staff.groupBy { it.consult(flowFiber, currentState, error, medicalHistory) } // We're only interested in the highest priority diagnosis for the error - val (diagnosis, by) = diagnoses.entries.minBy { it.key }!! + val (diagnosis, by) = diagnoses.entries.minBy { it.key } ConsultationReport(error, diagnosis, by) } // And we're only interested in the error with the highest priority diagnosis - .minBy { it.diagnosis }!! + .minBy { it.diagnosis } } private data class ConsultationReport(val error: Throwable, val diagnosis: Diagnosis, val by: List) diff --git a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowMetadataRecordingTest.kt b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowMetadataRecordingTest.kt index 457693d4ac..ab7bf7de13 100644 --- a/node/src/test/kotlin/net/corda/node/services/statemachine/FlowMetadataRecordingTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/statemachine/FlowMetadataRecordingTest.kt @@ -412,7 +412,7 @@ class FlowMetadataRecordingTest { metadata!!.let { assertNull(it.finishInstant) assertNotNull(finishTime) - assertTrue(finishTime!! >= it.startInstant) + assertTrue(finishTime >= it.startInstant) } } } diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryExceptionsTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryExceptionsTests.kt index 2dbd77b3ed..735c965d22 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryExceptionsTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryExceptionsTests.kt @@ -11,7 +11,6 @@ import net.corda.testing.core.* import net.corda.testing.internal.vault.DummyLinearStateSchemaV1 import org.assertj.core.api.Assertions.assertThatThrownBy import org.junit.* -import org.junit.rules.ExpectedException class VaultQueryExceptionsTests : VaultQueryParties by rule { @@ -30,10 +29,6 @@ class VaultQueryExceptionsTests : VaultQueryParties by rule { } } - @Rule - @JvmField - val expectedEx: ExpectedException = ExpectedException.none() - @Rule @JvmField val rollbackRule = VaultQueryRollbackRule(this) diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt index c534f6ae3e..99be985de9 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultQueryTests.kt @@ -45,7 +45,8 @@ import org.junit.ClassRule import org.junit.Ignore import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException +import org.junit.jupiter.api.Assertions.assertTrue +import org.junit.jupiter.api.assertThrows import org.junit.rules.ExternalResource import java.time.Duration import java.time.Instant @@ -148,7 +149,7 @@ open class VaultQueryTestRule(private val persistentServices: Boolean) : Externa cordappPackages, makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity), megaCorp, - moreKeys = *arrayOf(DUMMY_NOTARY_KEY) + moreKeys = arrayOf(DUMMY_NOTARY_KEY) ) } database = databaseAndServices.first @@ -184,10 +185,6 @@ class VaultQueryRollbackRule(private val vaultQueryParties: VaultQueryParties) : abstract class VaultQueryTestsBase : VaultQueryParties { - @Rule - @JvmField - val expectedEx: ExpectedException = ExpectedException.none() - companion object { @ClassRule @JvmField val testSerialization = SerializationEnvironmentRule() @@ -1006,10 +1003,11 @@ abstract class VaultQueryTestsBase : VaultQueryParties { assertThat(resultsUnlockedAndByLockIds.states).hasSize(5) // missing lockId - expectedEx.expect(VaultQueryException::class.java) - expectedEx.expectMessage("Must specify one or more lockIds") - val criteriaMissingLockId = VaultQueryCriteria(softLockingCondition = SoftLockingCondition(SoftLockingType.UNLOCKED_AND_SPECIFIED)) - vaultService.queryBy(criteriaMissingLockId) + val anException = assertThrows { + val criteriaMissingLockId = VaultQueryCriteria(softLockingCondition = SoftLockingCondition(SoftLockingType.UNLOCKED_AND_SPECIFIED)) + vaultService.queryBy(criteriaMissingLockId) + } + anException.message?.let { assertTrue(it.contains("Must specify one or more lockIds")) } } } @@ -1707,44 +1705,43 @@ abstract class VaultQueryTestsBase : VaultQueryParties { // pagination: invalid page number @Test(timeout=300_000) fun `invalid page number`() { - expectedEx.expect(VaultQueryException::class.java) - expectedEx.expectMessage("Page specification: invalid page number") - - database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) - val pagingSpec = PageSpecification(0, 10) - - val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) - vaultService.queryBy(criteria, paging = pagingSpec) + val anException = assertThrows { + database.transaction { + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) + val pagingSpec = PageSpecification(0, 10) + val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) + vaultService.queryBy(criteria, paging = pagingSpec) + } } + anException.message?.let { assertTrue(it.contains("Page specification: invalid page number")) } } // pagination: invalid page size @Suppress("INTEGER_OVERFLOW") @Test(timeout=300_000) fun `invalid page size`() { - expectedEx.expect(VaultQueryException::class.java) - expectedEx.expectMessage("Page specification: invalid page size") - - database.transaction { - vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) - val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, Integer.MAX_VALUE + 1) // overflow = -2147483648 - val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) - vaultService.queryBy(criteria, paging = pagingSpec) + val anException = assertThrows { + database.transaction { + vaultFiller.fillWithSomeTestCash(100.DOLLARS, notaryServices, 100, DUMMY_CASH_ISSUER) + val pagingSpec = PageSpecification(DEFAULT_PAGE_NUM, Integer.MAX_VALUE + 1) // overflow = -2147483648 + val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) + vaultService.queryBy(criteria, paging = pagingSpec) + } } + anException.message?.let { assertTrue(it.contains("Page specification: invalid page size")) } } // pagination not specified but more than DEFAULT_PAGE_SIZE results available (fail-fast test) @Test(timeout=300_000) fun `pagination not specified but more than default results available`() { - expectedEx.expect(VaultQueryException::class.java) - expectedEx.expectMessage("provide a PageSpecification") - - database.transaction { - vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER) - val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) - vaultService.queryBy(criteria) + val anException = assertThrows { + database.transaction { + vaultFiller.fillWithSomeTestCash(201.DOLLARS, notaryServices, 201, DUMMY_CASH_ISSUER) + val criteria = VaultQueryCriteria(status = Vault.StateStatus.ALL) + vaultService.queryBy(criteria) + } } + anException.message?.let { assertTrue(it.contains("provide a PageSpecification")) } } // example of querying states with paging using totalStatesAvailable diff --git a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt index 556ba13c90..0177169fb5 100644 --- a/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt +++ b/node/src/test/kotlin/net/corda/node/services/vault/VaultWithCashTest.kt @@ -83,7 +83,7 @@ class VaultWithCashTest { makeTestIdentityService(MEGA_CORP_IDENTITY, MINI_CORP_IDENTITY, dummyCashIssuer.identity, dummyNotary.identity), TestIdentity(MEGA_CORP.name, servicesKey), networkParameters, - moreKeys = *arrayOf(dummyNotary.keyPair)) + moreKeys = arrayOf(dummyNotary.keyPair)) database = databaseAndServices.first services = databaseAndServices.second vaultFiller = VaultFiller(services, dummyNotary) diff --git a/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt b/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt index 2424101214..1ecec4aec4 100644 --- a/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt +++ b/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmFlow.kt @@ -131,7 +131,7 @@ object SimmFlow { val valuer = serviceHub.identityService.wellKnownPartyFromAnonymous(state.valuer) require(valuer != null) { "Valuer party must be known to this node" } - val valuation = agreeValuation(portfolio, valuationDate, valuer!!) + val valuation = agreeValuation(portfolio, valuationDate, valuer) val update = PortfolioState.Update(valuation = valuation) return subFlow(StateRevisionFlowRequester(otherPartySession, stateRef, update)).state.data } diff --git a/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt b/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt index 599e9d4345..edbbabca2f 100644 --- a/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt +++ b/samples/simm-valuation-demo/flows/src/main/kotlin/net/corda/vega/flows/SimmRevaluation.kt @@ -25,7 +25,7 @@ object SimmRevaluation { if (ourIdentity == curState.participants[0]) { val otherParty = serviceHub.identityService.wellKnownPartyFromAnonymous(curState.participants[1]) require(otherParty != null) { "Other party must be known by this node" } - subFlow(SimmFlow.Requester(otherParty!!, valuationDate, stateAndRef)) + subFlow(SimmFlow.Requester(otherParty, valuationDate, stateAndRef)) } } } diff --git a/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt index 26bb86a116..6d03937bbe 100644 --- a/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt +++ b/serialization-tests/src/test/kotlin/net/corda/serialization/internal/CordaClassResolverTests.kt @@ -25,9 +25,8 @@ import net.corda.testing.internal.TestingNamedCacheFactory import net.corda.testing.internal.services.InternalMockAttachmentStorage import net.corda.testing.services.MockAttachmentStorage import org.assertj.core.api.Assertions.assertThatExceptionOfType -import org.junit.Rule import org.junit.Test -import org.junit.rules.ExpectedException +import org.junit.jupiter.api.assertThrows import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.verify @@ -267,16 +266,15 @@ class CordaClassResolverTests { } // Blacklist tests. Note: leave the variable public or else expected messages do not work correctly - @get:Rule - val expectedEx = ExpectedException.none()!! @Test(timeout=300_000) fun `Check blacklisted class`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("Class java.util.HashSet is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // HashSet is blacklisted. - resolver.getRegistration(HashSet::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // HashSet is blacklisted. + resolver.getRegistration(HashSet::class.java) + } + assertEquals("Class java.util.HashSet is blacklisted, so it cannot be used in serialization.", anException.message) } @Test(timeout=300_000) @@ -349,33 +347,37 @@ class CordaClassResolverTests { @Test(timeout=300_000) fun `Check blacklisted subclass`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$SubHashSet is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // SubHashSet extends the blacklisted HashSet. - resolver.getRegistration(SubHashSet::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // SubHashSet extends the blacklisted HashSet. + resolver.getRegistration(SubHashSet::class.java) + } + assertEquals("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$SubHashSet is blacklisted, so it cannot be used in serialization.", anException.message) } class SubSubHashSet : SubHashSet() @Test(timeout=300_000) fun `Check blacklisted subsubclass`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$SubSubHashSet is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // SubSubHashSet extends SubHashSet, which extends the blacklisted HashSet. - resolver.getRegistration(SubSubHashSet::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // SubSubHashSet extends SubHashSet, which extends the blacklisted HashSet. + resolver.getRegistration(SubSubHashSet::class.java) + } + assertEquals("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$SubSubHashSet is blacklisted, so it cannot be used in serialization.", anException.message) + } class ConnectionImpl(private val connection: Connection) : Connection by connection @Test(timeout=300_000) fun `Check blacklisted interface impl`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("The superinterface java.sql.Connection of net.corda.serialization.internal.CordaClassResolverTests\$ConnectionImpl is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // ConnectionImpl implements blacklisted Connection. - resolver.getRegistration(ConnectionImpl::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // ConnectionImpl implements blacklisted Connection. + resolver.getRegistration(ConnectionImpl::class.java) + } + assertEquals("The superinterface java.sql.Connection of net.corda.serialization.internal.CordaClassResolverTests\$ConnectionImpl is blacklisted, so it cannot be used in serialization.", anException.message) } interface SubConnection : Connection @@ -383,11 +385,13 @@ class CordaClassResolverTests { @Test(timeout=300_000) fun `Check blacklisted super-interface impl`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("The superinterface java.sql.Connection of net.corda.serialization.internal.CordaClassResolverTests\$SubConnectionImpl is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // SubConnectionImpl implements SubConnection, which extends the blacklisted Connection. - resolver.getRegistration(SubConnectionImpl::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // SubConnectionImpl implements SubConnection, which extends the blacklisted Connection. + resolver.getRegistration(SubConnectionImpl::class.java) + } + assertEquals("The superinterface java.sql.Connection of net.corda.serialization.internal.CordaClassResolverTests\$SubConnectionImpl is blacklisted, so it cannot be used in serialization.", anException.message) + } @Test(timeout=300_000) @@ -402,10 +406,11 @@ class CordaClassResolverTests { @Test(timeout=300_000) fun `Check blacklist precedes CordaSerializable`() { - expectedEx.expect(IllegalStateException::class.java) - expectedEx.expectMessage("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$CordaSerializableHashSet is blacklisted, so it cannot be used in serialization.") - val resolver = CordaClassResolver(allButBlacklistedContext) - // CordaSerializableHashSet is @CordaSerializable, but extends the blacklisted HashSet. - resolver.getRegistration(CordaSerializableHashSet::class.java) + val anException = assertThrows { + val resolver = CordaClassResolver(allButBlacklistedContext) + // CordaSerializableHashSet is @CordaSerializable, but extends the blacklisted HashSet. + resolver.getRegistration(CordaSerializableHashSet::class.java) + } + assertEquals("The superclass java.util.HashSet of net.corda.serialization.internal.CordaClassResolverTests\$CordaSerializableHashSet is blacklisted, so it cannot be used in serialization.", anException.message) } } diff --git a/testing/core-test-utils/src/main/kotlin/net/corda/coretesting/internal/RigorousMock.kt b/testing/core-test-utils/src/main/kotlin/net/corda/coretesting/internal/RigorousMock.kt index 5d040c907b..4a9f4c7e5d 100644 --- a/testing/core-test-utils/src/main/kotlin/net/corda/coretesting/internal/RigorousMock.kt +++ b/testing/core-test-utils/src/main/kotlin/net/corda/coretesting/internal/RigorousMock.kt @@ -79,7 +79,7 @@ private class SpectatorDefaultAnswer : DefaultAnswer() { ?: method.returnType!! } - private fun newSpectator(invocation: InvocationOnMock) = spectator(type)!!.also { log.info("New spectator {} for: {}", it, invocation.arguments) } + private fun newSpectator(invocation: InvocationOnMock) = spectator(type).also { log.info("New spectator {} for: {}", it, invocation.arguments) } private val spectators = try { val first = newSpectator(invocation) ConcurrentHashMap().apply { put(invocation, first) } diff --git a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt index fe24c77248..80023384cf 100644 --- a/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt +++ b/testing/node-driver/src/main/kotlin/net/corda/testing/node/internal/network/NetworkMapServer.kt @@ -232,7 +232,7 @@ class NetworkMapServer(private val pollInterval: Duration, null } requireNotNull(requestedParameters) - return Response.ok(requestedParameters!!.serialize().bytes).build() + return Response.ok(requestedParameters.serialize().bytes).build() } @GET diff --git a/tools/explorer/src/main/kotlin/net/corda/explorer/views/TransactionViewer.kt b/tools/explorer/src/main/kotlin/net/corda/explorer/views/TransactionViewer.kt index da9cf4c585..418e153235 100644 --- a/tools/explorer/src/main/kotlin/net/corda/explorer/views/TransactionViewer.kt +++ b/tools/explorer/src/main/kotlin/net/corda/explorer/views/TransactionViewer.kt @@ -57,7 +57,7 @@ class TransactionViewer : CordaView("Transactions") { override val widgets = listOf(CordaWidget(title, TransactionWidget(), icon)).observable() private var scrollPosition: Int = 0 - private lateinit var expander: ExpanderColumn + private var expander: ExpanderColumn private var txIdToScroll: SecureHash? = null // Passed as param. /** diff --git a/tools/loadtest/src/main/kotlin/net/corda/loadtest/NodeConnection.kt b/tools/loadtest/src/main/kotlin/net/corda/loadtest/NodeConnection.kt index 620cc92d99..3771aea1c4 100644 --- a/tools/loadtest/src/main/kotlin/net/corda/loadtest/NodeConnection.kt +++ b/tools/loadtest/src/main/kotlin/net/corda/loadtest/NodeConnection.kt @@ -47,7 +47,7 @@ class NodeConnection(val remoteNode: RemoteNode, private val jSchSession: Sessio val connection = rpcConnection require(connection != null) { "doWhileClientStopped called with no running client" } log.info("Stopping RPC proxy to ${remoteNode.hostname}, tunnel at $localTunnelAddress") - connection!!.close() + connection.close() try { return action() } finally {