-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated link repository and service, controller, added javadoc
- Loading branch information
1 parent
b5dd793
commit 3947d0e
Showing
9 changed files
with
81 additions
and
59 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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,12 +2,17 @@ | |
|
||
import com.linkurlshorter.urlshortener.user.User; | ||
import com.linkurlshorter.urlshortener.user.UserRole; | ||
import jakarta.persistence.EntityManager; | ||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
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.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.*; | ||
|
@@ -189,36 +194,31 @@ void findByShortLinkNotFoundTest() { | |
} | ||
|
||
/** | ||
* Test case for the {@link LinkService#findAllByUser(User)} method. | ||
* Test case for the {@link LinkService#findAllByUserId(UUID)} method. | ||
*/ | ||
@Test | ||
void findByAllByUserTest() { | ||
User user = User.builder() | ||
.id(UUID.fromString("84991c79-f6a9-4b7b-b1b4-0d66c0b92c81")) | ||
.email("[email protected]") | ||
.password("password1") | ||
.role(UserRole.USER) | ||
.build(); | ||
|
||
void findByAllByUserIdTest() { | ||
UUID userId = UUID.fromString("84991c79-f6a9-4b7b-b1b4-0d66c0b92c81"); | ||
User user = User.builder().id(userId).build(); | ||
List<Link> userLinks = Arrays.asList( | ||
Link.builder().id(UUID.randomUUID()).user(user).build(), | ||
Link.builder().id(UUID.randomUUID()).user(user).build(), | ||
Link.builder().id(UUID.randomUUID()).user(user).build() | ||
); | ||
|
||
when(linkRepository.findAllByUser(user)).thenReturn(userLinks); | ||
List<Link> foundLinks = linkService.findAllByUser(user); | ||
when(linkRepository.findAllByUserId(userId)).thenReturn(userLinks); | ||
List<Link> foundLinks = linkService.findAllByUserId(userId); | ||
|
||
assertThat(foundLinks).isNotNull().isEqualTo(userLinks); | ||
verify(linkRepository, times(1)).findAllByUser(user); | ||
verify(linkRepository, times(1)).findAllByUserId(userId); | ||
} | ||
|
||
/** | ||
* Test case for the {@link LinkService#findAllByUser(User)} method when the provided user is null. | ||
* Test case for the {@link LinkService#findAllByUserId(UUID)} method when the provided user is null. | ||
*/ | ||
@Test | ||
void findAllByNullUserTest() { | ||
assertThatThrownBy(() -> linkService.findAllByUser(null)) | ||
assertThatThrownBy(() -> linkService.findAllByUserId(null)) | ||
.isInstanceOf(NullLinkPropertyException.class); | ||
} | ||
|
||
|