Use assert methods from test framework. Don't use Java assert. (#625)

This commit is contained in:
Chris Rankin 2017-05-03 17:32:30 +01:00 committed by GitHub
parent a1fd215863
commit e22ad19fcd
12 changed files with 56 additions and 59 deletions

View File

@ -4,16 +4,14 @@ import net.corda.core.contracts.*
import org.junit.Test
import java.time.LocalDate
import java.util.*
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotEquals
import kotlin.test.*
class FinanceTypesTest {
@Test
fun `make sure Amount has decimal places`() {
val x = Amount(1, Currency.getInstance("USD"))
assert("0.01" in x.toString())
assertTrue("0.01" in x.toString())
}
@Test
@ -47,7 +45,7 @@ class FinanceTypesTest {
fun `schedule generator 1`() {
val ret = BusinessCalendar.createGenericSchedule(startDate = LocalDate.of(2014, 11, 25), period = Frequency.Monthly, noOfAdditionalPeriods = 3)
// We know that Jan 25th 2015 is on the weekend -> It should not be in this list returned.
assert(LocalDate.of(2015, 1, 25) !in ret)
assertFalse(LocalDate.of(2015, 1, 25) in ret)
println(ret)
}
@ -55,7 +53,7 @@ class FinanceTypesTest {
fun `schedule generator 2`() {
val ret = BusinessCalendar.createGenericSchedule(startDate = LocalDate.of(2015, 11, 25), period = Frequency.Monthly, noOfAdditionalPeriods = 3, calendar = BusinessCalendar.getInstance("London"), dateRollConvention = DateRollConvention.Following)
// Xmas should not be in the list!
assert(LocalDate.of(2015, 12, 25) !in ret)
assertFalse(LocalDate.of(2015, 12, 25) in ret)
println(ret)
}
@ -65,14 +63,14 @@ class FinanceTypesTest {
val cal = BusinessCalendar.getInstance("London")
val holdates = cal.holidayDates
println(holdates)
assert(LocalDate.of(2016, 12, 27) in holdates) // Christmas this year is at the weekend...
assertTrue(LocalDate.of(2016, 12, 27) in holdates) // Christmas this year is at the weekend...
}
@Test
fun `create a US UK calendar`() {
val cal = BusinessCalendar.getInstance("London", "NewYork")
assert(LocalDate.of(2016, 7, 4) in cal.holidayDates) // The most American of holidays
assert(LocalDate.of(2016, 8, 29) in cal.holidayDates) // August Bank Holiday for brits only
assertTrue(LocalDate.of(2016, 7, 4) in cal.holidayDates) // The most American of holidays
assertTrue(LocalDate.of(2016, 8, 29) in cal.holidayDates) // August Bank Holiday for brits only
println("Calendar contains both US and UK holidays")
}
@ -80,14 +78,14 @@ class FinanceTypesTest {
fun `calendar test of modified following`() {
val ldn = BusinessCalendar.getInstance("London")
val result = ldn.applyRollConvention(LocalDate.of(2016, 12, 25), DateRollConvention.ModifiedFollowing)
assert(result == LocalDate.of(2016, 12, 28))
assertEquals(LocalDate.of(2016, 12, 28), result)
}
@Test
fun `calendar test of modified following pt 2`() {
val ldn = BusinessCalendar.getInstance("London")
val result = ldn.applyRollConvention(LocalDate.of(2016, 12, 31), DateRollConvention.ModifiedFollowing)
assert(result == LocalDate.of(2016, 12, 30))
assertEquals(LocalDate.of(2016, 12, 30), result)
}
@ -95,21 +93,21 @@ class FinanceTypesTest {
fun `calendar test of modified previous`() {
val ldn = BusinessCalendar.getInstance("London")
val result = ldn.applyRollConvention(LocalDate.of(2016, 1, 1), DateRollConvention.ModifiedPrevious)
assert(result == LocalDate.of(2016, 1, 4))
assertEquals(LocalDate.of(2016, 1, 4), result)
}
@Test
fun `calendar test of previous`() {
val ldn = BusinessCalendar.getInstance("London")
val result = ldn.applyRollConvention(LocalDate.of(2016, 12, 25), DateRollConvention.Previous)
assert(result == LocalDate.of(2016, 12, 23))
assertEquals(LocalDate.of(2016, 12, 23), result)
}
@Test
fun `calendar test of following`() {
val ldn = BusinessCalendar.getInstance("London")
val result = ldn.applyRollConvention(LocalDate.of(2016, 12, 25), DateRollConvention.Following)
assert(result == LocalDate.of(2016, 12, 28))
assertEquals(LocalDate.of(2016, 12, 28), result)
}
@Test

View File

@ -117,7 +117,7 @@ class PartialMerkleTreeTest {
assertTrue(mt.filteredLeaves.timestamp != null)
assertEquals(null, mt.filteredLeaves.type)
assertEquals(null, mt.filteredLeaves.notary)
assert(mt.verify())
assertTrue(mt.verify())
}
@Test
@ -143,19 +143,19 @@ class PartialMerkleTreeTest {
fun `build Partial Merkle Tree, only left nodes branch`() {
val inclHashes = listOf(hashed[3], hashed[5])
val pmt = PartialMerkleTree.build(merkleTree, inclHashes)
assert(pmt.verify(merkleTree.hash, inclHashes))
assertTrue(pmt.verify(merkleTree.hash, inclHashes))
}
@Test
fun `build Partial Merkle Tree, include zero leaves`() {
val pmt = PartialMerkleTree.build(merkleTree, emptyList())
assert(pmt.verify(merkleTree.hash, emptyList()))
assertTrue(pmt.verify(merkleTree.hash, emptyList()))
}
@Test
fun `build Partial Merkle Tree, include all leaves`() {
val pmt = PartialMerkleTree.build(merkleTree, hashed)
assert(pmt.verify(merkleTree.hash, hashed))
assertTrue(pmt.verify(merkleTree.hash, hashed))
}
@Test

View File

@ -228,7 +228,7 @@ class X509UtilitiesTest {
val serverThread = thread {
try {
val sslServerSocket = serverSocket.accept()
assert(sslServerSocket.isConnected)
assertTrue(sslServerSocket.isConnected)
val serverInput = DataInputStream(sslServerSocket.inputStream)
val receivedString = serverInput.readUTF()
assertEquals("Hello World", receivedString)

View File

@ -24,9 +24,7 @@ import java.net.URLClassLoader
import java.security.PublicKey
import java.util.jar.JarOutputStream
import java.util.zip.ZipEntry
import kotlin.test.assertEquals
import kotlin.test.assertFailsWith
import kotlin.test.assertNotNull
import kotlin.test.*
interface DummyContractBackdoor {
fun generateInitial(owner: PartyAndReference, magicNumber: Int, notary: Party): TransactionBuilder
@ -136,7 +134,7 @@ class AttachmentClassLoaderTests {
val jar = attachment.openAsJAR()
assert(jar.nextEntry != null)
assertNotNull(jar.nextEntry)
}
@Test
@ -234,7 +232,7 @@ class AttachmentClassLoaderTests {
kryo.addToWhitelist(contract.javaClass)
val state2 = bytes.deserialize(kryo)
assert(state2.javaClass.classLoader is AttachmentsClassLoader)
assertTrue(state2.javaClass.classLoader is AttachmentsClassLoader)
assertNotNull(state2)
}

View File

@ -1,13 +1,13 @@
package net.corda.contracts.universal
import net.corda.core.crypto.Party
import net.corda.core.crypto.X509Utilities
import net.corda.core.crypto.generateKeyPair
import net.corda.core.utilities.ALICE
import net.corda.testing.MEGA_CORP
import net.corda.testing.MINI_CORP
import org.junit.Test
import java.util.*
import kotlin.test.*
// Test parties
val acmeCorp = Party(ALICE.name, generateKeyPair().public)
@ -99,10 +99,10 @@ class ContractDefinition {
}
}
assert( arr is Actions )
assertTrue( arr is Actions )
if (arr is Actions) {
assert( arr.actions.size == 1)
assertEquals(1, arr.actions.size)
}
}
*/
@ -124,10 +124,10 @@ class ContractDefinition {
}
}
assert(arr is Actions)
assertTrue(arr is Actions)
if (arr is Actions) {
assert(arr.actions.size == 1)
assertEquals(1, arr.actions.size)
}
}

View File

@ -4,6 +4,7 @@ import net.corda.core.utilities.DUMMY_NOTARY
import net.corda.testing.transaction
import org.junit.Test
import java.time.Instant
import kotlin.test.assertEquals
class ZeroCouponBond {
@ -41,7 +42,7 @@ class ZeroCouponBond {
@Test
fun basic() {
assert(Zero().equals(Zero()))
assertEquals(Zero(), Zero())
}

View File

@ -43,7 +43,6 @@ import net.corda.testing.sequence
import org.assertj.core.api.Assertions.assertThat
import org.assertj.core.api.Assertions.assertThatThrownBy
import org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType
import org.bouncycastle.asn1.x500.X500Name
import org.junit.After
import org.junit.Before
import org.junit.Test
@ -334,7 +333,7 @@ class StateMachineManagerTests {
}
val endpoint = net.messagingNetwork.endpoint(notary1.net.myAddress as InMemoryMessagingNetwork.PeerHandle)!!
val party1Info = notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!
assert(party1Info is PartyInfo.Service)
assertTrue(party1Info is PartyInfo.Service)
val notary1Address: MessageRecipients = endpoint.getAddressOfParty(notary1.services.networkMapCache.getPartyInfo(notary1.info.notaryIdentity)!!)
assertThat(notary1Address).isInstanceOf(InMemoryMessagingNetwork.ServiceHandle::class.java)
assertEquals(notary1Address, endpoint.getAddressOfParty(notary2.services.networkMapCache.getPartyInfo(notary2.info.notaryIdentity)!!))

View File

@ -5,9 +5,7 @@ import org.junit.Test
import java.util.*
import java.util.concurrent.CountDownLatch
import java.util.concurrent.atomic.AtomicReference
import kotlin.test.assertEquals
import kotlin.test.assertFails
import kotlin.test.assertNotEquals
import kotlin.test.*
class AffinityExecutorTests {
var _executor: AffinityExecutor.ServiceAffinityExecutor? = null
@ -28,13 +26,13 @@ class AffinityExecutorTests {
}
latch.countDown()
executor.flush()
assert(nestedRan)
assertTrue(nestedRan)
}
@Test fun `single threaded affinity executor runs on correct thread`() {
val thisThread = Thread.currentThread()
_executor = AffinityExecutor.ServiceAffinityExecutor("test thread", 1)
assert(!executor.isOnThread)
assertTrue(!executor.isOnThread)
assertFails { executor.checkOnThread() }
val thread = AtomicReference<Thread>()
@ -54,7 +52,7 @@ class AffinityExecutorTests {
@Test fun `pooled executor`() {
_executor = AffinityExecutor.ServiceAffinityExecutor("test2", 3)
assert(!executor.isOnThread)
assertFalse(executor.isOnThread)
val latch = CountDownLatch(1)
val latch2 = CountDownLatch(2)
@ -62,7 +60,7 @@ class AffinityExecutorTests {
fun blockAThread() {
executor.execute {
assert(executor.isOnThread)
assertTrue(executor.isOnThread)
threads += Thread.currentThread()
latch2.countDown()
latch.await()
@ -73,7 +71,7 @@ class AffinityExecutorTests {
latch2.await()
assertEquals(2, threads.size)
val numThreads = executor.fetchFrom {
assert(executor.isOnThread)
assertTrue(executor.isOnThread)
threads += Thread.currentThread()
threads.distinct().size
}

View File

@ -10,6 +10,7 @@ import net.corda.node.services.transactions.SimpleNotaryService
import net.corda.testing.BOC
import org.bouncycastle.asn1.x500.X500Name
import org.junit.Test
import kotlin.test.assertTrue
class BankOfCordaHttpAPITest {
@Test
@ -20,7 +21,7 @@ class BankOfCordaHttpAPITest {
startNode(BIGCORP_LEGAL_NAME)
).getOrThrow()
val nodeBankOfCordaApiAddr = startWebserver(nodeBankOfCorda).getOrThrow().listenAddress
assert(BankOfCordaClientApi(nodeBankOfCordaApiAddr).requestWebIssue(IssueRequestParams(1000, "USD", BIGCORP_LEGAL_NAME, "1", X500Name(BOC.name))))
assertTrue(BankOfCordaClientApi(nodeBankOfCordaApiAddr).requestWebIssue(IssueRequestParams(1000, "USD", BIGCORP_LEGAL_NAME, "1", X500Name(BOC.name))))
}, isDebug = true)
}
}

View File

@ -80,20 +80,20 @@ class IRSDemoTest : IntegrationTestCategory {
private fun runDateChange(nodeAddr: HostAndPort) {
val url = URL("http://$nodeAddr/api/irs/demodate")
assert(putJson(url, "\"$futureDate\""))
assertThat(putJson(url, "\"$futureDate\"")).isTrue()
}
private fun runTrade(nodeAddr: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example-irs-trade.json"), Charsets.UTF_8.name())
val tradeFile = fileContents.replace("tradeXXX", "trade1")
val url = URL("http://$nodeAddr/api/irs/deals")
assert(postJson(url, tradeFile))
assertThat(postJson(url, tradeFile)).isTrue()
}
private fun runUploadRates(host: HostAndPort) {
val fileContents = IOUtils.toString(Thread.currentThread().contextClassLoader.getResourceAsStream("example.rates.txt"), Charsets.UTF_8.name())
val url = URL("http://$host/upload/interest-rates")
assert(uploadFile(url, fileContents))
assertThat(uploadFile(url, fileContents)).isTrue()
}
private fun getTradeCount(nodeAddr: HostAndPort): Int {

View File

@ -14,6 +14,7 @@ import org.junit.Test
import java.math.BigDecimal
import java.time.LocalDate
import java.util.*
import kotlin.test.assertEquals
fun createDummyIRS(irsSelect: Int): InterestRateSwap.State<AnonymousParty> {
return when (irsSelect) {
@ -326,7 +327,7 @@ class IRSTests {
@Test
fun `test some rate objects 100 * FixedRate(5%)`() {
val r1 = FixedRate(PercentageRatioUnit("5"))
assert(100 * r1 == 5)
assertEquals(5, 100 * r1)
}
@Test

View File

@ -38,6 +38,7 @@ import net.corda.vega.analytics.RwamBimmNotProductClassesCalculator
import java.nio.file.Paths
import java.time.LocalDate
import java.util.stream.Collectors.toList
import kotlin.test.assertEquals
/**
* A example of calculating the margin for a portfolio of two swaps using Strata and SIMM.
@ -69,7 +70,7 @@ class SwapExample {
var totalCurrencyExposure = MultiCurrencyAmount.empty()
for (resolvedTrade in resolvedTrades) {
val swap = resolvedTrade.getProduct()
val swap = resolvedTrade.product
val pointSensitivities = pricer.presentValueSensitivity(swap, combinedRatesProvider).build()
val sensitivities = combinedRatesProvider.parameterSensitivity(pointSensitivities)
@ -97,31 +98,31 @@ class SwapExample {
fun testingEqualitymain(@Suppress("UNUSED_PARAMETER") args: Array<String>) {
val curveGroupDefinition1 = loadCurveGroup()
val curveGroupDefinition2 = loadCurveGroup()
assert(curveGroupDefinition1 == curveGroupDefinition2)
assertEquals(curveGroupDefinition2, curveGroupDefinition1)
val marketData1 = loadMarketData()
val marketData2 = loadMarketData()
assert(marketData1 == marketData2)
assertEquals(marketData2, marketData1)
val trades1 = ImmutableList.of(createVanillaFixedVsLibor3mSwap(), createVanillaFixedVsLibor6mSwap())
val trades2 = ImmutableList.of(createVanillaFixedVsLibor3mSwap(), createVanillaFixedVsLibor6mSwap())
assert(trades1 == trades2)
assertEquals(trades2, trades1)
val calibrator1 = CurveCalibrator.of(1e-9, 1e-9, 100, CalibrationMeasures.PAR_SPREAD)
val calibrator2 = CurveCalibrator.of(1e-9, 1e-9, 100, CalibrationMeasures.PAR_SPREAD)
assert(calibrator1 == calibrator2)
assertEquals(calibrator2, calibrator1)
val ratesProvider1 = calibrator1.calibrate(curveGroupDefinition1, marketData1, ReferenceData.standard())
val ratesProvider2 = calibrator1.calibrate(curveGroupDefinition1, marketData1, ReferenceData.standard())
assert(ratesProvider1 == ratesProvider2)
assertEquals(ratesProvider2, ratesProvider1)
val fxRateProvider1 = MarketDataFxRateProvider.of(marketData1)
val fxRateProvider2 = MarketDataFxRateProvider.of(marketData2)
assert(fxRateProvider1 == fxRateProvider2)
assertEquals(fxRateProvider2, fxRateProvider1)
val combinedRatesProvider1 = ImmutableRatesProvider.combined(fxRateProvider1, ratesProvider1)
val combinedRatesProvider2 = ImmutableRatesProvider.combined(fxRateProvider2, ratesProvider2)
assert(combinedRatesProvider1 == combinedRatesProvider2)
assertEquals(combinedRatesProvider2, combinedRatesProvider1)
val resolvedTrades = trades1.stream().map({ trade -> trade.resolve(ReferenceData.standard()) }).collect(toList<ResolvedSwapTrade>())
val pricer = DiscountingSwapProductPricer.DEFAULT
@ -130,7 +131,7 @@ class SwapExample {
var totalCurrencyExposure1 = MultiCurrencyAmount.empty()
for (resolvedTrade in resolvedTrades) {
val swap = resolvedTrade.getProduct()
val swap = resolvedTrade.product
val pointSensitivities = pricer.presentValueSensitivity(swap, combinedRatesProvider1).build()
val sensitivities = combinedRatesProvider1.parameterSensitivity(pointSensitivities)
@ -145,7 +146,7 @@ class SwapExample {
var totalCurrencyExposure2 = MultiCurrencyAmount.empty()
for (resolvedTrade in resolvedTrades) {
val swap = resolvedTrade.getProduct()
val swap = resolvedTrade.product
val pointSensitivities = pricer.presentValueSensitivity(swap, combinedRatesProvider2).build()
val sensitivities = combinedRatesProvider2.parameterSensitivity(pointSensitivities)
@ -155,13 +156,13 @@ class SwapExample {
totalCurrencyExposure2 = totalCurrencyExposure2.plus(currencyExposure)
}
assert(totalSensitivities1 == totalSensitivities2)
assert(totalCurrencyExposure1 == totalCurrencyExposure2)
assertEquals(totalSensitivities2, totalSensitivities1)
assertEquals(totalCurrencyExposure2, totalCurrencyExposure1)
val totalSensitivities3 = totalSensitivities1.serialize().deserialize()
assert(totalSensitivities1 == totalSensitivities3)
assertEquals(totalSensitivities3, totalSensitivities1)
val totalCurrencyExposure3 = totalCurrencyExposure1.serialize().deserialize()
assert(totalCurrencyExposure1 == totalCurrencyExposure3)
assertEquals(totalCurrencyExposure3, totalCurrencyExposure1)
val normalizer1 = PortfolioNormalizer(Currency.EUR, combinedRatesProvider1)
val normalizer2 = PortfolioNormalizer(Currency.EUR, combinedRatesProvider2)