snowplow / snowplow-java-tracker

Snowplow event tracker for Java. Add analytics to your Java desktop and server apps, servlets and games. (See also: snowplow-android-tracker)
http://snowplowanalytics.com
Apache License 2.0
23 stars 36 forks source link

Support object comparison for SelfDescribingJson #380

Closed stephen-murby closed 6 months ago

stephen-murby commented 6 months ago

Unit testing is made difficult for consumers of the library without being able to compare like library types.

We should implement and override the equals and hashCode methods for SelfDescribingJson & SelfDescribing

stephen-murby commented 6 months ago

An example of the unit tests is as such

val actual = SnowplowCustomContexts.Builder.from(serverSideEvent)
val expected = listOf( SelfDescribingJson("iglu:uk.co.autotrader/custom_context/jsonschema/1-0-0", mapOf("field" to "value")) )

assertThat(actual.toString()).isEqualTo(expected.toString()) // Currently the only way to compare
assertThat(actual.).isEqualTo(expected) // Would rather do this
stephen-murby commented 6 months ago

Even if we only go as far as comparing this.toString() to that.toString(); it would stop the user having to do this themselves over and over again.