Skip to content

Commit

Permalink
Fix kotlin tests, remove unused code (project-chip#32880)
Browse files Browse the repository at this point in the history
* Fix kotlin tests, remove unused code

assertThat(false) doesn't actually do anythung, it returns an object
you can then make assertions against, use assertTrue instead

testQRCodeWithOptionalData relied upon an implicit ordering, however
the underlying representation (HashMap) is unordered

* re-add line with unused val

* Revert val unused =
  • Loading branch information
achaulk-goog authored and shgutte committed Sep 10, 2024
1 parent 7452f74 commit e0bb76c
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,6 @@ fun payloadBase38RepresentationWithTLV(

// Copy the subBuffer back to the outBuffer
subBuffer.copyInto(outBuffer, prefixLen)

// Reduce output buffer size to be the size of written data
outBuffer.copyOf(prefixLen + subBuffer.size)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import kotlin.math.ceil
import kotlin.math.log10
import kotlin.math.pow
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
Expand Down Expand Up @@ -444,7 +445,7 @@ class ManualCodeTest {
// Override the discriminator in the input payload with the short version,
// since that's what we will produce.
inPayload.setShortDiscriminatorValue(inPayload.getShortDiscriminatorValue())
assertThat(inPayload == outPayload)
assertEquals(inPayload, outPayload)
}

/*
Expand All @@ -464,7 +465,7 @@ class ManualCodeTest {
// Override the discriminator in the input payload with the short version,
// since that's what we will produce.
inPayload.setShortDiscriminatorValue(inPayload.getShortDiscriminatorValue())
assertThat(inPayload == outPayload)
assertEquals(inPayload, outPayload)
}

/*
Expand All @@ -479,15 +480,15 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

representationWithoutCheckDigit = "1"
try {
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -516,28 +517,28 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("01234567891", false)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678", false)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678901234567891", true)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.checkCodeLengthValidity("0123456789012345678", true)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand All @@ -562,14 +563,14 @@ class ManualCodeTest {

try {
ManualOnboardingPayloadParser.toNumber("012345.123456789")
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.toNumber("/")
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -631,22 +632,22 @@ class ManualCodeTest {
try {
index.set(1)
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12345", index, 5)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12", index, 5)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}

try {
index.set(200)
ManualOnboardingPayloadParser.readDigitsFromDecimalString("6256276377282", index, 1)
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down
29 changes: 15 additions & 14 deletions src/controller/java/tests/matter/onboardingpayload/QRCodeTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ package matter.onboardingpayload

import com.google.common.truth.Truth.assertThat
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
Expand Down Expand Up @@ -224,7 +225,7 @@ class QRCodeTest {

try {
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand All @@ -240,7 +241,7 @@ class QRCodeTest {

try {
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
assertThat(false)
assertTrue(false)
} catch (e: Exception) {
println("Expected exception occurred: ${e.message}")
}
Expand Down Expand Up @@ -396,21 +397,21 @@ class QRCodeTest {
// verify we can grab just the serial number as well
assertThat(parsedQrCode.getSerialNumber()).isEqualTo("123456789")

// Test 2nd optional field
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
optionalQRCodeInfo.tag = 130
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_STRING
optionalQRCodeInfo.data = "myData"
val optionalQRCodeInfo1 = OptionalQRCodeInfoExtension()
optionalQRCodeInfo1.tag = 130
optionalQRCodeInfo1.type = OptionalQRCodeInfoType.TYPE_STRING
optionalQRCodeInfo1.data = "myData"

assertThat(parsedQrCode.getAllOptionalVendorData()[0]).isEqualTo(optionalQRCodeInfo)
val optionalQRCodeInfo2 = OptionalQRCodeInfoExtension()
optionalQRCodeInfo2.tag = 131
optionalQRCodeInfo2.type = OptionalQRCodeInfoType.TYPE_INT32
optionalQRCodeInfo2.int32 = 12

// Test 3rd optional field
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
optionalQRCodeInfo.tag = 131
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_INT32
optionalQRCodeInfo.int32 = 12
val vendor1 = parsedQrCode.getAllOptionalVendorData()[0]
val vendor2 = parsedQrCode.getAllOptionalVendorData()[1]

assertThat(parsedQrCode.getAllOptionalVendorData()[1]).isEqualTo(optionalQRCodeInfo)
assertTrue(vendor1 == optionalQRCodeInfo1 || vendor1 == optionalQRCodeInfo2)
assertTrue(vendor2 == optionalQRCodeInfo1 || vendor2 == optionalQRCodeInfo2)
}

companion object {
Expand Down

0 comments on commit e0bb76c

Please sign in to comment.