Use JUnit 5 for tests, bump dependencies
This commit is contained in:
@ -13,9 +13,11 @@ uploadArchives {
|
||||
dependencies {
|
||||
compile project(':core')
|
||||
compile 'org.flywaydb:flyway-core'
|
||||
testCompile 'junit:junit'
|
||||
testCompile 'com.h2database:h2'
|
||||
testCompile 'org.hamcrest:java-hamcrest'
|
||||
testCompile 'com.nhaarman:mockito-kotlin'
|
||||
testCompile 'org.junit.jupiter:junit-jupiter-api'
|
||||
testRuntime 'org.junit.jupiter:junit-jupiter-engine'
|
||||
testCompile project(path: ':core', configuration: 'testArtifacts')
|
||||
testCompile project(':cryptography-bc')
|
||||
}
|
||||
|
@ -19,9 +19,9 @@ package ch.dissem.bitmessage.repository
|
||||
import ch.dissem.bitmessage.entity.BitmessageAddress
|
||||
import ch.dissem.bitmessage.entity.payload.Pubkey.Feature.DOES_ACK
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||
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
|
||||
|
||||
class JdbcAddressRepositoryTest : TestBase() {
|
||||
private val CONTACT_A = "BM-2cW7cD5cDQJDNkE7ibmyTxfvGAmnPqa9Vt"
|
||||
@ -34,7 +34,7 @@ class JdbcAddressRepositoryTest : TestBase() {
|
||||
private lateinit var config: TestJdbcConfig
|
||||
private lateinit var repo: JdbcAddressRepository
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
config = TestJdbcConfig()
|
||||
config.reset()
|
||||
|
@ -26,9 +26,9 @@ import ch.dissem.bitmessage.entity.valueobject.InventoryVector
|
||||
import ch.dissem.bitmessage.ports.Inventory
|
||||
import ch.dissem.bitmessage.utils.UnixTime.DAY
|
||||
import ch.dissem.bitmessage.utils.UnixTime.now
|
||||
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.*
|
||||
|
||||
class JdbcInventoryTest : TestBase() {
|
||||
@ -39,7 +39,7 @@ class JdbcInventoryTest : TestBase() {
|
||||
private lateinit var inventoryVector2: InventoryVector
|
||||
private lateinit var inventoryVectorIgnore: InventoryVector
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
config = TestJdbcConfig()
|
||||
config.reset()
|
||||
|
@ -18,15 +18,15 @@ package ch.dissem.bitmessage.repository
|
||||
|
||||
import ch.dissem.bitmessage.entity.valueobject.Label
|
||||
import ch.dissem.bitmessage.ports.LabelRepository
|
||||
import org.junit.Assert.assertEquals
|
||||
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
|
||||
|
||||
class JdbcLabelRepositoryTest : TestBase() {
|
||||
|
||||
private lateinit var repo: LabelRepository
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
val config = TestJdbcConfig()
|
||||
config.reset()
|
||||
|
@ -35,10 +35,12 @@ import org.hamcrest.BaseMatcher
|
||||
import org.hamcrest.CoreMatchers.`is`
|
||||
import org.hamcrest.Description
|
||||
import org.hamcrest.Matcher
|
||||
import org.hamcrest.MatcherAssert.assertThat
|
||||
import org.hamcrest.Matchers.*
|
||||
import org.junit.Assert.*
|
||||
import org.junit.Before
|
||||
import org.junit.Test
|
||||
import org.junit.jupiter.api.Assertions.assertEquals
|
||||
import org.junit.jupiter.api.Assertions.assertNotNull
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
|
||||
class JdbcMessageRepositoryTest : TestBase() {
|
||||
@ -54,7 +56,7 @@ class JdbcMessageRepositoryTest : TestBase() {
|
||||
private lateinit var drafts: Label
|
||||
private lateinit var unread: Label
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
val config = TestJdbcConfig()
|
||||
config.reset()
|
||||
@ -230,6 +232,7 @@ class JdbcMessageRepositoryTest : TestBase() {
|
||||
val parent = storeConversation()
|
||||
|
||||
val responses = repo.findResponses(parent)
|
||||
|
||||
assertThat(responses, hasSize<Plaintext>(2))
|
||||
assertThat(responses, hasItem(hasMessage("Re: new test", "Nice!")))
|
||||
assertThat(responses, hasItem(hasMessage("Re: new test", "PS: it did work!")))
|
||||
|
@ -19,11 +19,10 @@ package ch.dissem.bitmessage.repository
|
||||
import ch.dissem.bitmessage.entity.valueobject.NetworkAddress
|
||||
import ch.dissem.bitmessage.ports.NodeRegistry
|
||||
import ch.dissem.bitmessage.utils.UnixTime.now
|
||||
import org.hamcrest.Matchers.empty
|
||||
import org.junit.Assert.assertEquals
|
||||
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.Assertions.assertTrue
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Test
|
||||
import java.util.*
|
||||
|
||||
/**
|
||||
@ -34,23 +33,25 @@ class JdbcNodeRegistryTest : TestBase() {
|
||||
private lateinit var config: TestJdbcConfig
|
||||
private lateinit var registry: NodeRegistry
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
config = TestJdbcConfig()
|
||||
config.reset()
|
||||
registry = JdbcNodeRegistry(config)
|
||||
|
||||
registry.offerAddresses(Arrays.asList(
|
||||
registry.offerAddresses(
|
||||
Arrays.asList(
|
||||
createAddress(1, 8444, 1, now),
|
||||
createAddress(2, 8444, 1, now),
|
||||
createAddress(3, 8444, 1, now),
|
||||
createAddress(4, 8444, 2, now)
|
||||
))
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure getKnownNodes() without streams yields empty`() {
|
||||
assertThat(registry.getKnownAddresses(10), empty<NetworkAddress>())
|
||||
assertTrue(registry.getKnownAddresses(10).isEmpty())
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -71,11 +72,13 @@ class JdbcNodeRegistryTest : TestBase() {
|
||||
|
||||
@Test
|
||||
fun `ensure offered addresses are added`() {
|
||||
registry.offerAddresses(Arrays.asList(
|
||||
registry.offerAddresses(
|
||||
Arrays.asList(
|
||||
createAddress(1, 8444, 1, now),
|
||||
createAddress(10, 8444, 1, now),
|
||||
createAddress(11, 8444, 1, now)
|
||||
))
|
||||
)
|
||||
)
|
||||
|
||||
var knownAddresses = registry.getKnownAddresses(1000, 1)
|
||||
assertEquals(5, knownAddresses.size.toLong())
|
||||
@ -88,10 +91,10 @@ class JdbcNodeRegistryTest : TestBase() {
|
||||
|
||||
private fun createAddress(lastByte: Int, port: Int, stream: Long, time: Long): NetworkAddress {
|
||||
return NetworkAddress.Builder()
|
||||
.ipv6(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, lastByte)
|
||||
.port(port)
|
||||
.stream(stream)
|
||||
.time(time)
|
||||
.build()
|
||||
.ipv6(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, lastByte)
|
||||
.port(port)
|
||||
.stream(stream)
|
||||
.time(time)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
@ -22,9 +22,6 @@ import ch.dissem.bitmessage.entity.Plaintext
|
||||
import ch.dissem.bitmessage.entity.Plaintext.Type.MSG
|
||||
import ch.dissem.bitmessage.entity.payload.GenericPayload
|
||||
import ch.dissem.bitmessage.entity.payload.GetPubkey
|
||||
import ch.dissem.bitmessage.entity.payload.ObjectPayload
|
||||
import ch.dissem.bitmessage.entity.payload.Pubkey
|
||||
import ch.dissem.bitmessage.entity.valueobject.PrivateKey
|
||||
import ch.dissem.bitmessage.ports.AddressRepository
|
||||
import ch.dissem.bitmessage.ports.MessageRepository
|
||||
import ch.dissem.bitmessage.ports.ProofOfWorkRepository.Item
|
||||
@ -32,11 +29,9 @@ import ch.dissem.bitmessage.utils.Singleton.cryptography
|
||||
import ch.dissem.bitmessage.utils.TestUtils
|
||||
import ch.dissem.bitmessage.utils.UnixTime
|
||||
import ch.dissem.bitmessage.utils.UnixTime.MINUTE
|
||||
import org.hamcrest.CoreMatchers.*
|
||||
import org.junit.Assert.assertThat
|
||||
import org.junit.Assert.assertTrue
|
||||
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 kotlin.properties.Delegates
|
||||
|
||||
/**
|
||||
@ -51,7 +46,7 @@ class JdbcProofOfWorkRepositoryTest : TestBase() {
|
||||
private var initialHash1: ByteArray by Delegates.notNull<ByteArray>()
|
||||
private var initialHash2: ByteArray by Delegates.notNull<ByteArray>()
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
fun setUp() {
|
||||
config = TestJdbcConfig()
|
||||
config.reset()
|
||||
@ -66,9 +61,11 @@ class JdbcProofOfWorkRepositoryTest : TestBase() {
|
||||
cryptography = cryptography()
|
||||
)
|
||||
|
||||
repo.putObject(ObjectMessage.Builder()
|
||||
.payload(GetPubkey(BitmessageAddress("BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn"))).build(),
|
||||
1000, 1000)
|
||||
repo.putObject(
|
||||
ObjectMessage.Builder()
|
||||
.payload(GetPubkey(BitmessageAddress("BM-2DAjcCFrqFrp88FUxExhJ9kPqHdunQmiyn"))).build(),
|
||||
1000, 1000
|
||||
)
|
||||
initialHash1 = repo.getItems()[0]
|
||||
|
||||
val sender = TestUtils.loadIdentity("BM-2cSqjfJ8xK6UUn5Rw3RpdGQ9RsDkBhWnS8")
|
||||
@ -84,21 +81,25 @@ class JdbcProofOfWorkRepositoryTest : TestBase() {
|
||||
.build()
|
||||
messageRepo.save(plaintext)
|
||||
initialHash2 = cryptography().getInitialHash(plaintext.ackMessage!!)
|
||||
repo.putObject(Item(
|
||||
plaintext.ackMessage!!,
|
||||
1000, 1000,
|
||||
UnixTime.now + 10 * MINUTE,
|
||||
plaintext
|
||||
))
|
||||
repo.putObject(
|
||||
Item(
|
||||
plaintext.ackMessage!!,
|
||||
1000, 1000,
|
||||
UnixTime.now + 10 * MINUTE,
|
||||
plaintext
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure object is stored`() {
|
||||
val sizeBefore = repo.getItems().size
|
||||
repo.putObject(ObjectMessage.Builder()
|
||||
.payload(GetPubkey(BitmessageAddress("BM-2D9U2hv3YBMHM1zERP32anKfVKohyPN9x2"))).build(),
|
||||
1000, 1000)
|
||||
assertThat(repo.getItems().size, `is`(sizeBefore + 1))
|
||||
repo.putObject(
|
||||
ObjectMessage.Builder()
|
||||
.payload(GetPubkey(BitmessageAddress("BM-2D9U2hv3YBMHM1zERP32anKfVKohyPN9x2"))).build(),
|
||||
1000, 1000
|
||||
)
|
||||
assertEquals(sizeBefore + 1, repo.getItems().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
@ -116,40 +117,42 @@ class JdbcProofOfWorkRepositoryTest : TestBase() {
|
||||
.status(Plaintext.Status.DOING_PROOF_OF_WORK)
|
||||
.build()
|
||||
messageRepo.save(plaintext)
|
||||
repo.putObject(Item(
|
||||
plaintext.ackMessage!!,
|
||||
1000, 1000,
|
||||
UnixTime.now + 10 * MINUTE,
|
||||
plaintext
|
||||
))
|
||||
assertThat(repo.getItems().size, `is`(sizeBefore + 1))
|
||||
repo.putObject(
|
||||
Item(
|
||||
plaintext.ackMessage!!,
|
||||
1000, 1000,
|
||||
UnixTime.now + 10 * MINUTE,
|
||||
plaintext
|
||||
)
|
||||
)
|
||||
assertEquals(sizeBefore + 1, repo.getItems().size)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure item can be retrieved`() {
|
||||
val item = repo.getItem(initialHash1)
|
||||
assertThat(item, notNullValue())
|
||||
assertThat<ObjectPayload>(item.objectMessage.payload, instanceOf<ObjectPayload>(GetPubkey::class.java))
|
||||
assertThat(item.nonceTrialsPerByte, `is`(1000L))
|
||||
assertThat(item.extraBytes, `is`(1000L))
|
||||
assertTrue(item.objectMessage.payload is GetPubkey)
|
||||
assertEquals(1000L, item.nonceTrialsPerByte)
|
||||
assertEquals(1000L, item.extraBytes)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `ensure ack item can be retrieved`() {
|
||||
val item = repo.getItem(initialHash2)
|
||||
assertThat(item, notNullValue())
|
||||
assertThat<ObjectPayload>(item.objectMessage.payload, instanceOf<ObjectPayload>(GenericPayload::class.java))
|
||||
assertThat(item.nonceTrialsPerByte, `is`(1000L))
|
||||
assertThat(item.extraBytes, `is`(1000L))
|
||||
assertThat(item.expirationTime, not<Number>(0))
|
||||
assertThat(item.message, notNullValue())
|
||||
assertThat<PrivateKey>(item.message?.from?.privateKey, notNullValue())
|
||||
assertThat<Pubkey>(item.message?.to?.pubkey, notNullValue())
|
||||
assertTrue(item.objectMessage.payload is GenericPayload)
|
||||
assertEquals(1000L, item.nonceTrialsPerByte)
|
||||
assertEquals(1000L, item.extraBytes)
|
||||
assertTrue(item.expirationTime ?: 0L > 0L)
|
||||
assertNotNull(item.message)
|
||||
assertNotNull(item.message?.from?.privateKey)
|
||||
assertNotNull(item.message?.to?.pubkey)
|
||||
}
|
||||
|
||||
@Test(expected = RuntimeException::class)
|
||||
@Test
|
||||
fun `ensure retrieving nonexisting item causes exception`() {
|
||||
repo.getItem(ByteArray(0))
|
||||
assertThrows(RuntimeException::class.java) {
|
||||
repo.getItem(ByteArray(0))
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Reference in New Issue
Block a user