Skip to content

Commit

Permalink
Restore original behaviour
Browse files Browse the repository at this point in the history
  • Loading branch information
mscwilson committed Jan 27, 2024
1 parent 5c45695 commit 07d301a
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,21 @@ class AbstractEventTest {
@Test
fun testAddsEntitiesUsingAllAPIs() {
val event = ScreenView("screen")
val entity = SelfDescribingJson("schema3", "data3")

event.entities.add(SelfDescribingJson("schema1", "data1"))
event.contexts(listOf(SelfDescribingJson("schema2", "data2")))
event.entities(listOf(entity))
val entity1 = SelfDescribingJson("schema1", "data1")
val entity2 = SelfDescribingJson("schema2", "data2")
val entity3 = SelfDescribingJson("schema3", "data3")

event.entities.add(entity1)
Assert.assertEquals(1, event.entities.count())
Assert.assertEquals(1, event.contexts.count())
Assert.assertTrue(event.entities.contains(entity))

event.entities(listOf(entity2))
Assert.assertEquals(2, event.entities.count())

event.contexts(listOf(entity3))
Assert.assertEquals(3, event.entities.count())
Assert.assertEquals(3, event.contexts.count())
Assert.assertTrue(event.entities.contains(entity1))
Assert.assertTrue(event.entities.contains(entity2))
Assert.assertTrue(event.entities.contains(entity3))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import java.util.*
* - "True" timestamp: user-defined custom event timestamp
*/
abstract class AbstractEvent : Event {
private var _entities: MutableList<SelfDescribingJson> = LinkedList()
private var _entities = mutableListOf<SelfDescribingJson>()
/**
* @return the custom context entities associated with the event.
*/
Expand Down Expand Up @@ -55,13 +55,13 @@ abstract class AbstractEvent : Event {

// Builder methods

/** Replace the context entities attached to the event with a new list of entities. */
/** Adds a list of context entities to the existing ones. */
fun entities(entities: List<SelfDescribingJson>): AbstractEvent {
this.entities = entities.toMutableList()
this.entities.addAll(entities)
return this
}

/** Replace the context entities attached to the event with a new list of entities. */
/** Adds a list of context entities to the existing ones. */
@Deprecated("Old nomenclature.", ReplaceWith("entities()"))
fun contexts(contexts: List<SelfDescribingJson>): AbstractEvent {
return entities(contexts)
Expand Down

0 comments on commit 07d301a

Please sign in to comment.