Skip to content

Commit

Permalink
fix 1 hot spot (#140)
Browse files Browse the repository at this point in the history
  • Loading branch information
khanhduzz authored Sep 26, 2024
1 parent 33b4521 commit 86539d3
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
Expand Down Expand Up @@ -216,7 +215,7 @@ public boolean checkPhoneIsDuplicate(String phone) {
public User getUserByEmailOrPhone(String emailOrPhone) {
User user = userRepository.findByEmailOrPhone(emailOrPhone);
if (user == null) {
throw new UsernameNotFoundException(String.format("User not found with email or phone: %s", emailOrPhone));
throw new NotFoundException("User not found with email or phone: ", emailOrPhone);
}
return user;
}
Expand Down
8 changes: 1 addition & 7 deletions src/test/java/com/fjb/sunrise/services/UserServiceTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,6 @@
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
Expand Down Expand Up @@ -261,7 +255,7 @@ void getUserByEmailOrPhone_WhenUserDoesNotExist_ShouldThrowUsernameNotFoundExcep

Mockito.when(userRepository.findByEmailOrPhone(emailOrPhone)).thenReturn(null);

assertThrows(UsernameNotFoundException.class, () -> userService.getUserByEmailOrPhone(emailOrPhone));
assertThrows(NotFoundException.class, () -> userService.getUserByEmailOrPhone(emailOrPhone));
}

@Test
Expand Down

0 comments on commit 86539d3

Please sign in to comment.