I am looking for Guava Truth equivalent of AssertJ usingElementComparatorIgnoringFields to ignore some field.
Exemple:
data class CalendarEntity(
@PrimaryKey(autoGenerate = true)
var id: Int = 0,
var name: String
)
Truth.assertThat(currentCalendars).containsExactlyElementsIn(expectedCalendars) // Here I want to ignore the id field
Thanks for your help.
For Truth, we decided not to provide reflection-based APIs, so there's no built-in equivalent.
Our general approach to custom comparisons is Fuzzy Truth. In your case, that would look something like this (Java, untested):
If you anticipate wanting this a lot (and you want to stick with Truth rather than AssertJ), then you could generalize the
ignoreIdcode to work with arbitrary field names.(Also: In this specific example, your
CalendarEntityhas only one field that you do want to compare. In that case, you can construct theCorrespondencein a slightly simpler way:Correspondence.transforming(CalendarEntity::name, "name").)