mirror of
https://github.com/corda/corda.git
synced 2025-01-02 19:26:47 +00:00
Remove unused test class (#4139)
This commit is contained in:
parent
f159629e36
commit
8ddd8d383d
@ -13,170 +13,166 @@ import kotlin.test.assertEquals
|
|||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
|
||||||
class ContractsDSLTests {
|
class UnwantedCommand : CommandData
|
||||||
class UnwantedCommand : CommandData
|
|
||||||
|
|
||||||
interface TestCommands : CommandData {
|
interface TestCommands : CommandData {
|
||||||
class CommandOne : TypeOnlyCommandData(), TestCommands
|
class CommandOne : TypeOnlyCommandData(), TestCommands
|
||||||
class CommandTwo : TypeOnlyCommandData(), TestCommands
|
class CommandTwo : TypeOnlyCommandData(), TestCommands
|
||||||
|
}
|
||||||
|
|
||||||
|
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
||||||
|
val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
|
||||||
|
|
||||||
|
val validCommandOne = CommandWithParties(listOf(megaCorp.publicKey, miniCorp.publicKey), listOf(megaCorp.party, miniCorp.party), TestCommands.CommandOne())
|
||||||
|
val validCommandTwo = CommandWithParties(listOf(megaCorp.publicKey), listOf(megaCorp.party), TestCommands.CommandTwo())
|
||||||
|
val invalidCommand = CommandWithParties(emptyList(), emptyList(), UnwantedCommand())
|
||||||
|
|
||||||
|
@RunWith(Parameterized::class)
|
||||||
|
class RequireSingleCommandTests(private val testFunction: (Collection<CommandWithParties<CommandData>>) -> CommandWithParties<CommandData>,
|
||||||
|
@Suppress("UNUSED_PARAMETER") description: String) {
|
||||||
|
companion object {
|
||||||
|
@JvmStatic
|
||||||
|
@Parameterized.Parameters(name = "{1}")
|
||||||
|
fun data(): Collection<Array<Any>> = listOf(
|
||||||
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>> -> commands.requireSingleCommand<TestCommands>() }, "Inline version"),
|
||||||
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>> -> commands.requireSingleCommand(TestCommands::class.java) }, "Interop version")
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private companion object {
|
@Test
|
||||||
val megaCorp = TestIdentity(CordaX500Name("MegaCorp", "London", "GB"))
|
fun `check function returns one value`() {
|
||||||
val miniCorp = TestIdentity(CordaX500Name("MiniCorp", "London", "GB"))
|
val commands = listOf(validCommandOne, invalidCommand)
|
||||||
|
val returnedCommand = testFunction(commands)
|
||||||
val validCommandOne = CommandWithParties(listOf(megaCorp.publicKey, miniCorp.publicKey), listOf(megaCorp.party, miniCorp.party), TestCommands.CommandOne())
|
assertEquals(returnedCommand, validCommandOne, "they should be the same")
|
||||||
val validCommandTwo = CommandWithParties(listOf(megaCorp.publicKey), listOf(megaCorp.party), TestCommands.CommandTwo())
|
|
||||||
val invalidCommand = CommandWithParties(emptyList(), emptyList(), UnwantedCommand())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RunWith(Parameterized::class)
|
@Test(expected = IllegalArgumentException::class)
|
||||||
class RequireSingleCommandTests(private val testFunction: (Collection<CommandWithParties<CommandData>>) -> CommandWithParties<CommandData>,
|
fun `check error is thrown if more than one valid command`() {
|
||||||
@Suppress("UNUSED_PARAMETER") description: String) {
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
companion object {
|
testFunction(commands)
|
||||||
@JvmStatic
|
|
||||||
@Parameterized.Parameters(name = "{1}")
|
|
||||||
fun data(): Collection<Array<Any>> = listOf(
|
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>> -> commands.requireSingleCommand<TestCommands>() }, "Inline version"),
|
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>> -> commands.requireSingleCommand(TestCommands::class.java) }, "Interop version")
|
|
||||||
)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `check function returns one value`() {
|
|
||||||
val commands = listOf(validCommandOne, invalidCommand)
|
|
||||||
val returnedCommand = testFunction(commands)
|
|
||||||
assertEquals(returnedCommand, validCommandOne, "they should be the same")
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException::class)
|
|
||||||
fun `check error is thrown if more than one valid command`() {
|
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
|
||||||
testFunction(commands)
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
fun `check error is thrown when command is of wrong type`() {
|
|
||||||
val commands = listOf(invalidCommand)
|
|
||||||
Assertions.assertThatThrownBy { testFunction(commands) }
|
|
||||||
.isInstanceOf(IllegalStateException::class.java)
|
|
||||||
.hasMessage("Required net.corda.core.contracts.ContractsDSLTests.TestCommands command")
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@RunWith(Parameterized::class)
|
@Test
|
||||||
class SelectWithSingleInputsTests(private val testFunction: (Collection<CommandWithParties<CommandData>>, PublicKey?, AbstractParty?) -> Iterable<CommandWithParties<CommandData>>,
|
fun `check error is thrown when command is of wrong type`() {
|
||||||
@Suppress("UNUSED_PARAMETER") description: String) {
|
val commands = listOf(invalidCommand)
|
||||||
companion object {
|
Assertions.assertThatThrownBy { testFunction(commands) }
|
||||||
@JvmStatic
|
.isInstanceOf(IllegalStateException::class.java)
|
||||||
@Parameterized.Parameters(name = "{1}")
|
.hasMessage("Required net.corda.core.contracts.TestCommands command")
|
||||||
fun data(): Collection<Array<Any>> = listOf(
|
}
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signer: PublicKey?, party: AbstractParty? -> commands.select<TestCommands>(signer, party) }, "Inline version"),
|
}
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signer: PublicKey?, party: AbstractParty? -> commands.select(TestCommands::class.java, signer, party) }, "Interop version")
|
|
||||||
)
|
@RunWith(Parameterized::class)
|
||||||
}
|
class SelectWithSingleInputsTests(private val testFunction: (Collection<CommandWithParties<CommandData>>, PublicKey?, AbstractParty?) -> Iterable<CommandWithParties<CommandData>>,
|
||||||
|
@Suppress("UNUSED_PARAMETER") description: String) {
|
||||||
@Test
|
companion object {
|
||||||
fun `check that function returns all values`() {
|
@JvmStatic
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
@Parameterized.Parameters(name = "{1}")
|
||||||
testFunction(commands, null, null)
|
fun data(): Collection<Array<Any>> = listOf(
|
||||||
assertEquals(2, commands.size)
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signer: PublicKey?, party: AbstractParty? -> commands.select<TestCommands>(signer, party) }, "Inline version"),
|
||||||
assertTrue(commands.contains(validCommandOne))
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signer: PublicKey?, party: AbstractParty? -> commands.select(TestCommands::class.java, signer, party) }, "Interop version")
|
||||||
assertTrue(commands.contains(validCommandTwo))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function does not return invalid command types`() {
|
fun `check that function returns all values`() {
|
||||||
val commands = listOf(validCommandOne, invalidCommand)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, null, null).toList()
|
testFunction(commands, null, null)
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(2, commands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(commands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(invalidCommand))
|
assertTrue(commands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from valid signers`() {
|
fun `check that function does not return invalid command types`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, invalidCommand)
|
||||||
val filteredCommands = testFunction(commands, miniCorp.publicKey, null).toList()
|
val filteredCommands = testFunction(commands, null, null).toList()
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(1, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(validCommandTwo))
|
assertFalse(filteredCommands.contains(invalidCommand))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from valid parties`() {
|
fun `check that function returns commands from valid signers`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, null, miniCorp.party).toList()
|
val filteredCommands = testFunction(commands, miniCorp.publicKey, null).toList()
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(1, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(validCommandTwo))
|
assertFalse(filteredCommands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Test
|
||||||
@RunWith(Parameterized::class)
|
fun `check that function returns commands from valid parties`() {
|
||||||
class SelectWithMultipleInputsTests(private val testFunction: (Collection<CommandWithParties<CommandData>>, Collection<PublicKey>?, Collection<Party>?) -> Iterable<CommandWithParties<CommandData>>,
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
@Suppress("UNUSED_PARAMETER") description: String) {
|
val filteredCommands = testFunction(commands, null, miniCorp.party).toList()
|
||||||
companion object {
|
assertEquals(1, filteredCommands.size)
|
||||||
@JvmStatic
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
@Parameterized.Parameters(name = "{1}")
|
assertFalse(filteredCommands.contains(validCommandTwo))
|
||||||
fun data(): Collection<Array<Any>> = listOf(
|
}
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signers: Collection<PublicKey>?, party: Collection<Party>? -> commands.select<TestCommands>(signers, party) }, "Inline version"),
|
}
|
||||||
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signers: Collection<PublicKey>?, party: Collection<Party>? -> commands.select(TestCommands::class.java, signers, party) }, "Interop version")
|
|
||||||
)
|
@RunWith(Parameterized::class)
|
||||||
}
|
class SelectWithMultipleInputsTests(private val testFunction: (Collection<CommandWithParties<CommandData>>, Collection<PublicKey>?, Collection<Party>?) -> Iterable<CommandWithParties<CommandData>>,
|
||||||
|
@Suppress("UNUSED_PARAMETER") description: String) {
|
||||||
@Test
|
companion object {
|
||||||
fun `check that function returns all values`() {
|
@JvmStatic
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
@Parameterized.Parameters(name = "{1}")
|
||||||
testFunction(commands, null, null)
|
fun data(): Collection<Array<Any>> = listOf(
|
||||||
assertEquals(2, commands.size)
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signers: Collection<PublicKey>?, party: Collection<Party>? -> commands.select<TestCommands>(signers, party) }, "Inline version"),
|
||||||
assertTrue(commands.contains(validCommandOne))
|
arrayOf<Any>({ commands: Collection<CommandWithParties<CommandData>>, signers: Collection<PublicKey>?, party: Collection<Party>? -> commands.select(TestCommands::class.java, signers, party) }, "Interop version")
|
||||||
assertTrue(commands.contains(validCommandTwo))
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function does not return invalid command types`() {
|
fun `check that function returns all values`() {
|
||||||
val commands = listOf(validCommandOne, invalidCommand)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, null, null).toList()
|
testFunction(commands, null, null)
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(2, commands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(commands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(invalidCommand))
|
assertTrue(commands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from valid signers`() {
|
fun `check that function does not return invalid command types`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, invalidCommand)
|
||||||
val filteredCommands = testFunction(commands, listOf(megaCorp.publicKey), null).toList()
|
val filteredCommands = testFunction(commands, null, null).toList()
|
||||||
assertEquals(2, filteredCommands.size)
|
assertEquals(1, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertTrue(filteredCommands.contains(validCommandTwo))
|
assertFalse(filteredCommands.contains(invalidCommand))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from all valid signers`() {
|
fun `check that function returns commands from valid signers`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, listOf(miniCorp.publicKey, megaCorp.publicKey), null).toList()
|
val filteredCommands = testFunction(commands, listOf(megaCorp.publicKey), null).toList()
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(2, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(validCommandTwo))
|
assertTrue(filteredCommands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from valid parties`() {
|
fun `check that function returns commands from all valid signers`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, null, listOf(megaCorp.party)).toList()
|
val filteredCommands = testFunction(commands, listOf(miniCorp.publicKey, megaCorp.publicKey), null).toList()
|
||||||
assertEquals(2, filteredCommands.size)
|
assertEquals(1, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertTrue(filteredCommands.contains(validCommandTwo))
|
assertFalse(filteredCommands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `check that function returns commands from all valid parties`() {
|
fun `check that function returns commands from valid parties`() {
|
||||||
val commands = listOf(validCommandOne, validCommandTwo)
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
val filteredCommands = testFunction(commands, null, listOf(miniCorp.party, megaCorp.party)).toList()
|
val filteredCommands = testFunction(commands, null, listOf(megaCorp.party)).toList()
|
||||||
assertEquals(1, filteredCommands.size)
|
assertEquals(2, filteredCommands.size)
|
||||||
assertTrue(filteredCommands.contains(validCommandOne))
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
assertFalse(filteredCommands.contains(validCommandTwo))
|
assertTrue(filteredCommands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
fun `check that function returns commands from all valid parties`() {
|
||||||
|
val commands = listOf(validCommandOne, validCommandTwo)
|
||||||
|
val filteredCommands = testFunction(commands, null, listOf(miniCorp.party, megaCorp.party)).toList()
|
||||||
|
assertEquals(1, filteredCommands.size)
|
||||||
|
assertTrue(filteredCommands.contains(validCommandOne))
|
||||||
|
assertFalse(filteredCommands.contains(validCommandTwo))
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user