[JAVA-13221] Added test case + clean up (#12850)
Co-authored-by: panagiotiskakos <panagiotis.kakos@libra-is.com>
This commit is contained in:
parent
bf719b41aa
commit
e460a10c6d
|
@ -2,16 +2,25 @@ package com.baeldung.pattern.cleanarchitecture.usercreation;
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat;
|
import static org.assertj.core.api.Assertions.assertThat;
|
||||||
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
import static org.assertj.core.api.Assertions.assertThatThrownBy;
|
||||||
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||||
|
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.ArgumentMatchers.anyString;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
import static org.mockito.Mockito.verify;
|
||||||
|
|
||||||
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.junit.jupiter.api.Test;
|
import org.junit.jupiter.api.Test;
|
||||||
import org.springframework.web.server.ResponseStatusException;
|
import org.springframework.web.server.ResponseStatusException;
|
||||||
|
|
||||||
import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseFormatter;
|
|
||||||
import com.baeldung.pattern.cleanarchitecture.usercreation.UserResponseModel;
|
|
||||||
|
|
||||||
class UserResponseFormatterUnitTest {
|
class UserResponseFormatterUnitTest {
|
||||||
|
|
||||||
UserResponseFormatter userResponseFormatter = new UserResponseFormatter();
|
UserResponseFormatter userResponseFormatter = new UserResponseFormatter();
|
||||||
|
UserRegisterDsGateway userDsGateway = mock(UserRegisterDsGateway.class);
|
||||||
|
UserPresenter userPresenter = mock(UserPresenter.class);
|
||||||
|
UserFactory userFactory = mock(UserFactory.class);
|
||||||
|
UserInputBoundary userInputBoundary = new UserRegisterInteractor(userDsGateway, userPresenter, userFactory);
|
||||||
|
ArgumentCaptor<String> userRequestModelArgumentCaptor = ArgumentCaptor.forClass(String.class);
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void givenDateAnd3HourTime_whenPrepareSuccessView_thenReturnOnly3HourTime() {
|
void givenDateAnd3HourTime_whenPrepareSuccessView_thenReturnOnly3HourTime() {
|
||||||
|
@ -23,7 +32,19 @@ class UserResponseFormatterUnitTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void whenPrepareFailView_thenThrowHttpConflictException() {
|
void whenPrepareFailView_thenThrowHttpConflictException() {
|
||||||
assertThatThrownBy(() -> userResponseFormatter.prepareFailView("Invalid password"))
|
assertThatThrownBy(() -> userResponseFormatter.prepareFailView("Invalid password")).isInstanceOf(ResponseStatusException.class);
|
||||||
.isInstanceOf(ResponseStatusException.class);
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void whenCreateUser_thenSuccess() {
|
||||||
|
|
||||||
|
UserRequestModel userRequestModel = new UserRequestModel("baeldung", "123456");
|
||||||
|
when(userFactory.create(anyString(), anyString())).thenReturn(new CommonUser("baeldung", "123456"));
|
||||||
|
|
||||||
|
userInputBoundary.create(userRequestModel);
|
||||||
|
|
||||||
|
verify(userDsGateway).existsByName(userRequestModelArgumentCaptor.capture());
|
||||||
|
String name = userRequestModel.getName();
|
||||||
|
assertEquals("baeldung", name);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue