Clean up some stuff around ImportExportTest.

This commit is contained in:
Greyson Parrelli
2024-06-03 10:43:23 -04:00
committed by Cody Henthorne
parent c3ab8dddd0
commit f761008509
3 changed files with 58 additions and 48 deletions

View File

@@ -17,6 +17,8 @@ java {
}
dependencies {
implementation(libs.kotlin.reflect)
testImplementation(testLibs.junit.junit)
testImplementation(testLibs.assertj.core)
}

View File

@@ -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()
}