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

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

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

@ -1,7 +1,6 @@
package avb.blob package avb.blob
import cfig.io.Struct3 import cfig.io.Struct3
import org.junit.Assert
import java.io.File import java.io.File
import java.io.FileInputStream import java.io.FileInputStream
import java.io.InputStream import java.io.InputStream
@ -35,7 +34,7 @@ data class Footer constructor(
@Throws(IllegalArgumentException::class) @Throws(IllegalArgumentException::class)
constructor(iS: InputStream) : this() { constructor(iS: InputStream) : this() {
val info = Struct3(FORMAT_STRING).unpack(iS) val info = Struct3(FORMAT_STRING).unpack(iS)
Assert.assertEquals(7, info.size) assert(7 == info.size)
if (MAGIC != (info[0] as String)) { if (MAGIC != (info[0] as String)) {
throw IllegalArgumentException("stream doesn't look like valid AVB Footer") 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" private const val FORMAT_STRING = "!4s2L3Q${RESERVED}x"
init { 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.Avb
import cfig.io.Struct3 import cfig.io.Struct3
import org.junit.Assert
import java.io.InputStream import java.io.InputStream
//avbtool::AvbVBMetaHeader //avbtool::AvbVBMetaHeader
@ -29,7 +28,7 @@ data class Header(
@Throws(IllegalArgumentException::class) @Throws(IllegalArgumentException::class)
constructor(iS: InputStream) : this() { constructor(iS: InputStream) : this() {
val info = Struct3(FORMAT_STRING).unpack(iS) val info = Struct3(FORMAT_STRING).unpack(iS)
Assert.assertEquals(22, info.size) assert(22 == info.size)
if (info[0] != magic) { if (info[0] != magic) {
throw IllegalArgumentException("stream doesn't look like valid VBMeta Header") 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") private const val FORMAT_STRING = ("!4s2L2QL11QL${REVERSED0}x47sx" + "${REVERSED}x")
init { 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.Helper
import cfig.io.Struct3 import cfig.io.Struct3
import org.apache.commons.codec.binary.Hex import org.apache.commons.codec.binary.Hex
import org.junit.Assert
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.File import java.io.File
import java.io.FileInputStream 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") 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) 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.partition_name = payload[0] as String
this.salt = payload[1] as ByteArray this.salt = payload[1] as ByteArray
this.digest = payload[2] as ByteArray this.digest = payload[2] as ByteArray

@ -2,7 +2,6 @@ package avb.desc
import cfig.Helper import cfig.Helper
import cfig.io.Struct3 import cfig.io.Struct3
import org.junit.Assert
import java.io.InputStream import java.io.InputStream
@ExperimentalUnsignedTypes @ExperimentalUnsignedTypes
@ -60,7 +59,7 @@ class KernelCmdlineDescriptor(
const val flagHashTreeDisabled = 2U const val flagHashTreeDisabled = 2U
init { 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.Helper
import cfig.io.Struct3 import cfig.io.Struct3
import org.apache.commons.codec.binary.Hex import org.apache.commons.codec.binary.Hex
import org.junit.Assert
import org.slf4j.LoggerFactory import org.slf4j.LoggerFactory
import java.io.ByteArrayInputStream import java.io.ByteArrayInputStream
import java.io.InputStream import java.io.InputStream
@ -108,7 +107,7 @@ class UnknownDescriptor(var data: ByteArray = byteArrayOf()) : Descriptor(0U, 0U
} }
init { init {
Assert.assertEquals(SIZE, Struct3(FORMAT).calcSize()) assert(SIZE == Struct3(FORMAT).calcSize())
} }
} }
} }

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

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

Loading…
Cancel
Save