1+ package com .somemore .global .imageupload .service ;
2+
3+ import com .somemore .global .exception .ImageUploadException ;
4+ import org .junit .jupiter .api .DisplayName ;
5+ import org .junit .jupiter .api .Test ;
6+
7+ import static com .somemore .global .exception .ExceptionMessage .UPLOAD_FAILED ;
8+ import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
9+ import static org .junit .jupiter .api .Assertions .assertEquals ;
10+ import static org .junit .jupiter .api .Assertions .assertThrows ;
11+
12+ class PresignedUrlTest {
13+
14+ @ Test
15+ @ DisplayName ("쿼리 문자열이 포함된 URL에서 removeQueryString() 호출 시 쿼리 문자열 제거 후 반환" )
16+ void removeQueryString_shouldReturnUrlWithoutQuery () {
17+ // given
18+ String url = "https://example.com/file.png?param=value" ;
19+ PresignedUrl presignedUrl = PresignedUrl .from (url );
20+
21+ // when
22+ String result = presignedUrl .removeQueryString ();
23+
24+ // then
25+ assertEquals ("https://example.com/file.png" , result );
26+ }
27+
28+ @ Test
29+ @ DisplayName ("쿼리 문자열이 없는 URL을 PresignedUrl.from()으로 생성하면 예외 발생" )
30+ void from_shouldThrowException_whenUrlHasNoQueryString () {
31+ // given
32+ String url = "https://example.com/file.png" ;
33+
34+ // when
35+ // then
36+ ImageUploadException exception = assertThrows (ImageUploadException .class ,
37+ () -> PresignedUrl .from (url ));
38+
39+ assertEquals (UPLOAD_FAILED .getMessage (), exception .getMessage ());
40+ }
41+
42+ @ Test
43+ @ DisplayName ("null 값을 PresignedUrl.from()으로 전달하면 예외 발생" )
44+ void from_shouldThrowException_whenUrlIsNull () {
45+ // given
46+ String url = null ;
47+
48+ // when
49+ // then
50+ assertThrows (ImageUploadException .class ,
51+ () -> PresignedUrl .from (url ));
52+ }
53+
54+ @ Test
55+ @ DisplayName ("removeQueryString() 호출 시 올바르게 동작하고 예외가 발생하지 않음" )
56+ void removeQueryString_shouldWorkCorrectly () {
57+ // given
58+ String url = "https://example.com/file.png?param=value" ;
59+ PresignedUrl presignedUrl = PresignedUrl .from (url );
60+
61+ // when
62+ // then
63+ assertDoesNotThrow (presignedUrl ::removeQueryString );
64+ }
65+ }
0 commit comments