This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #64 from f-lab-edu/feature/28
[#28] 사용자의 개별 알람 읽기 기능 구현
- Loading branch information
Showing
8 changed files
with
145 additions
and
8 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
12 changes: 12 additions & 0 deletions
12
src/main/java/me/soo/helloworld/exception/NoSuchAlarmException.java
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 |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package me.soo.helloworld.exception; | ||
|
||
public class NoSuchAlarmException extends RuntimeException { | ||
|
||
public NoSuchAlarmException(String message) { | ||
super(message); | ||
} | ||
|
||
public NoSuchAlarmException(String message, Throwable cause) { | ||
super(message, cause); | ||
} | ||
} |
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
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
73 changes: 73 additions & 0 deletions
73
src/test/java/me/soo/helloworld/service/AlarmServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package me.soo.helloworld.service; | ||
|
||
import me.soo.helloworld.exception.NoSuchAlarmException; | ||
import me.soo.helloworld.mapper.AlarmMapper; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.mockito.InjectMocks; | ||
import org.mockito.Mock; | ||
import org.mockito.junit.jupiter.MockitoExtension; | ||
|
||
import java.util.Optional; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertThrows; | ||
import static org.mockito.Mockito.*; | ||
|
||
|
||
@ExtendWith(MockitoExtension.class) | ||
public class AlarmServiceTest { | ||
|
||
private final String to = "Soo"; | ||
|
||
private final int alarmId = 1; | ||
|
||
@InjectMocks | ||
AlarmService alarmService; | ||
|
||
@Mock | ||
AlarmMapper alarmMapper; | ||
|
||
@Test | ||
@DisplayName("해당 알람이 존재하지 않는 경우 hasRead 상태를 읽어오는데 실패하며 예외가 발생합니다.") | ||
public void readAlarmFailOnNotExistingAlarm() { | ||
when(alarmMapper.getHasReadStatus(alarmId, to)).thenReturn(Optional.empty()); | ||
|
||
assertThrows(NoSuchAlarmException.class, () -> { | ||
alarmService.getAlarm(alarmId, to); | ||
}); | ||
|
||
verify(alarmMapper, times(1)).getHasReadStatus(alarmId, to); | ||
verify(alarmMapper, never()).updateToRead(alarmId, to); | ||
verify(alarmMapper, never()).getAlarm(alarmId, to); | ||
|
||
} | ||
|
||
@Test | ||
@DisplayName("해당 알람이 존재하여 기존에 읽지 않은 상태인 'N'을 리턴하는 경우 읽었다는 'Y'로 업데이트하고 알람을 읽어오는데 성공합니다.") | ||
public void readAlarmSuccessOnExistingUnreadAlarm() { | ||
String unRead = "N"; | ||
when(alarmMapper.getHasReadStatus(alarmId, to)).thenReturn(Optional.of(unRead)); | ||
doNothing().when(alarmMapper).updateToRead(alarmId, to); | ||
|
||
alarmService.getAlarm(alarmId, to); | ||
|
||
verify(alarmMapper, times(1)).getHasReadStatus(alarmId, to); | ||
verify(alarmMapper, times(1)).updateToRead(alarmId, to); | ||
verify(alarmMapper, times(1)).getAlarm(alarmId, to); | ||
} | ||
|
||
@Test | ||
@DisplayName("해당 알람이 존재하여 기존에 읽은 상태인 'Y'를 리턴하는 경우 읽은 상태로 업데이트 하는 과정 없이 바로 알람을 읽어오는데 성공합니다.") | ||
public void readAlarmSuccessOnExistingReadAlarm() { | ||
String read = "Y"; | ||
when(alarmMapper.getHasReadStatus(alarmId, to)).thenReturn(Optional.of(read)); | ||
|
||
alarmService.getAlarm(alarmId, to); | ||
|
||
verify(alarmMapper, times(1)).getHasReadStatus(alarmId, to); | ||
verify(alarmMapper, never()).updateToRead(alarmId, to); | ||
verify(alarmMapper, times(1)).getAlarm(alarmId, to); | ||
} | ||
|
||
} |
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