Mutualizing some similar tests with different parameters

This commit is contained in:
Maxime NATUREL 2022-06-13 10:09:09 +02:00
parent 2c96179383
commit ac4b33647d
1 changed files with 105 additions and 114 deletions

View File

@ -77,78 +77,71 @@ internal class LiveLocationAggregationProcessorTest {
result shouldBeEqualTo false result shouldBeEqualTo false
} }
@Test private data class IgnoredBeaconInfoEvent(
fun `given beacon info and event when senderId is null or empty then it is ignored`() { val event: Event,
val eventNoSenderId = Event(eventId = AN_EVENT_ID) val beaconInfo: MessageBeaconInfoContent
val eventEmptySenderId = Event(eventId = AN_EVENT_ID, senderId = "") )
val beaconInfo = MessageBeaconInfoContent()
val resultNoSenderId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventNoSenderId,
content = beaconInfo,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventEmptySenderId,
content = beaconInfo,
roomId = A_ROOM_ID,
isLocalEcho = false
)
resultNoSenderId shouldBeEqualTo false
resultEmptySenderId shouldBeEqualTo false
}
@Test @Test
fun `given beacon info when no target eventId is found then it is ignored`() { fun `given beacon info and event when some values are missing then it is ignored`() {
val unsignedDataWithNoEventId = UnsignedData( val ignoredInfoEvents = listOf(
age = 123 // missing senderId
) IgnoredBeaconInfoEvent(
val unsignedDataWithEmptyEventId = UnsignedData( event = Event(eventId = AN_EVENT_ID, senderId = null),
age = 123, beaconInfo = MessageBeaconInfoContent()
replacesState = "" ),
) // empty senderId
val eventWithNoEventId = Event(senderId = A_SENDER_ID, unsignedData = unsignedDataWithNoEventId) IgnoredBeaconInfoEvent(
val eventWithEmptyEventId = Event(senderId = A_SENDER_ID, eventId = "", unsignedData = unsignedDataWithEmptyEventId) event = Event(eventId = AN_EVENT_ID, senderId = ""),
val beaconInfoLive = MessageBeaconInfoContent(isLive = true) beaconInfo = MessageBeaconInfoContent()
val beaconInfoNotLive = MessageBeaconInfoContent(isLive = false) ),
// beacon is live and no eventId
val resultLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo( IgnoredBeaconInfoEvent(
realm = fakeRealm.instance, event = Event(eventId = null, senderId = A_SENDER_ID),
event = eventWithNoEventId, beaconInfo = MessageBeaconInfoContent(isLive = true)
content = beaconInfoLive, ),
roomId = A_ROOM_ID, // beacon is live and eventId is empty
isLocalEcho = false IgnoredBeaconInfoEvent(
) event = Event(eventId = "", senderId = A_SENDER_ID),
val resultLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo( beaconInfo = MessageBeaconInfoContent(isLive = true)
realm = fakeRealm.instance, ),
event = eventWithEmptyEventId, // beacon is not live and replaced event id is null
content = beaconInfoLive, IgnoredBeaconInfoEvent(
roomId = A_ROOM_ID, event = Event(
isLocalEcho = false eventId = AN_EVENT_ID,
) senderId = A_SENDER_ID,
val resultNotLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo( unsignedData = UnsignedData(
realm = fakeRealm.instance, age = 123,
event = eventWithNoEventId, replacesState = null
content = beaconInfoNotLive, )
roomId = A_ROOM_ID, ),
isLocalEcho = false beaconInfo = MessageBeaconInfoContent(isLive = false)
) ),
val resultNotLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo( // beacon is not live and replaced event id is empty
realm = fakeRealm.instance, IgnoredBeaconInfoEvent(
event = eventWithEmptyEventId, event = Event(
content = beaconInfoNotLive, eventId = AN_EVENT_ID,
roomId = A_ROOM_ID, senderId = A_SENDER_ID,
isLocalEcho = false unsignedData = UnsignedData(
age = 123,
replacesState = ""
)
),
beaconInfo = MessageBeaconInfoContent(isLive = false)
),
) )
resultLiveNoEventId shouldBeEqualTo false ignoredInfoEvents.forEach {
resultLiveEmptyEventId shouldBeEqualTo false val result = liveLocationAggregationProcessor.handleBeaconInfo(
resultNotLiveNoEventId shouldBeEqualTo false realm = fakeRealm.instance,
resultNotLiveEmptyEventId shouldBeEqualTo false event = it.event,
content = it.beaconInfo,
roomId = A_ROOM_ID,
isLocalEcho = false
)
result shouldBeEqualTo false
}
} }
@Test @Test
@ -271,57 +264,55 @@ internal class LiveLocationAggregationProcessorTest {
result shouldBeEqualTo false result shouldBeEqualTo false
} }
private data class IgnoredBeaconLocationDataEvent(
val event: Event,
val beaconLocationData: MessageBeaconLocationDataContent
)
@Test
fun `given event and beacon location data when some values are missing then it is ignored`() {
val ignoredLocationDataEvents = listOf(
// missing sender id
IgnoredBeaconLocationDataEvent(
event = Event(eventId = AN_EVENT_ID),
beaconLocationData = MessageBeaconLocationDataContent()
),
// empty sender id
IgnoredBeaconLocationDataEvent(
event = Event(eventId = AN_EVENT_ID, senderId = ""),
beaconLocationData = MessageBeaconLocationDataContent()
),
)
ignoredLocationDataEvents.forEach {
val result = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance,
event = it.event,
content = it.beaconLocationData,
roomId = A_ROOM_ID,
relatedEventId = "",
isLocalEcho = false
)
result shouldBeEqualTo false
}
}
@Test @Test
fun `given beacon location data when relatedEventId is null or empty then it is ignored`() { fun `given beacon location data when relatedEventId is null or empty then it is ignored`() {
val event = Event(senderId = A_SENDER_ID) val event = Event(senderId = A_SENDER_ID)
val beaconLocationData = MessageBeaconLocationDataContent() val beaconLocationData = MessageBeaconLocationDataContent()
val resultNoRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData( listOf(null, "").forEach {
realm = fakeRealm.instance, val result = liveLocationAggregationProcessor.handleBeaconLocationData(
event = event, realm = fakeRealm.instance,
content = beaconLocationData, event = event,
roomId = A_ROOM_ID, content = beaconLocationData,
relatedEventId = null, roomId = A_ROOM_ID,
isLocalEcho = false relatedEventId = it,
) isLocalEcho = false
val resultEmptyRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData( )
realm = fakeRealm.instance, result shouldBeEqualTo false
event = event, }
content = beaconLocationData,
roomId = A_ROOM_ID,
relatedEventId = "",
isLocalEcho = false
)
resultNoRelatedEventId shouldBeEqualTo false
resultEmptyRelatedEventId shouldBeEqualTo false
}
@Test
fun `given beacon location data and event when senderId is null or empty then it is ignored`() {
val eventNoSenderId = Event(eventId = AN_EVENT_ID)
val eventEmptySenderId = Event(eventId = AN_EVENT_ID, senderId = "")
val beaconLocationData = MessageBeaconLocationDataContent()
val resultNoSenderId = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance,
event = eventNoSenderId,
content = beaconLocationData,
roomId = "",
relatedEventId = AN_EVENT_ID,
isLocalEcho = false
)
val resultEmptySenderId = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance,
event = eventEmptySenderId,
content = beaconLocationData,
roomId = A_ROOM_ID,
relatedEventId = AN_EVENT_ID,
isLocalEcho = false
)
resultNoSenderId shouldBeEqualTo false
resultEmptySenderId shouldBeEqualTo false
} }
@Test @Test