Rename Fake class with Mockk prefix for clarity

This commit is contained in:
Benoit Marty
2024-03-26 11:49:57 +01:00
committed by Benoit Marty
parent 8588ce7a72
commit e9308400bd
11 changed files with 63 additions and 63 deletions

View File

@@ -23,10 +23,10 @@ import io.element.android.libraries.matrix.test.A_SPACE_ID
import io.element.android.libraries.matrix.test.A_THREAD_ID
import io.element.android.libraries.matrix.test.FakeMatrixClientProvider
import io.element.android.libraries.matrix.test.core.aBuildMeta
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.FakeImageLoaderHolder
import io.element.android.libraries.push.impl.notifications.fake.FakeRoomGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.FakeSummaryGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkRoomGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkSummaryGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
import io.element.android.services.appnavstate.api.AppNavigationState
@@ -115,12 +115,12 @@ class DefaultNotificationDrawerManagerTest {
appNavigationStateService = appNavigationStateService
),
notificationRenderer = NotificationRenderer(
NotificationIdProvider(),
NotificationDisplayer(context),
NotificationFactory(
FakeNotificationCreator().instance,
FakeRoomGroupMessageCreator().instance,
FakeSummaryGroupMessageCreator().instance,
notificationIdProvider = NotificationIdProvider(),
notificationDisplayer = NotificationDisplayer(context),
notificationFactory = NotificationFactory(
notificationCreator = MockkNotificationCreator().instance,
roomGroupMessageCreator = MockkRoomGroupMessageCreator().instance,
summaryGroupMessageCreator = MockkSummaryGroupMessageCreator().instance,
)
),
notificationEventPersistence = InMemoryNotificationEventPersistence(initialData = initialData),

View File

@@ -25,7 +25,7 @@ import io.element.android.libraries.matrix.test.A_ROOM_ID_2
import io.element.android.libraries.matrix.test.A_SESSION_ID
import io.element.android.libraries.matrix.test.A_SPACE_ID
import io.element.android.libraries.matrix.test.A_THREAD_ID
import io.element.android.libraries.push.impl.notifications.fake.FakeOutdatedEventDetector
import io.element.android.libraries.push.impl.notifications.fake.MockkOutdatedEventDetector
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
import io.element.android.libraries.push.impl.notifications.fixtures.aSimpleNotifiableEvent
import io.element.android.libraries.push.impl.notifications.fixtures.anInviteNotifiableEvent
@@ -42,7 +42,7 @@ private val VIEWING_A_ROOM = aNavigationState(A_SESSION_ID, A_SPACE_ID, A_ROOM_I
private val VIEWING_A_THREAD = aNavigationState(A_SESSION_ID, A_SPACE_ID, A_ROOM_ID, A_THREAD_ID)
class NotifiableEventProcessorTest {
private val outdatedDetector = FakeOutdatedEventDetector()
private val mockkOutdatedDetector = MockkOutdatedEventDetector()
@Test
fun `given simple events when processing then keep simple events`() {
@@ -97,7 +97,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given out of date message event when processing then removes message event`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID))
outdatedDetector.givenEventIsOutOfDate(events[0])
mockkOutdatedDetector.givenEventIsOutOfDate(events[0])
val eventProcessor = createProcessor(navigationState = NOT_VIEWING_A_ROOM)
@@ -113,7 +113,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given in date message event when processing then keep message event`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID))
outdatedDetector.givenEventIsInDate(events[0])
mockkOutdatedDetector.givenEventIsInDate(events[0])
val eventProcessor = createProcessor(navigationState = NOT_VIEWING_A_ROOM)
val result = eventProcessor.process(events, renderedEvents = emptyList())
@@ -128,7 +128,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given viewing the same room main timeline when processing main timeline message event then removes message`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID, threadId = null))
events.forEach { outdatedDetector.givenEventIsOutOfDate(it) }
events.forEach { mockkOutdatedDetector.givenEventIsOutOfDate(it) }
val eventProcessor = createProcessor(isInForeground = true, navigationState = VIEWING_A_ROOM)
val result = eventProcessor.process(events, renderedEvents = emptyList())
@@ -143,7 +143,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given viewing the same thread timeline when processing thread message event then removes message`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID, threadId = A_THREAD_ID))
events.forEach { outdatedDetector.givenEventIsOutOfDate(it) }
events.forEach { mockkOutdatedDetector.givenEventIsOutOfDate(it) }
val eventProcessor = createProcessor(isInForeground = true, navigationState = VIEWING_A_THREAD)
val result = eventProcessor.process(events, renderedEvents = emptyList())
@@ -158,7 +158,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given viewing main timeline of the same room when processing thread timeline message event then keep message`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID, threadId = A_THREAD_ID))
outdatedDetector.givenEventIsInDate(events[0])
mockkOutdatedDetector.givenEventIsInDate(events[0])
val eventProcessor = createProcessor(isInForeground = true, navigationState = VIEWING_A_ROOM)
val result = eventProcessor.process(events, renderedEvents = emptyList())
@@ -173,7 +173,7 @@ class NotifiableEventProcessorTest {
@Test
fun `given viewing thread timeline of the same room when processing main timeline message event then keep message`() {
val events = listOf(aNotifiableMessageEvent(eventId = AN_EVENT_ID, roomId = A_ROOM_ID))
outdatedDetector.givenEventIsInDate(events[0])
mockkOutdatedDetector.givenEventIsInDate(events[0])
val eventProcessor = createProcessor(isInForeground = true, navigationState = VIEWING_A_THREAD)
val result = eventProcessor.process(events, renderedEvents = emptyList())
@@ -213,8 +213,8 @@ class NotifiableEventProcessorTest {
navigationState: NavigationState
): NotifiableEventProcessor {
return NotifiableEventProcessor(
outdatedDetector.instance,
FakeAppNavigationStateService(MutableStateFlow(AppNavigationState(navigationState, isInForeground))),
outdatedDetector = mockkOutdatedDetector.instance,
appNavigationStateService = FakeAppNavigationStateService(MutableStateFlow(AppNavigationState(navigationState, isInForeground))),
)
}
}

View File

@@ -22,10 +22,10 @@ import io.element.android.libraries.matrix.api.user.MatrixUser
import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.A_ROOM_ID
import io.element.android.libraries.matrix.test.A_SESSION_ID
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.FakeImageLoader
import io.element.android.libraries.push.impl.notifications.fake.FakeRoomGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.FakeSummaryGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkRoomGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkSummaryGroupMessageCreator
import io.element.android.libraries.push.impl.notifications.fixtures.aNotifiableMessageEvent
import io.element.android.libraries.push.impl.notifications.fixtures.aSimpleNotifiableEvent
import io.element.android.libraries.push.impl.notifications.fixtures.anInviteNotifiableEvent
@@ -41,19 +41,19 @@ private val A_MESSAGE_EVENT = aNotifiableMessageEvent(eventId = AN_EVENT_ID, roo
@RunWith(RobolectricTestRunner::class)
class NotificationFactoryTest {
private val androidNotificationFactory = FakeNotificationCreator()
private val roomGroupMessageCreator = FakeRoomGroupMessageCreator()
private val summaryGroupMessageCreator = FakeSummaryGroupMessageCreator()
private val mockkNotificationCreator = MockkNotificationCreator()
private val mockkRoomGroupMessageCreator = MockkRoomGroupMessageCreator()
private val mockkSummaryGroupMessageCreator = MockkSummaryGroupMessageCreator()
private val notificationFactory = NotificationFactory(
androidNotificationFactory.instance,
roomGroupMessageCreator.instance,
summaryGroupMessageCreator.instance
notificationCreator = mockkNotificationCreator.instance,
roomGroupMessageCreator = mockkRoomGroupMessageCreator.instance,
summaryGroupMessageCreator = mockkSummaryGroupMessageCreator.instance
)
@Test
fun `given a room invitation when mapping to notification then is Append`() = testWith(notificationFactory) {
val expectedNotification = androidNotificationFactory.givenCreateRoomInvitationNotificationFor(AN_INVITATION_EVENT)
val expectedNotification = mockkNotificationCreator.givenCreateRoomInvitationNotificationFor(AN_INVITATION_EVENT)
val roomInvitation = listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, AN_INVITATION_EVENT))
val result = roomInvitation.toNotifications()
@@ -90,7 +90,7 @@ class NotificationFactoryTest {
@Test
fun `given a simple event when mapping to notification then is Append`() = testWith(notificationFactory) {
val expectedNotification = androidNotificationFactory.givenCreateSimpleInvitationNotificationFor(A_SIMPLE_EVENT)
val expectedNotification = mockkNotificationCreator.givenCreateSimpleInvitationNotificationFor(A_SIMPLE_EVENT)
val roomInvitation = listOf(ProcessedEvent(ProcessedEvent.Type.KEEP, A_SIMPLE_EVENT))
val result = roomInvitation.toNotifications()
@@ -128,7 +128,7 @@ class NotificationFactoryTest {
@Test
fun `given room with message when mapping to notification then delegates to room group message creator`() = testWith(notificationFactory) {
val events = listOf(A_MESSAGE_EVENT)
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
val expectedNotification = mockkRoomGroupMessageCreator.givenCreatesRoomMessageFor(
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
events,
A_ROOM_ID
@@ -197,7 +197,7 @@ class NotificationFactoryTest {
)
)
val withRedactedRemoved = listOf(A_MESSAGE_EVENT.copy(eventId = EventId("\$not-redacted")))
val expectedNotification = roomGroupMessageCreator.givenCreatesRoomMessageFor(
val expectedNotification = mockkRoomGroupMessageCreator.givenCreatesRoomMessageFor(
MatrixUser(A_SESSION_ID, A_SESSION_ID.value, MY_AVATAR_URL),
withRedactedRemoved,
A_ROOM_ID,

View File

@@ -22,8 +22,8 @@ import io.element.android.libraries.matrix.test.AN_EVENT_ID
import io.element.android.libraries.matrix.test.A_ROOM_ID
import io.element.android.libraries.matrix.test.A_SESSION_ID
import io.element.android.libraries.push.impl.notifications.fake.FakeImageLoader
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationFactory
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationDisplayer
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationFactory
import io.element.android.libraries.push.impl.notifications.model.NotifiableEvent
import io.mockk.mockk
import kotlinx.coroutines.test.runTest
@@ -51,14 +51,14 @@ private val ONE_SHOT_META = OneShotNotification.Append.Meta(key = "ignored", sum
@RunWith(RobolectricTestRunner::class)
class NotificationRendererTest {
private val notificationDisplayer = FakeNotificationDisplayer()
private val notificationFactory = FakeNotificationFactory()
private val mockkNotificationDisplayer = MockkNotificationDisplayer()
private val mockkNotificationFactory = MockkNotificationFactory()
private val notificationIdProvider = NotificationIdProvider()
private val notificationRenderer = NotificationRenderer(
notificationIdProvider = notificationIdProvider,
notificationDisplayer = notificationDisplayer.instance,
notificationFactory = notificationFactory.instance,
notificationDisplayer = mockkNotificationDisplayer.instance,
notificationFactory = mockkNotificationFactory.instance,
)
@Test
@@ -67,8 +67,8 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifySummaryCancelled()
notificationDisplayer.verifyNoOtherInteractions()
mockkNotificationDisplayer.verifySummaryCancelled()
mockkNotificationDisplayer.verifyNoOtherInteractions()
}
@Test
@@ -77,7 +77,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID))
cancelNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID))
}
@@ -89,7 +89,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID))
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -108,7 +108,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
showNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomMessagesNotificationId(A_SESSION_ID), A_NOTIFICATION)
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -120,7 +120,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID))
cancelNotificationMessage(tag = AN_EVENT_ID.value, notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID))
}
@@ -132,7 +132,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = AN_EVENT_ID.value, notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID))
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -151,7 +151,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
showNotificationMessage(tag = AN_EVENT_ID.value, notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID), A_NOTIFICATION)
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -163,7 +163,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID))
cancelNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomInvitationNotificationId(A_SESSION_ID))
}
@@ -175,7 +175,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
cancelNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomInvitationNotificationId(A_SESSION_ID))
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -194,7 +194,7 @@ class NotificationRendererTest {
renderEventsAsNotifications()
notificationDisplayer.verifyInOrder {
mockkNotificationDisplayer.verifyInOrder {
showNotificationMessage(tag = A_ROOM_ID.value, notificationIdProvider.getRoomEventNotificationId(A_SESSION_ID), A_NOTIFICATION)
showNotificationMessage(tag = null, notificationIdProvider.getSummaryNotificationId(A_SESSION_ID), A_SUMMARY_NOTIFICATION.notification)
}
@@ -221,7 +221,7 @@ class NotificationRendererTest {
useCompleteNotificationFormat: Boolean = USE_COMPLETE_NOTIFICATION_FORMAT,
summaryNotification: SummaryNotification = A_SUMMARY_NOTIFICATION
) {
notificationFactory.givenNotificationsFor(
mockkNotificationFactory.givenNotificationsFor(
groupedEvents = A_PROCESSED_EVENTS,
matrixUser = MatrixUser(A_SESSION_ID, MY_USER_DISPLAY_NAME, MY_USER_AVATAR_URL),
useCompleteNotificationFormat = useCompleteNotificationFormat,

View File

@@ -23,7 +23,7 @@ import io.element.android.libraries.push.impl.notifications.model.SimpleNotifiab
import io.mockk.every
import io.mockk.mockk
class FakeNotificationCreator {
class MockkNotificationCreator {
val instance = mockk<NotificationCreator>()
fun givenCreateRoomInvitationNotificationFor(event: InviteNotifiableEvent): Notification {

View File

@@ -25,7 +25,7 @@ import io.mockk.mockk
import io.mockk.verify
import io.mockk.verifyOrder
class FakeNotificationDisplayer {
class MockkNotificationDisplayer {
val instance = mockk<NotificationDisplayer>(relaxed = true)
fun givenDisplayDiagnosticNotificationResult(result: Boolean) {

View File

@@ -26,7 +26,7 @@ import io.mockk.coEvery
import io.mockk.every
import io.mockk.mockk
class FakeNotificationFactory {
class MockkNotificationFactory {
val instance = mockk<NotificationFactory>()
fun givenNotificationsFor(

View File

@@ -21,7 +21,7 @@ import io.element.android.libraries.push.impl.notifications.model.NotifiableEven
import io.mockk.every
import io.mockk.mockk
class FakeOutdatedEventDetector {
class MockkOutdatedEventDetector {
val instance = mockk<OutdatedEventDetector>()
fun givenEventIsOutOfDate(notifiableEvent: NotifiableEvent) {

View File

@@ -24,7 +24,7 @@ import io.element.android.libraries.push.impl.notifications.model.NotifiableMess
import io.mockk.coEvery
import io.mockk.mockk
class FakeRoomGroupMessageCreator {
class MockkRoomGroupMessageCreator {
val instance = mockk<RoomGroupMessageCreator>()
fun givenCreatesRoomMessageFor(

View File

@@ -19,6 +19,6 @@ package io.element.android.libraries.push.impl.notifications.fake
import io.element.android.libraries.push.impl.notifications.SummaryGroupMessageCreator
import io.mockk.mockk
class FakeSummaryGroupMessageCreator {
class MockkSummaryGroupMessageCreator {
val instance = mockk<SummaryGroupMessageCreator>()
}

View File

@@ -19,17 +19,17 @@ package io.element.android.libraries.push.impl.troubleshoot
import app.cash.turbine.test
import com.google.common.truth.Truth.assertThat
import io.element.android.libraries.core.notifications.NotificationTroubleshootTestState
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.FakeNotificationDisplayer
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationCreator
import io.element.android.libraries.push.impl.notifications.fake.MockkNotificationDisplayer
import kotlinx.coroutines.launch
import kotlinx.coroutines.test.runTest
import org.junit.Test
class NotificationTestTest {
private val fakeNotificationCreator = FakeNotificationCreator().apply {
private val mockkNotificationCreator = MockkNotificationCreator().apply {
givenCreateDiagnosticNotification()
}
private val fakeNotificationDisplayer = FakeNotificationDisplayer().apply {
private val mockkNotificationDisplayer = MockkNotificationDisplayer().apply {
givenDisplayDiagnosticNotificationResult(true)
}
@@ -37,7 +37,7 @@ class NotificationTestTest {
@Test
fun `test NotificationTest notification cannot be displayed`() = runTest {
fakeNotificationDisplayer.givenDisplayDiagnosticNotificationResult(false)
mockkNotificationDisplayer.givenDisplayDiagnosticNotificationResult(false)
val sut = createNotificationTest()
launch {
sut.run(this)
@@ -80,8 +80,8 @@ class NotificationTestTest {
private fun createNotificationTest(): NotificationTest {
return NotificationTest(
notificationCreator = fakeNotificationCreator.instance,
notificationDisplayer = fakeNotificationDisplayer.instance,
notificationCreator = mockkNotificationCreator.instance,
notificationDisplayer = mockkNotificationDisplayer.instance,
notificationClickHandler = notificationClickHandler
)
}