-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Multicast Message Converter를 Object 클래스로 변경
- Loading branch information
1 parent
242822e
commit 4c02d4b
Showing
3 changed files
with
24 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 21 additions & 19 deletions
40
dmforu-infrastructure/fcm/src/test/kotlin/com/dmforu/fcm/FirebaseMessageSenderTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,50 @@ | ||
package com.dmforu.fcm | ||
|
||
import com.dmforu.domain.message.NoticeMessage | ||
import com.dmforu.domain.notice.Notice | ||
import com.google.firebase.messaging.FirebaseMessaging | ||
import com.google.firebase.messaging.MulticastMessage | ||
import org.junit.jupiter.api.Assertions.* | ||
import org.junit.jupiter.api.BeforeEach | ||
import org.junit.jupiter.api.DisplayName | ||
import org.junit.jupiter.api.Test | ||
import org.junit.jupiter.api.extension.ExtendWith | ||
|
||
import org.mockito.BDDMockito.given | ||
import org.mockito.InjectMocks | ||
import org.mockito.Mock | ||
import org.mockito.Mockito.mock | ||
import org.mockito.Mockito.verify | ||
import org.mockito.junit.jupiter.MockitoExtension | ||
import org.mockito.kotlin.eq | ||
import org.mockito.kotlin.any | ||
import org.mockito.kotlin.given | ||
import java.time.LocalDate | ||
|
||
@ExtendWith(MockitoExtension::class) | ||
class FirebaseMessageSenderTest { | ||
|
||
@Mock | ||
private lateinit var firebaseMessageConverter: FirebaseMessageConverter | ||
|
||
@Mock | ||
private lateinit var firebaseMessaging: FirebaseMessaging | ||
|
||
@InjectMocks | ||
private lateinit var messageSender: FirebaseMessageSender | ||
|
||
@BeforeEach | ||
fun setUp() { | ||
firebaseMessaging = mock() | ||
messageSender = FirebaseMessageSender(firebaseMessaging) | ||
} | ||
|
||
@DisplayName("공지를 푸시 알림으로 전송한다.") | ||
@Test | ||
fun sendNoticeMessage() { | ||
// given | ||
val message = mock(NoticeMessage::class.java) | ||
val multicastMessage = mock(MulticastMessage::class.java) | ||
val notice = Notice.of( | ||
number = 1, | ||
type = "대학", | ||
date = LocalDate.now(), | ||
title = "공지사항입니다.", | ||
author = "관리자", | ||
url = "https://www.test.com" | ||
) | ||
val message = NoticeMessage.createDepartmentNoticeMessage(notice) | ||
val tokens = listOf("토큰1", "토큰2") | ||
|
||
given(firebaseMessageConverter.buildMessageToNotice(eq(message), eq(tokens))).willReturn(multicastMessage) | ||
|
||
// when | ||
messageSender.sendNoticeMessage(message, tokens) | ||
|
||
// then | ||
verify(firebaseMessageConverter).buildMessageToNotice(message, tokens) | ||
verify(firebaseMessaging).sendEachForMulticast(multicastMessage) | ||
verify(firebaseMessaging).sendEachForMulticast(any()) | ||
} | ||
} |