Skip to content

Commit

Permalink
Merge pull request #27 from My-Music-Note/fix-issues
Browse files Browse the repository at this point in the history
SonarCloud Issue Fix
  • Loading branch information
masiljangajji authored Dec 15, 2024
2 parents f4bedfd + e387b86 commit ecbe35a
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
5 changes: 1 addition & 4 deletions src/main/java/my/music/note/back/service/UserService.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ public class UserService {
private final UserRepository userRepository;

public User loginOrRegister(LoginOrRegisterRequest request) {

if (userRepository.existsByProviderId(request.providerId())) {
return userRepository.findByProviderId(request.providerId());
}
Expand All @@ -34,13 +33,11 @@ public User loginOrRegister(LoginOrRegisterRequest request) {
public void deleteUser(DeleteAccountRequest request) {
Optional<User> optionalUser = userRepository.findById(request.id());


User user = optionalUser.orElseThrow(RuntimeException::new);
user.deleteAccount();;
user.deleteAccount();
}

public void modifyName(ModifyNameRequest request, Long userId) {

Optional<User> optionalUser = userRepository.findById(userId);
User user = optionalUser.orElseThrow(RuntimeException::new);

Expand Down
8 changes: 8 additions & 0 deletions src/test/java/my/music/note/back/BackApplicationTests.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
package my.music.note.back;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.context.ApplicationContext;

import static org.assertj.core.api.AssertionsForClassTypes.assertThat;

@SpringBootTest
class BackApplicationTests {

@Autowired
ApplicationContext applicationContext;

@Test
void contextLoads() {
assertThat(applicationContext).isNotNull();
}

}
15 changes: 13 additions & 2 deletions src/test/java/my/music/note/back/service/DiaryServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,12 @@ void createDiaryTestFailure() {

when(userRepository.findById(anyLong())).thenReturn(Optional.empty());

assertThrows(NoSuchElementException.class, () -> diaryService.createDiary(new DiaryCreateRequest("test-content", true), 1L));
DiaryCreateRequest request = new DiaryCreateRequest("test-content", true);

assertThrows(NoSuchElementException.class, () ->
diaryService.createDiary(request, 1L)
);

}


Expand Down Expand Up @@ -116,8 +121,14 @@ void modifyDiaryTestSuccess(@Mock Diary diary) {
@Test
@DisplayName("일기 내용 수정 실패 - 해당 유저 or 일기 존재하지 않음")
void modifyDiaryTestFailure() {

when(diaryRepository.existsByIdAndUserId(1L, 1L)).thenReturn(false);
assertThrows(IllegalArgumentException.class, () -> diaryService.modifyDiary(1L, 1L, new DiaryModifyRequest("modify-test-content")));

DiaryModifyRequest request = new DiaryModifyRequest("modify-test-content");

assertThrows(IllegalArgumentException.class, () ->
diaryService.modifyDiary(1L, 1L, request)
);
}

@Test
Expand Down

0 comments on commit ecbe35a

Please sign in to comment.