test 정리
parent
b2c0a1574c
commit
39df7f7dd6
@ -0,0 +1,54 @@
|
||||
package com.xit.core.repository.core;
|
||||
|
||||
import com.xit.biz.cmm.repository.ICmmUserRepository;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.context.junit.jupiter.SpringExtension;
|
||||
|
||||
@ExtendWith(SpringExtension.class)
|
||||
@DataJpaTest
|
||||
@ActiveProfiles(value = "dev")
|
||||
public class CmmUserRepositoryTest {
|
||||
@Autowired
|
||||
private ICmmUserRepository cmmUserRepository;
|
||||
|
||||
|
||||
// @Test
|
||||
// public void saveUserTest() {
|
||||
// User user = new User(null,"name", "password");
|
||||
// User savedUser = userRepository.save(user);
|
||||
// Assertions.assertEquals(user.getEmail(), savedUser.getEmail(),
|
||||
// "saveUserTest");
|
||||
// Assertions.assertEquals(user.getPassword(), savedUser.getPassword(),
|
||||
// "saveUserTest");
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void findByEmailSuccessTest() {
|
||||
// User user = new User(null, "name1", "password");
|
||||
// User savedUser = userRepository.save(user);
|
||||
//
|
||||
// Optional<User> userFindByEmail = userRepository.findByEmail(user.getEmail());
|
||||
// userFindByEmail.ifPresent(value -> Assertions.assertEquals(savedUser.getEmail(), value.getEmail()));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void findByEmailFailureTest() {
|
||||
//
|
||||
// Optional<User> userFindByEmail = userRepository.findByEmail("not exist email");
|
||||
// Assertions.assertEquals(Optional.empty(), userFindByEmail);
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// public void idStrategyTest() {
|
||||
// User user1 = new User(null, "name1", "password");
|
||||
// User user2 = new User(null,"name2", "password");
|
||||
// User savedUser1 = userRepository.save(user1);
|
||||
// User savedUser2 = userRepository.save(user2);
|
||||
//
|
||||
// Assertions.assertEquals(1, Math.abs(savedUser1.getId() - savedUser2.getId()));
|
||||
//
|
||||
// }
|
||||
}
|
@ -0,0 +1,96 @@
|
||||
package com.xit.core.service.core;
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
public class OAuthLocalServiceTest {
|
||||
|
||||
// @Mock
|
||||
// private UserRepository userRepository;
|
||||
//
|
||||
// @InjectMocks
|
||||
// private UserService userService = new UserServiceImpl(this.userRepository);
|
||||
|
||||
// @Test
|
||||
// void addUserSuccessfully() {
|
||||
// final User user = new User(null, "name", "password");
|
||||
// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.empty());
|
||||
// given(userRepository.save(user)).willReturn(user);
|
||||
//
|
||||
// User savedUser = userService.add(user);
|
||||
// Assertions.assertNotNull(savedUser);
|
||||
// verify(userRepository).findByEmail(anyString());
|
||||
// verify(userRepository).save(any(User.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void addUserFailure() {
|
||||
// final User user = new User(1L, "name", "password");
|
||||
// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.of(user));
|
||||
// Assertions.assertThrows(UserNotFoundException.class, () -> userService.add(user));
|
||||
// verify(userRepository, never()).save(any(User.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void getUserSuccessfully() {
|
||||
// final User user = new User(1L, "name", "password");
|
||||
// given(userRepository.findById(user.getId())).willReturn(Optional.of(user));
|
||||
// User userByGet = userService.get(user.getId());
|
||||
// Assertions.assertEquals(user, userByGet);
|
||||
// verify(userRepository).findById(anyLong());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void getUserFailure() {
|
||||
// given(userRepository.findById(anyLong())).willReturn(Optional.empty());
|
||||
// Assertions.assertThrows(UserNotFoundException.class, () -> userService.get(anyLong()));
|
||||
// verify(userRepository).findById(anyLong());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void updateSuccessfully() {
|
||||
// final User user = new User(1L, "name", "password");
|
||||
// given(userRepository.findById(user.getId())).willReturn(Optional.of(user));
|
||||
// given(userRepository.save(user)).willReturn(user);
|
||||
// User updatedUser = userService.update(user);
|
||||
// Assertions.assertNotNull(updatedUser);
|
||||
// verify(userRepository).save(any(User.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void updateFailure() {
|
||||
// final User user = new User(1L, "name", "password");
|
||||
// given(userRepository.findById(anyLong())).willReturn(Optional.empty());
|
||||
// Assertions.assertThrows(UserNotFoundException.class, () -> userService.update(user));
|
||||
// verify(userRepository).findById(anyLong());
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void deleteSuccessfully() {
|
||||
// final Long id = 1L;
|
||||
// userService.delete(id);
|
||||
// verify(userRepository, times(1)).deleteById(anyLong());
|
||||
// verify(userRepository, times(1)).findById(anyLong());
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void findByEmailSuccessfully() {
|
||||
// final User user = new User(1L, "name", "password");
|
||||
// given(userRepository.findByEmail(user.getEmail())).willReturn(Optional.of(user));
|
||||
// User userByEmail = userService.findByEmail(user.getEmail());
|
||||
// Assertions.assertEquals(user, userByEmail);
|
||||
// verify(userRepository).findByEmail(any(String.class));
|
||||
// }
|
||||
//
|
||||
// @Test
|
||||
// void findByEmailFailure() {
|
||||
// final String email = "email";
|
||||
// given(userRepository.findByEmail(email)).willReturn(Optional.empty());
|
||||
// Assertions.assertThrows(UserNotFoundException.class, () -> userService.findByEmail(email));
|
||||
// verify(userRepository).findByEmail(any(String.class));
|
||||
// }
|
||||
}
|
Loading…
Reference in New Issue