move all org.juit.Assert to kotlin assert

pull/41/head
cfig 5 years ago
parent 0d0484248d
commit ef02d54a78
No known key found for this signature in database
GPG Key ID: B104C307F0FDABB7

@ -9,8 +9,6 @@ import org.apache.commons.exec.CommandLine
import org.apache.commons.exec.DefaultExecutor
import org.apache.commons.exec.ExecuteException
import org.apache.commons.exec.PumpStreamHandler
import org.junit.Assert
import org.junit.Assert.assertTrue
import org.slf4j.LoggerFactory
import java.io.*
import java.math.BigInteger
@ -175,7 +173,7 @@ class Helper {
RandomAccessFile(outImgName, "rw").use { outRaf ->
inRaf.seek(offset)
val data = ByteArray(length)
assertTrue(length == inRaf.read(data))
assert(length == inRaf.read(data))
outRaf.write(data)
}
}
@ -210,7 +208,7 @@ class Helper {
*/
fun encodeRSAkey(key: ByteArray): ByteArray {
val rsa = KeyUtil.parsePemPrivateKey(ByteArrayInputStream(key))
Assert.assertEquals(65537.toBigInteger(), rsa.publicExponent)
assert(65537.toBigInteger() == rsa.publicExponent)
val numBits: Int = BigIntegerMath.log2(rsa.modulus, RoundingMode.CEILING)
log.debug("modulus: " + rsa.modulus)
log.debug("numBits: $numBits")

@ -11,7 +11,6 @@ import cfig.Helper.Companion.paddingWith
import cfig.io.Struct3
import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.commons.codec.binary.Hex
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileInputStream
@ -93,7 +92,7 @@ class Avb {
log.info("4/4 Appending AVB footer (${footerBlobWithPadding.size} bytes)...")
fos.write(footerBlobWithPadding)
}
Assert.assertEquals("generated file size mismatch", partition_size, File(image_file).length())
assert(partition_size == File(image_file).length()) { "generated file size mismatch" }
log.info("addHashFooter($image_file) done.")
}

@ -6,7 +6,6 @@ import cfig.Helper
import cfig.io.Struct3
import com.fasterxml.jackson.annotation.JsonIgnore
import com.fasterxml.jackson.annotation.JsonIgnoreProperties
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.nio.file.Files
import java.nio.file.Paths
@ -98,7 +97,7 @@ class AuxBlob(
}
encodedKey = Helper.encodeRSAkey(algKey!!)
log.info("encodePubKey(): size = ${alg.public_key_num_bytes}, algorithm key size: ${encodedKey.size}")
Assert.assertEquals(alg.public_key_num_bytes, encodedKey.size)
assert(alg.public_key_num_bytes == encodedKey.size)
} else {
log.info("encodePubKey(): No key to encode for algorithm " + alg.name)
}

@ -1,7 +1,6 @@
package avb.blob
import cfig.io.Struct3
import org.junit.Assert
import java.io.File
import java.io.FileInputStream
import java.io.InputStream
@ -35,7 +34,7 @@ data class Footer constructor(
@Throws(IllegalArgumentException::class)
constructor(iS: InputStream) : this() {
val info = Struct3(FORMAT_STRING).unpack(iS)
Assert.assertEquals(7, info.size)
assert(7 == info.size)
if (MAGIC != (info[0] as String)) {
throw IllegalArgumentException("stream doesn't look like valid AVB Footer")
}
@ -81,7 +80,7 @@ data class Footer constructor(
private const val FORMAT_STRING = "!4s2L3Q${RESERVED}x"
init {
Assert.assertEquals(SIZE, Struct3(FORMAT_STRING).calcSize())
assert(SIZE == Struct3(FORMAT_STRING).calcSize())
}
}
}

@ -2,7 +2,6 @@ package avb.blob
import cfig.Avb
import cfig.io.Struct3
import org.junit.Assert
import java.io.InputStream
//avbtool::AvbVBMetaHeader
@ -29,7 +28,7 @@ data class Header(
@Throws(IllegalArgumentException::class)
constructor(iS: InputStream) : this() {
val info = Struct3(FORMAT_STRING).unpack(iS)
Assert.assertEquals(22, info.size)
assert(22 == info.size)
if (info[0] != magic) {
throw IllegalArgumentException("stream doesn't look like valid VBMeta Header")
}
@ -109,7 +108,7 @@ data class Header(
private const val FORMAT_STRING = ("!4s2L2QL11QL${REVERSED0}x47sx" + "${REVERSED}x")
init {
Assert.assertEquals(SIZE, Struct3(FORMAT_STRING).calcSize())
assert(SIZE == Struct3(FORMAT_STRING).calcSize())
}
}
}

@ -4,7 +4,6 @@ import avb.blob.Header
import cfig.Helper
import cfig.io.Struct3
import org.apache.commons.codec.binary.Hex
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileInputStream
@ -50,7 +49,7 @@ class HashDescriptor(var flags: UInt = 0U,
throw IllegalArgumentException("Given data does not look like a |hash| descriptor")
}
val payload = Struct3("${this.partition_name_len}s${this.salt_len}b${this.digest_len}b").unpack(data)
Assert.assertEquals(3, payload.size)
assert(3 == payload.size)
this.partition_name = payload[0] as String
this.salt = payload[1] as ByteArray
this.digest = payload[2] as ByteArray

@ -2,7 +2,6 @@ package avb.desc
import cfig.Helper
import cfig.io.Struct3
import org.junit.Assert
import java.io.InputStream
@ExperimentalUnsignedTypes
@ -60,7 +59,7 @@ class KernelCmdlineDescriptor(
const val flagHashTreeDisabled = 2U
init {
Assert.assertEquals(SIZE, Struct3(FORMAT_STRING).calcSize())
assert(SIZE == Struct3(FORMAT_STRING).calcSize())
}
}
}

@ -3,7 +3,6 @@ package avb.desc
import cfig.Helper
import cfig.io.Struct3
import org.apache.commons.codec.binary.Hex
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.io.ByteArrayInputStream
import java.io.InputStream
@ -108,7 +107,7 @@ class UnknownDescriptor(var data: ByteArray = byteArrayOf()) : Descriptor(0U, 0U
}
init {
Assert.assertEquals(SIZE, Struct3(FORMAT).calcSize())
assert(SIZE == Struct3(FORMAT).calcSize())
}
}
}

@ -3,7 +3,6 @@ package cfig.bootimg
import cfig.Helper
import cfig.ParamConfig
import cfig.io.Struct3
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileInputStream
@ -53,7 +52,7 @@ open class BootImgHeader(
}
log.warn("BootImgHeader constructor")
val info = Struct3(FORMAT_STRING).unpack(iS)
Assert.assertEquals(20, info.size)
assert(20 == info.size)
if (info[0] != magic) {
throw IllegalArgumentException("stream doesn't look like Android Boot Image Header")
}
@ -118,9 +117,9 @@ open class BootImgHeader(
if (m.groupCount() == 3) {
c = Integer.decode(m.group(3))
}
Assert.assertTrue(a < 128)
Assert.assertTrue(b < 128)
Assert.assertTrue(c < 128)
assert(a < 128)
assert(b < 128)
assert(c < 128)
return (a shl 14) or (b shl 7) or c
} else {
throw IllegalArgumentException("invalid os_version")
@ -136,8 +135,8 @@ open class BootImgHeader(
val y = Integer.parseInt(matcher.group(1), 10) - 2000
val m = Integer.parseInt(matcher.group(2), 10)
// 7 bits allocated for the year, 4 bits for the month
Assert.assertTrue(y in 0..127)
Assert.assertTrue(m in 1..12)
assert(y in 0..127)
assert(m in 1..12)
ret = (y shl 4) or m
} else {
throw IllegalArgumentException("invalid os_patch_level")
@ -181,9 +180,9 @@ open class BootImgHeader(
private fun get_recovery_dtbo_offset(): UInt {
return Helper.round_to_multiple(this.headerSize, pageSize) +
Helper.round_to_multiple(this.kernelLength, pageSize) +
Helper.round_to_multiple(this.ramdiskLength, pageSize) +
Helper.round_to_multiple(this.secondBootloaderLength, pageSize)
Helper.round_to_multiple(this.kernelLength, pageSize) +
Helper.round_to_multiple(this.ramdiskLength, pageSize) +
Helper.round_to_multiple(this.secondBootloaderLength, pageSize)
}
private fun refresh() {
@ -245,8 +244,7 @@ open class BootImgHeader(
val pageSizeChoices: MutableSet<Long> = mutableSetOf<Long>().apply {
(11..14).forEach { add(2.0.pow(it).toLong()) }
}
Assert.assertTrue("invalid parameter [pageSize=$pageSize], (choose from $pageSizeChoices)",
pageSizeChoices.contains(pageSize.toLong()))
assert(pageSizeChoices.contains(pageSize.toLong())) { "invalid parameter [pageSize=$pageSize], (choose from $pageSizeChoices)" }
return Struct3(FORMAT_STRING).pack(
"ANDROID!",
//10I
@ -304,7 +302,7 @@ open class BootImgHeader(
const val BOOT_IMAGE_HEADER_V1_SIZE = 1648
init {
Assert.assertEquals(BOOT_IMAGE_HEADER_V2_SIZE, Struct3(FORMAT_STRING).calcSize())
assert(BOOT_IMAGE_HEADER_V2_SIZE == Struct3(FORMAT_STRING).calcSize())
}
}
}

@ -5,7 +5,6 @@ import com.fasterxml.jackson.databind.ObjectMapper
import org.apache.commons.exec.CommandLine
import org.apache.commons.exec.DefaultExecutor
import org.apache.commons.exec.PumpStreamHandler
import org.junit.Assert.assertTrue
import org.slf4j.LoggerFactory
import java.io.*
import java.nio.ByteBuffer
@ -50,7 +49,7 @@ class Packer {
}
private fun writePaddedFile(inBF: ByteBuffer, srcFile: String, padding: UInt) {
assertTrue(padding < Int.MAX_VALUE.toUInt())
assert(padding < Int.MAX_VALUE.toUInt())
writePaddedFile(inBF, srcFile, padding.toInt())
}

@ -1,7 +1,6 @@
package cfig.bootloader_message
import cfig.io.Struct3
import org.junit.Assert
import org.slf4j.LoggerFactory
import java.io.File
import java.io.FileInputStream
@ -23,7 +22,7 @@ data class BootloaderMsg(
private val log = LoggerFactory.getLogger("BootloaderMsg")
init {
Assert.assertEquals(SIZE, Struct3(FORMAT_STRING).calcSize())
assert(SIZE == Struct3(FORMAT_STRING).calcSize())
}
}

Loading…
Cancel
Save