Use JUnit 5 for tests, bump dependencies
This commit is contained in:
@ -26,9 +26,9 @@ artifacts {
|
||||
dependencies {
|
||||
compile 'org.slf4j:slf4j-api'
|
||||
compile 'ch.dissem.msgpack:msgpack'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'org.hamcrest:hamcrest-library'
|
||||
testCompile 'com.nhaarman:mockito-kotlin'
|
||||
testCompile 'org.junit.jupiter:junit-jupiter-api'
|
||||
testRuntime 'org.junit.jupiter:junit-jupiter-engine'
|
||||
testCompile project(':cryptography-bc')
|
||||
}
|
||||
|
||||
|
@ -35,11 +35,9 @@ import ch.dissem.bitmessage.utils.TTL
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import ch.dissem.bitmessage.utils.UnixTime.MINUTE
|
||||
import com.nhaarman.mockito_kotlin.*
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.CoreMatchers.notNullValue
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
import kotlin.concurrent.thread
|
||||
|
||||
@ -55,7 +53,8 @@ class BitmessageContextTest {
|
||||
internal var removed = 0
|
||||
|
||||
override fun getItem(initialHash: ByteArray): ProofOfWorkRepository.Item {
|
||||
return items[InventoryVector(initialHash)] ?: throw IllegalArgumentException("${hex(initialHash)} not found in $items")
|
||||
return items[InventoryVector(initialHash)]
|
||||
?: throw IllegalArgumentException("${hex(initialHash)} not found in $items")
|
||||
}
|
||||
|
||||
override fun getItems(): List<ByteArray> {
|
||||
@ -72,7 +71,10 @@ class BitmessageContextTest {
|
||||
}
|
||||
|
||||
override fun putObject(objectMessage: ObjectMessage, nonceTrialsPerByte: Long, extraBytes: Long) {
|
||||
items.put(InventoryVector(cryptography().getInitialHash(objectMessage)), ProofOfWorkRepository.Item(objectMessage, nonceTrialsPerByte, extraBytes))
|
||||
items.put(
|
||||
InventoryVector(cryptography().getInitialHash(objectMessage)),
|
||||
ProofOfWorkRepository.Item(objectMessage, nonceTrialsPerByte, extraBytes)
|
||||
)
|
||||
added++
|
||||
}
|
||||
|
||||
@ -113,7 +115,7 @@ class BitmessageContextTest {
|
||||
TTL.msg = 2 * MINUTE
|
||||
}
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
testPowRepo.reset()
|
||||
}
|
||||
@ -202,60 +204,73 @@ class BitmessageContextTest {
|
||||
ctx.addSubscribtion(address)
|
||||
|
||||
verify(ctx.addresses, atLeastOnce()).save(address)
|
||||
assertThat(address.isSubscribed, `is`(true))
|
||||
assertTrue(address.isSubscribed)
|
||||
verify(ctx.internals.inventory).getObjects(eq(address.stream), any(), any())
|
||||
verify(testListener).receive(any())
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure identity is created`() {
|
||||
assertThat(ctx.createIdentity(false), notNullValue())
|
||||
assertNotNull(ctx.createIdentity(false))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure message is sent`() {
|
||||
ctx.send(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"), TestUtils.loadContact(),
|
||||
"Subject", "Message")
|
||||
ctx.send(
|
||||
TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"), TestUtils.loadContact(),
|
||||
"Subject", "Message"
|
||||
)
|
||||
verify(ctx.internals.proofOfWorkRepository, timeout(10000)).putObject(
|
||||
argThat { payload.type == ObjectType.MSG }, eq(1000L), eq(1000L))
|
||||
argThat { payload.type == ObjectType.MSG }, eq(1000L), eq(1000L)
|
||||
)
|
||||
assertEquals(2, testPowRepo.added)
|
||||
verify(ctx.messages, timeout(10000).atLeastOnce()).save(argThat<Plaintext> { type == Type.MSG })
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure pubkey is requested if it is missing`() {
|
||||
ctx.send(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"),
|
||||
ctx.send(
|
||||
TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"),
|
||||
BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"),
|
||||
"Subject", "Message")
|
||||
"Subject", "Message"
|
||||
)
|
||||
verify(testPowRepo, timeout(10000).atLeastOnce())
|
||||
.putObject(argThat { payload.type == ObjectType.GET_PUBKEY }, eq(1000L), eq(1000L))
|
||||
verify(ctx.messages, timeout(10000).atLeastOnce()).save(argThat<Plaintext> { type == Type.MSG })
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
@Test
|
||||
fun `ensure sender must be identity`() {
|
||||
ctx.send(BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"),
|
||||
BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"),
|
||||
"Subject", "Message")
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
ctx.send(
|
||||
BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"),
|
||||
BitmessageAddress("BM-opWQhvk9xtMFvQA2Kvetedpk8LkbraWHT"),
|
||||
"Subject", "Message"
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure broadcast is sent`() {
|
||||
ctx.broadcast(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"),
|
||||
"Subject", "Message")
|
||||
ctx.broadcast(
|
||||
TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"),
|
||||
"Subject", "Message"
|
||||
)
|
||||
verify(ctx.internals.proofOfWorkRepository, timeout(1000).atLeastOnce())
|
||||
.putObject(argThat { payload.type == ObjectType.BROADCAST }, eq(1000L), eq(1000L))
|
||||
verify(testPowEngine).calculateNonce(any(), any(), any<ProofOfWorkEngine.Callback>())
|
||||
verify(ctx.messages, timeout(10000).atLeastOnce()).save(argThat<Plaintext> { type == Type.BROADCAST })
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException::class)
|
||||
@Test
|
||||
fun `ensure sender without private key throws exception`() {
|
||||
val msg = Plaintext.Builder(Type.BROADCAST)
|
||||
.from(BitmessageAddress("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||
.message("Subject", "Message")
|
||||
.build()
|
||||
ctx.send(msg)
|
||||
assertThrows(IllegalArgumentException::class.java) {
|
||||
val msg = Plaintext.Builder(Type.BROADCAST)
|
||||
.from(BitmessageAddress("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||
.message("Subject", "Message")
|
||||
.build()
|
||||
ctx.send(msg)
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -326,6 +341,6 @@ class BitmessageContextTest {
|
||||
@Test
|
||||
fun `ensure status contains user agent`() {
|
||||
val userAgent = ctx.status().getProperty("user agent")?.value.toString()
|
||||
assertThat(userAgent, `is`("/Jabit:${BitmessageContext.version}/"))
|
||||
assertEquals("/Jabit:${BitmessageContext.version}/", userAgent)
|
||||
}
|
||||
}
|
||||
|
@ -21,9 +21,9 @@ import ch.dissem.bitmessage.entity.payload.V4Broadcast
|
||||
import ch.dissem.bitmessage.entity.payload.V5Broadcast
|
||||
import ch.dissem.bitmessage.utils.TestBase
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class DecryptionTest : TestBase() {
|
||||
@Test
|
||||
|
@ -34,8 +34,8 @@ import ch.dissem.bitmessage.utils.TestUtils
|
||||
import ch.dissem.bitmessage.utils.UnixTime.MINUTE
|
||||
import ch.dissem.bitmessage.utils.UnixTime.now
|
||||
import com.nhaarman.mockito_kotlin.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
/**
|
||||
* @author Christian Basler
|
||||
@ -47,7 +47,7 @@ class DefaultMessageListenerTest : TestBase() {
|
||||
cryptography = BouncyCryptography()
|
||||
)
|
||||
|
||||
@Before
|
||||
@BeforeAll
|
||||
fun setUp() {
|
||||
listener = ctx.networkListener as DefaultMessageListener
|
||||
}
|
||||
|
@ -24,9 +24,9 @@ import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||
import ch.dissem.bitmessage.utils.Singleton.cryptography
|
||||
import ch.dissem.bitmessage.utils.TestBase
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Assert.assertNotNull
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class EncryptionTest : TestBase() {
|
||||
@Test
|
||||
|
@ -28,10 +28,9 @@ import ch.dissem.bitmessage.ports.ProofOfWorkRepository
|
||||
import ch.dissem.bitmessage.utils.Singleton
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import com.nhaarman.mockito_kotlin.*
|
||||
import org.hamcrest.CoreMatchers.equalTo
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
@ -44,7 +43,7 @@ class ProofOfWorkServiceTest {
|
||||
|
||||
private var obj by Delegates.notNull<ObjectMessage>()
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
cryptography = spy(BouncyCryptography())
|
||||
Singleton.initialize(cryptography)
|
||||
@ -96,6 +95,6 @@ class ProofOfWorkServiceTest {
|
||||
verify(ctx.proofOfWorkRepository).removeObject(eq(initialHash))
|
||||
verify(ctx.inventory).storeObject(eq(objectMessage))
|
||||
verify(ctx.networkHandler).offer(eq(objectMessage.inventoryVector))
|
||||
assertThat(plaintext.inventoryVector, equalTo(objectMessage.inventoryVector))
|
||||
assertEquals(objectMessage.inventoryVector, plaintext.inventoryVector)
|
||||
}
|
||||
}
|
||||
|
@ -23,8 +23,8 @@ import ch.dissem.bitmessage.entity.payload.Pubkey
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||
import ch.dissem.bitmessage.utils.TestBase
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SignatureTest : TestBase() {
|
||||
@Test
|
||||
|
@ -22,16 +22,15 @@ import ch.dissem.bitmessage.entity.payload.Pubkey.Feature.INCLUDE_DESTINATION
|
||||
import ch.dissem.bitmessage.entity.payload.V4Pubkey
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||
import ch.dissem.bitmessage.utils.*
|
||||
import org.junit.Assert
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
|
||||
class BitmessageAddressTest : TestBase() {
|
||||
@Test
|
||||
fun `ensure feature flag is calculated correctly`() {
|
||||
Assert.assertEquals(1, Pubkey.Feature.bitfield(DOES_ACK))
|
||||
assertEquals(1, Pubkey.Feature.bitfield(DOES_ACK))
|
||||
assertEquals(2, Pubkey.Feature.bitfield(INCLUDE_DESTINATION))
|
||||
assertEquals(3, Pubkey.Feature.bitfield(DOES_ACK, INCLUDE_DESTINATION))
|
||||
}
|
||||
@ -74,7 +73,7 @@ class BitmessageAddressTest : TestBase() {
|
||||
try {
|
||||
address.pubkey = pubkey
|
||||
} catch (e: Exception) {
|
||||
fail(e.message)
|
||||
fail<Unit>(e.message)
|
||||
}
|
||||
|
||||
}
|
||||
@ -82,7 +81,7 @@ class BitmessageAddressTest : TestBase() {
|
||||
@Test
|
||||
fun `ensure V3Pubkey can be imported`() {
|
||||
val address = BitmessageAddress("BM-2D9Vc5rFxxR5vTi53T9gkLfemViHRMVLQZ")
|
||||
Assert.assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.ripe)
|
||||
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), address.ripe)
|
||||
|
||||
val objectMessage = TestUtils.loadObjectMessage(3, "V3Pubkey.payload")
|
||||
val pubkey = objectMessage.payload as Pubkey
|
||||
@ -90,7 +89,7 @@ class BitmessageAddressTest : TestBase() {
|
||||
try {
|
||||
address.pubkey = pubkey
|
||||
} catch (e: Exception) {
|
||||
fail(e.message)
|
||||
fail<Unit>(e.message)
|
||||
}
|
||||
|
||||
assertArrayEquals(Bytes.fromHex("007402be6e76c3cb87caa946d0c003a3d4d8e1d5"), pubkey.ripe)
|
||||
@ -107,7 +106,7 @@ class BitmessageAddressTest : TestBase() {
|
||||
try {
|
||||
address.pubkey = pubkey
|
||||
} catch (e: Exception) {
|
||||
fail(e.message)
|
||||
fail<Unit>(e.message)
|
||||
}
|
||||
|
||||
assertTrue(address.has(DOES_ACK))
|
||||
|
File diff suppressed because one or more lines are too long
@ -24,9 +24,8 @@ import ch.dissem.bitmessage.entity.valueobject.extended.Message
|
||||
import ch.dissem.bitmessage.factory.Factory
|
||||
import ch.dissem.bitmessage.utils.TestBase
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import org.hamcrest.Matchers.`is`
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.*
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.ObjectInputStream
|
||||
@ -95,7 +94,7 @@ class SerializationTest : TestBase() {
|
||||
received.isAccessible = true
|
||||
received.set(actual, null)
|
||||
|
||||
assertThat(expected, `is`(actual))
|
||||
assertEquals(actual, expected)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -103,10 +102,12 @@ class SerializationTest : TestBase() {
|
||||
val expected = Plaintext.Builder(MSG)
|
||||
.from(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||
.to(TestUtils.loadContact())
|
||||
.message(Message.Builder()
|
||||
.subject("Subject")
|
||||
.body("Message")
|
||||
.build())
|
||||
.message(
|
||||
Message.Builder()
|
||||
.subject("Subject")
|
||||
.body("Message")
|
||||
.build()
|
||||
)
|
||||
.ackData("ackMessage".toByteArray())
|
||||
.signature(ByteArray(0))
|
||||
.build()
|
||||
@ -127,10 +128,12 @@ class SerializationTest : TestBase() {
|
||||
fun `ensure plaintext without recipient can be serialized (needed for saving drafts)`() {
|
||||
val expected = Plaintext.Builder(MSG)
|
||||
.from(TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8"))
|
||||
.message(Message.Builder()
|
||||
.subject("Subject")
|
||||
.body("Message")
|
||||
.build())
|
||||
.message(
|
||||
Message.Builder()
|
||||
.subject("Subject")
|
||||
.body("Message")
|
||||
.build()
|
||||
)
|
||||
.signature(ByteArray(0))
|
||||
.status(Plaintext.Status.DRAFT)
|
||||
.build()
|
||||
|
@ -20,18 +20,24 @@ import ch.dissem.bitmessage.utils.Bytes
|
||||
import ch.dissem.bitmessage.utils.CallbackWaiter
|
||||
import ch.dissem.bitmessage.utils.Singleton.cryptography
|
||||
import ch.dissem.bitmessage.utils.TestBase
|
||||
import org.junit.Assert.assertTrue
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertTimeoutPreemptively
|
||||
import org.junit.jupiter.api.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.time.Duration.ofSeconds
|
||||
|
||||
class ProofOfWorkEngineTest : TestBase() {
|
||||
@Test(timeout = 90000)
|
||||
@Test
|
||||
fun `test SimplePOWEngine`() {
|
||||
testPOW(SimplePOWEngine())
|
||||
assertTimeoutPreemptively(ofSeconds(90)) {
|
||||
testPOW(SimplePOWEngine())
|
||||
}
|
||||
}
|
||||
|
||||
@Test(timeout = 90000)
|
||||
@Test
|
||||
fun `test MultiThreadedPOWEngine`() {
|
||||
testPOW(MultiThreadedPOWEngine())
|
||||
assertTimeoutPreemptively(ofSeconds(90)) {
|
||||
testPOW(MultiThreadedPOWEngine())
|
||||
}
|
||||
}
|
||||
|
||||
private fun testPOW(engine: ProofOfWorkEngine) {
|
||||
@ -65,6 +71,6 @@ class ProofOfWorkEngineTest : TestBase() {
|
||||
val nonce2 = waiter2.waitForValue()!!
|
||||
println("Calculating nonce1 took ${waiter2.time}ms")
|
||||
assertTrue(Bytes.lt(cryptography().doubleSha512(nonce2, initialHash2), target2, 8))
|
||||
assertTrue("Second nonce1 must be quicker to find", waiter1.time > waiter2.time)
|
||||
assertTrue(waiter1.time > waiter2.time, "Second nonce1 must be quicker to find")
|
||||
}
|
||||
}
|
||||
|
@ -17,9 +17,8 @@
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography
|
||||
import org.hamcrest.Matchers.`is`
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class Base64Test {
|
||||
@Test
|
||||
@ -29,7 +28,7 @@ class Base64Test {
|
||||
val data = cryptography.randomBytes(i)
|
||||
val string = Base64.encodeToString(data)
|
||||
val decoded = Base64.decode(string)
|
||||
assertThat(decoded, `is`(data))
|
||||
assertEquals(data, decoded)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,10 +16,10 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Assert.assertArrayEquals
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Ignore
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertArrayEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Disabled
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.math.BigInteger
|
||||
import java.util.*
|
||||
|
||||
@ -46,7 +46,11 @@ class BytesTest {
|
||||
for (i in 1..255) {
|
||||
val bytes = byteArrayOf(0, v.toByte())
|
||||
Bytes.inc(bytes, i.toByte())
|
||||
assertArrayEquals("value = " + v + "; inc = " + i + "; expected = " + (v + i), TestUtils.int16(v + i), bytes)
|
||||
assertArrayEquals(
|
||||
TestUtils.int16(v + i),
|
||||
bytes,
|
||||
"value = " + v + "; inc = " + i + "; expected = " + (v + i)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -55,7 +59,7 @@ class BytesTest {
|
||||
* This test is used to compare different implementations of the single byte lt comparison. It an safely be ignored.
|
||||
*/
|
||||
@Test
|
||||
@Ignore
|
||||
@Disabled
|
||||
fun `test lower than single byte`() {
|
||||
val a = ByteArray(1)
|
||||
val b = ByteArray(1)
|
||||
@ -85,10 +89,13 @@ class BytesTest {
|
||||
val a = BigInteger.valueOf(rnd.nextLong()).pow(rnd.nextInt(5) + 1).abs()
|
||||
val b = BigInteger.valueOf(rnd.nextLong()).pow(rnd.nextInt(5) + 1).abs()
|
||||
println("a = " + a.toString(16) + "\tb = " + b.toString(16))
|
||||
assertEquals(a.compareTo(b) == -1, Bytes.lt(
|
||||
Bytes.expand(a.toByteArray(), 100),
|
||||
Bytes.expand(b.toByteArray(), 100),
|
||||
100))
|
||||
assertEquals(
|
||||
a.compareTo(b) == -1, Bytes.lt(
|
||||
Bytes.expand(a.toByteArray(), 100),
|
||||
Bytes.expand(b.toByteArray(), 100),
|
||||
100
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -16,17 +16,12 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import java.util.LinkedList
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class CollectionsTest {
|
||||
@Test
|
||||
fun `ensure select random returns maximum possible items`() {
|
||||
val list = LinkedList<Int>()
|
||||
list += 0..9
|
||||
assertEquals(9, Collections.selectRandom(9, list).size)
|
||||
assertEquals(9, Collections.selectRandom(9, listOf(0..9)).size)
|
||||
}
|
||||
}
|
||||
|
@ -24,9 +24,8 @@ import ch.dissem.bitmessage.entity.valueobject.extended.Message
|
||||
import ch.dissem.bitmessage.ports.MessageRepository
|
||||
import ch.dissem.bitmessage.utils.TestUtils.RANDOM
|
||||
import com.nhaarman.mockito_kotlin.*
|
||||
import org.hamcrest.Matchers.`is`
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
|
||||
class ConversationServiceTest : TestBase() {
|
||||
@ -45,7 +44,7 @@ class ConversationServiceTest : TestBase() {
|
||||
|
||||
doReturn(expected).whenever(conversationService).getConversation(any<UUID>())
|
||||
val actual = conversationService.getConversation(UUID.randomUUID())
|
||||
assertThat(actual, `is`(expected))
|
||||
Assertions.assertEquals(expected, actual)
|
||||
}
|
||||
|
||||
companion object {
|
||||
@ -53,57 +52,69 @@ class ConversationServiceTest : TestBase() {
|
||||
fun conversation(alice: BitmessageAddress, bob: BitmessageAddress): List<Plaintext> {
|
||||
val result = LinkedList<Plaintext>()
|
||||
|
||||
val older = plaintext(alice, bob,
|
||||
val older = plaintext(
|
||||
alice, bob,
|
||||
Message.Builder()
|
||||
.subject("hey there")
|
||||
.body("does it work?")
|
||||
.build(),
|
||||
Plaintext.Status.SENT)
|
||||
Plaintext.Status.SENT
|
||||
)
|
||||
result.add(older)
|
||||
|
||||
val root = plaintext(alice, bob,
|
||||
val root = plaintext(
|
||||
alice, bob,
|
||||
Message.Builder()
|
||||
.subject("new test")
|
||||
.body("There's a new test in town!")
|
||||
.build(),
|
||||
Plaintext.Status.SENT)
|
||||
Plaintext.Status.SENT
|
||||
)
|
||||
result.add(root)
|
||||
|
||||
result.add(
|
||||
plaintext(bob, alice,
|
||||
plaintext(
|
||||
bob, alice,
|
||||
Message.Builder()
|
||||
.subject("Re: new test (1a)")
|
||||
.body("Nice!")
|
||||
.addParent(root)
|
||||
.build(),
|
||||
Plaintext.Status.RECEIVED)
|
||||
Plaintext.Status.RECEIVED
|
||||
)
|
||||
)
|
||||
|
||||
val latest = plaintext(bob, alice,
|
||||
val latest = plaintext(
|
||||
bob, alice,
|
||||
Message.Builder()
|
||||
.subject("Re: new test (2b)")
|
||||
.body("PS: it did work!")
|
||||
.addParent(root)
|
||||
.addParent(older)
|
||||
.build(),
|
||||
Plaintext.Status.RECEIVED)
|
||||
Plaintext.Status.RECEIVED
|
||||
)
|
||||
result.add(latest)
|
||||
|
||||
result.add(
|
||||
plaintext(alice, bob,
|
||||
plaintext(
|
||||
alice, bob,
|
||||
Message.Builder()
|
||||
.subject("Re: new test (2)")
|
||||
.body("")
|
||||
.addParent(latest)
|
||||
.build(),
|
||||
Plaintext.Status.DRAFT)
|
||||
Plaintext.Status.DRAFT
|
||||
)
|
||||
)
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
fun plaintext(from: BitmessageAddress, to: BitmessageAddress,
|
||||
content: ExtendedEncoding, status: Plaintext.Status): Plaintext {
|
||||
fun plaintext(
|
||||
from: BitmessageAddress, to: BitmessageAddress,
|
||||
content: ExtendedEncoding, status: Plaintext.Status
|
||||
): Plaintext {
|
||||
val builder = Plaintext.Builder(MSG)
|
||||
.IV(TestUtils.randomInventoryVector())
|
||||
.from(from)
|
||||
|
@ -16,8 +16,8 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
|
@ -16,8 +16,9 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assumptions
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.io.ByteArrayOutputStream
|
||||
|
||||
class EncodeTest {
|
||||
@ -111,7 +112,8 @@ class EncodeTest {
|
||||
|
||||
|
||||
fun checkBytes(stream: ByteArrayOutputStream, vararg bytes: Int) {
|
||||
assertEquals(bytes.size, stream.size())
|
||||
Assumptions.assumeTrue(bytes.size == stream.size())
|
||||
|
||||
val streamBytes = stream.toByteArray()
|
||||
|
||||
for (i in bytes.indices) {
|
||||
|
@ -16,14 +16,12 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class SqlStringsTest {
|
||||
@Test
|
||||
fun `ensure join works with long array`() {
|
||||
val test = longArrayOf(1L, 2L)
|
||||
assertEquals("1, 2", SqlStrings.join(*test))
|
||||
assertEquals("1, 2", SqlStrings.join(1L, 2L))
|
||||
}
|
||||
}
|
||||
|
@ -16,9 +16,8 @@
|
||||
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import org.junit.Test
|
||||
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Test
|
||||
|
||||
class StringsTest {
|
||||
@Test
|
||||
|
@ -17,15 +17,16 @@
|
||||
package ch.dissem.bitmessage.utils
|
||||
|
||||
import ch.dissem.bitmessage.cryptography.bc.BouncyCryptography
|
||||
import org.junit.BeforeClass
|
||||
import org.junit.jupiter.api.BeforeAll
|
||||
|
||||
/**
|
||||
* @author Christian Basler
|
||||
*/
|
||||
open class TestBase {
|
||||
companion object {
|
||||
@BeforeClass
|
||||
@JvmStatic fun setUpClass() {
|
||||
@BeforeAll
|
||||
@JvmStatic
|
||||
fun setUpClass() {
|
||||
Singleton.initialize(BouncyCryptography())
|
||||
}
|
||||
}
|
||||
|
@ -29,7 +29,7 @@ import ch.dissem.bitmessage.factory.Factory
|
||||
import ch.dissem.bitmessage.ports.*
|
||||
import com.nhaarman.mockito_kotlin.mock
|
||||
import com.nhaarman.mockito_kotlin.spy
|
||||
import org.junit.Assert.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import java.io.ByteArrayInputStream
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.InputStream
|
||||
@ -54,7 +54,8 @@ object TestUtils {
|
||||
fun loadObjectMessage(version: Int, resourceName: String): ObjectMessage {
|
||||
val data = getBytes(resourceName)
|
||||
val input = ByteArrayInputStream(data)
|
||||
return Factory.getObjectMessage(version, input, data.size) ?: throw NoSuchElementException("error loading object message")
|
||||
return Factory.getObjectMessage(version, input, data.size)
|
||||
?: throw NoSuchElementException("error loading object message")
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
Reference in New Issue
Block a user