mirror of
https://github.com/signalapp/Signal-Android.git
synced 2025-12-25 05:27:42 +00:00
Clean up some stuff around ImportExportTest.
This commit is contained in:
committed by
Cody Henthorne
parent
c3ab8dddd0
commit
f761008509
@@ -17,6 +17,8 @@ java {
|
||||
}
|
||||
|
||||
dependencies {
|
||||
implementation(libs.kotlin.reflect)
|
||||
|
||||
testImplementation(testLibs.junit.junit)
|
||||
testImplementation(testLibs.assertj.core)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* Copyright 2024 Signal Messenger, LLC
|
||||
* SPDX-License-Identifier: AGPL-3.0-only
|
||||
*/
|
||||
|
||||
package org.signal.core.util.test
|
||||
|
||||
import kotlin.reflect.full.memberProperties
|
||||
import kotlin.reflect.jvm.isAccessible
|
||||
|
||||
/**
|
||||
* Returns a string containing the differences between the expected and actual objects.
|
||||
* Useful for diffing complex data classes in your tests.
|
||||
*/
|
||||
inline fun <reified T : Any> getObjectDiff(expected: T, actual: T): String {
|
||||
val builder = StringBuilder()
|
||||
|
||||
val properties = T::class.memberProperties
|
||||
|
||||
for (prop in properties) {
|
||||
prop.isAccessible = true
|
||||
val expectedValue = prop.get(expected)
|
||||
val actualValue = prop.get(actual)
|
||||
if (expectedValue != actualValue) {
|
||||
builder.append("[${prop.name}] Expected: $expectedValue, Actual: $actualValue\n")
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toString()
|
||||
}
|
||||
Reference in New Issue
Block a user