Skip to content

Commit a6f083e

Browse files
authoredSep 3, 2024
Fix kotlin tests, remove unused code (project-chip#32880)
* 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 =
1 parent 5ffb598 commit a6f083e

File tree

3 files changed

+29
-30
lines changed

3 files changed

+29
-30
lines changed
 

‎src/controller/java/src/matter/onboardingpayload/QRCodeBasicOnboardingPayloadGenerator.kt

-3
Original file line numberDiff line numberDiff line change
@@ -68,9 +68,6 @@ fun payloadBase38RepresentationWithTLV(
6868

6969
// Copy the subBuffer back to the outBuffer
7070
subBuffer.copyInto(outBuffer, prefixLen)
71-
72-
// Reduce output buffer size to be the size of written data
73-
outBuffer.copyOf(prefixLen + subBuffer.size)
7471
}
7572
}
7673

‎src/controller/java/tests/matter/onboardingpayload/ManualCodeTest.kt

+14-13
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import kotlin.math.ceil
2424
import kotlin.math.log10
2525
import kotlin.math.pow
2626
import org.junit.Assert.assertEquals
27+
import org.junit.Assert.assertTrue
2728
import org.junit.Test
2829
import org.junit.runner.RunWith
2930
import org.junit.runners.JUnit4
@@ -444,7 +445,7 @@ class ManualCodeTest {
444445
// Override the discriminator in the input payload with the short version,
445446
// since that's what we will produce.
446447
inPayload.setShortDiscriminatorValue(inPayload.getShortDiscriminatorValue())
447-
assertThat(inPayload == outPayload)
448+
assertEquals(inPayload, outPayload)
448449
}
449450

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

470471
/*
@@ -479,15 +480,15 @@ class ManualCodeTest {
479480

480481
try {
481482
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
482-
assertThat(false)
483+
assertTrue(false)
483484
} catch (e: Exception) {
484485
println("Expected exception occurred: ${e.message}")
485486
}
486487

487488
representationWithoutCheckDigit = "1"
488489
try {
489490
ManualOnboardingPayloadParser.checkDecimalStringValidity(representationWithoutCheckDigit)
490-
assertThat(false)
491+
assertTrue(false)
491492
} catch (e: Exception) {
492493
println("Expected exception occurred: ${e.message}")
493494
}
@@ -516,28 +517,28 @@ class ManualCodeTest {
516517

517518
try {
518519
ManualOnboardingPayloadParser.checkCodeLengthValidity("01234567891", false)
519-
assertThat(false)
520+
assertTrue(false)
520521
} catch (e: Exception) {
521522
println("Expected exception occurred: ${e.message}")
522523
}
523524

524525
try {
525526
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678", false)
526-
assertThat(false)
527+
assertTrue(false)
527528
} catch (e: Exception) {
528529
println("Expected exception occurred: ${e.message}")
529530
}
530531

531532
try {
532533
ManualOnboardingPayloadParser.checkCodeLengthValidity("012345678901234567891", true)
533-
assertThat(false)
534+
assertTrue(false)
534535
} catch (e: Exception) {
535536
println("Expected exception occurred: ${e.message}")
536537
}
537538

538539
try {
539540
ManualOnboardingPayloadParser.checkCodeLengthValidity("0123456789012345678", true)
540-
assertThat(false)
541+
assertTrue(false)
541542
} catch (e: Exception) {
542543
println("Expected exception occurred: ${e.message}")
543544
}
@@ -562,14 +563,14 @@ class ManualCodeTest {
562563

563564
try {
564565
ManualOnboardingPayloadParser.toNumber("012345.123456789")
565-
assertThat(false)
566+
assertTrue(false)
566567
} catch (e: Exception) {
567568
println("Expected exception occurred: ${e.message}")
568569
}
569570

570571
try {
571572
ManualOnboardingPayloadParser.toNumber("/")
572-
assertThat(false)
573+
assertTrue(false)
573574
} catch (e: Exception) {
574575
println("Expected exception occurred: ${e.message}")
575576
}
@@ -631,22 +632,22 @@ class ManualCodeTest {
631632
try {
632633
index.set(1)
633634
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12345", index, 5)
634-
assertThat(false)
635+
assertTrue(false)
635636
} catch (e: Exception) {
636637
println("Expected exception occurred: ${e.message}")
637638
}
638639

639640
try {
640641
ManualOnboardingPayloadParser.readDigitsFromDecimalString("12", index, 5)
641-
assertThat(false)
642+
assertTrue(false)
642643
} catch (e: Exception) {
643644
println("Expected exception occurred: ${e.message}")
644645
}
645646

646647
try {
647648
index.set(200)
648649
ManualOnboardingPayloadParser.readDigitsFromDecimalString("6256276377282", index, 1)
649-
assertThat(false)
650+
assertTrue(false)
650651
} catch (e: Exception) {
651652
println("Expected exception occurred: ${e.message}")
652653
}

‎src/controller/java/tests/matter/onboardingpayload/QRCodeTest.kt

+15-14
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ package matter.onboardingpayload
2020

2121
import com.google.common.truth.Truth.assertThat
2222
import org.junit.Assert.assertEquals
23+
import org.junit.Assert.assertTrue
2324
import org.junit.Test
2425
import org.junit.runner.RunWith
2526
import org.junit.runners.JUnit4
@@ -224,7 +225,7 @@ class QRCodeTest {
224225

225226
try {
226227
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
227-
assertThat(false)
228+
assertTrue(false)
228229
} catch (e: Exception) {
229230
println("Expected exception occurred: ${e.message}")
230231
}
@@ -240,7 +241,7 @@ class QRCodeTest {
240241

241242
try {
242243
QRCodeOnboardingPayloadParser(invalidString).populatePayload()
243-
assertThat(false)
244+
assertTrue(false)
244245
} catch (e: Exception) {
245246
println("Expected exception occurred: ${e.message}")
246247
}
@@ -396,21 +397,21 @@ class QRCodeTest {
396397
// verify we can grab just the serial number as well
397398
assertThat(parsedQrCode.getSerialNumber()).isEqualTo("123456789")
398399

399-
// Test 2nd optional field
400-
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
401-
optionalQRCodeInfo.tag = 130
402-
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_STRING
403-
optionalQRCodeInfo.data = "myData"
400+
val optionalQRCodeInfo1 = OptionalQRCodeInfoExtension()
401+
optionalQRCodeInfo1.tag = 130
402+
optionalQRCodeInfo1.type = OptionalQRCodeInfoType.TYPE_STRING
403+
optionalQRCodeInfo1.data = "myData"
404404

405-
assertThat(parsedQrCode.getAllOptionalVendorData()[0]).isEqualTo(optionalQRCodeInfo)
405+
val optionalQRCodeInfo2 = OptionalQRCodeInfoExtension()
406+
optionalQRCodeInfo2.tag = 131
407+
optionalQRCodeInfo2.type = OptionalQRCodeInfoType.TYPE_INT32
408+
optionalQRCodeInfo2.int32 = 12
406409

407-
// Test 3rd optional field
408-
optionalQRCodeInfo = OptionalQRCodeInfoExtension()
409-
optionalQRCodeInfo.tag = 131
410-
optionalQRCodeInfo.type = OptionalQRCodeInfoType.TYPE_INT32
411-
optionalQRCodeInfo.int32 = 12
410+
val vendor1 = parsedQrCode.getAllOptionalVendorData()[0]
411+
val vendor2 = parsedQrCode.getAllOptionalVendorData()[1]
412412

413-
assertThat(parsedQrCode.getAllOptionalVendorData()[1]).isEqualTo(optionalQRCodeInfo)
413+
assertTrue(vendor1 == optionalQRCodeInfo1 || vendor1 == optionalQRCodeInfo2)
414+
assertTrue(vendor2 == optionalQRCodeInfo1 || vendor2 == optionalQRCodeInfo2)
414415
}
415416

416417
companion object {

0 commit comments

Comments
 (0)
Please sign in to comment.