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(
event = Event(eventId = AN_EVENT_ID, senderId = null),
beaconInfo = MessageBeaconInfoContent()
),
// empty senderId
IgnoredBeaconInfoEvent(
event = Event(eventId = AN_EVENT_ID, senderId = ""),
beaconInfo = MessageBeaconInfoContent()
),
// beacon is live and no eventId
IgnoredBeaconInfoEvent(
event = Event(eventId = null, senderId = A_SENDER_ID),
beaconInfo = MessageBeaconInfoContent(isLive = true)
),
// beacon is live and eventId is empty
IgnoredBeaconInfoEvent(
event = Event(eventId = "", senderId = A_SENDER_ID),
beaconInfo = MessageBeaconInfoContent(isLive = true)
),
// beacon is not live and replaced event id is null
IgnoredBeaconInfoEvent(
event = Event(
eventId = AN_EVENT_ID,
senderId = A_SENDER_ID,
unsignedData = UnsignedData(
age = 123,
replacesState = null
) )
val unsignedDataWithEmptyEventId = UnsignedData( ),
beaconInfo = MessageBeaconInfoContent(isLive = false)
),
// beacon is not live and replaced event id is empty
IgnoredBeaconInfoEvent(
event = Event(
eventId = AN_EVENT_ID,
senderId = A_SENDER_ID,
unsignedData = UnsignedData(
age = 123, age = 123,
replacesState = "" replacesState = ""
) )
val eventWithNoEventId = Event(senderId = A_SENDER_ID, unsignedData = unsignedDataWithNoEventId) ),
val eventWithEmptyEventId = Event(senderId = A_SENDER_ID, eventId = "", unsignedData = unsignedDataWithEmptyEventId) beaconInfo = MessageBeaconInfoContent(isLive = false)
val beaconInfoLive = MessageBeaconInfoContent(isLive = true) ),
val beaconInfoNotLive = MessageBeaconInfoContent(isLive = false) )
val resultLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo( ignoredInfoEvents.forEach {
val result = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = eventWithNoEventId, event = it.event,
content = beaconInfoLive, content = it.beaconInfo,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithEmptyEventId,
content = beaconInfoLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultNotLiveNoEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithNoEventId,
content = beaconInfoNotLive,
roomId = A_ROOM_ID,
isLocalEcho = false
)
val resultNotLiveEmptyEventId = liveLocationAggregationProcessor.handleBeaconInfo(
realm = fakeRealm.instance,
event = eventWithEmptyEventId,
content = beaconInfoNotLive,
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
isLocalEcho = false isLocalEcho = false
) )
resultLiveNoEventId shouldBeEqualTo false result shouldBeEqualTo false
resultLiveEmptyEventId shouldBeEqualTo false }
resultNotLiveNoEventId shouldBeEqualTo false
resultNotLiveEmptyEventId 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 {
val result = liveLocationAggregationProcessor.handleBeaconLocationData(
realm = fakeRealm.instance, realm = fakeRealm.instance,
event = event, event = event,
content = beaconLocationData, content = beaconLocationData,
roomId = A_ROOM_ID, roomId = A_ROOM_ID,
relatedEventId = null, relatedEventId = it,
isLocalEcho = false isLocalEcho = false
) )
val resultEmptyRelatedEventId = liveLocationAggregationProcessor.handleBeaconLocationData( result shouldBeEqualTo false
realm = fakeRealm.instance,
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