-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5기 손가현] Shorten-URL 과제 제출합니다. #72
Open
hyun2371
wants to merge
14
commits into
prgrms-be-devcourse:hyun2371
Choose a base branch
from
hyun2371:main
base: hyun2371
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+916
−0
Open
Changes from 1 commit
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
67c440e
[Feat] 프로젝트 초기 설정
hyun2371 e97a83c
[Feat] 데이터베이스 연동하기
hyun2371 4353eaa
[Feat] 엔티티 추가
hyun2371 21f4e6c
[Feat] DTO 및 검증 로직 추가
hyun2371 897e437
[Feat] 전역 예외 처리 핸들러 추가
hyun2371 d105911
[Feat] Shortening key 생성 알고리즘 추가
hyun2371 f2d160f
[Feat] 레이어별 로직 추가
hyun2371 dc562b1
[Feat] html 페이지 추가
hyun2371 45ae2f2
[Feat] Short Url 전체 주소로 반환
hyun2371 fca3743
[Refactor] url 저장 및 조회 로직 수정
hyun2371 925e8b1
[Refactor] 코드 리포맷팅
hyun2371 045ff56
[Feat] 서비스 테스트 코드 작성
hyun2371 76fb917
[Feat] url 형식 검사 테스트 추가
hyun2371 0fc1f64
[Refactor] 파일 이름 수정
hyun2371 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
[Feat] 서비스 테스트 코드 작성
commit 045ff56197e41bd3318a106bad1bdeecd29d0876
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
70 changes: 70 additions & 0 deletions
70
urlshortener/src/test/java/com/prgrms/url_shortener/service/UrlServiceTest.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,70 @@ | ||
package com.prgrms.url_shortener.service; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.when; | ||
|
||
import com.prgrms.url_shortener.algorithm.Base62Algorithm; | ||
import com.prgrms.url_shortener.dto.ShortenUrlRequest; | ||
import com.prgrms.url_shortener.dto.ShortenUrlResponse; | ||
import com.prgrms.url_shortener.entity.Url; | ||
import com.prgrms.url_shortener.repository.UrlRepository; | ||
import java.util.Optional; | ||
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 org.springframework.test.util.ReflectionTestUtils; | ||
|
||
|
||
@ExtendWith(MockitoExtension.class) | ||
class UrlServiceTest { | ||
@Mock | ||
private UrlRepository repository; | ||
|
||
@InjectMocks | ||
private UrlService service; | ||
|
||
@DisplayName("Base62인코딩으로 shortenUrl을 생성할 수 있다.") | ||
@Test | ||
void create_url() { | ||
//given | ||
String originUrl = "https://daum.net"; | ||
ShortenUrlRequest request = new ShortenUrlRequest(originUrl); | ||
|
||
Url url = new Url(originUrl); | ||
ReflectionTestUtils.setField(url, "id", 1L); | ||
|
||
when(repository.existsByOriginUrl(originUrl)).thenReturn(false); | ||
when(repository.save(any(Url.class))).thenReturn(url); | ||
String shortUri = Base62Algorithm.encode(1L); | ||
|
||
//when | ||
ShortenUrlResponse response = service.getShortUrl(request); | ||
|
||
//then | ||
assertThat(response.shortenUrl()).endsWith(shortUri); | ||
} | ||
|
||
|
||
@DisplayName("shortUri을 디코딩하여 DB에 저장된 originUrl을 가져올 수 있다.") | ||
@Test | ||
void get_origin_url() { | ||
//given | ||
String expectedOriginUrl = "https://daum.net"; | ||
Url url = new Url(expectedOriginUrl); | ||
ReflectionTestUtils.setField(url, "id", 1L); | ||
|
||
String shortUri = Base62Algorithm.encode(1L); | ||
|
||
when(repository.findById(any(Long.class))).thenReturn(Optional.of(url)); | ||
|
||
//when | ||
String actualOriginUrl = service.getOriginUrl(shortUri); | ||
|
||
//then | ||
assertThat(actualOriginUrl).isEqualTo(expectedOriginUrl); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
테스트 작성해주신 부분은 좋지만 추가되면 좋을 부분이 있습니다.
테스트만 봤을 때는 요구사항을 만족하는지 알 수가 없습니다.