-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
test: Greeting 도메인 테스트 코드 작성 #458
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
fa88486
rename: GreetingCache Manager로 네이밍 변경 (#457)
its-sky 640ef95
feat: FakeGreetingCacheManager 구현 (#457)
its-sky f245b81
feat: FakeAIManager 구현 (#457)
its-sky 6f24bdc
test: GreetingService 인삿말 조회 테스트 (#457)
its-sky ba6a198
chore: GreetingSuccessType 성공 코드 및 문자 변경 (#457)
its-sky 66bb096
test: GreetingController 테스트 (#457)
its-sky File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
17 changes: 17 additions & 0 deletions
17
module-domain/src/test/java/com/depromeet/mock/greeting/FakeAIManager.java
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 |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.depromeet.mock.greeting; | ||
|
||
import com.depromeet.greeting.port.out.AIPort; | ||
|
||
public class FakeAIManager implements AIPort { | ||
private static final String GENERATED_RESPONSE = "Hello, World!"; | ||
|
||
@Override | ||
public String getSummary(String inputText) { | ||
return GENERATED_RESPONSE; | ||
} | ||
|
||
@Override | ||
public String getChatCompletions() { | ||
return GENERATED_RESPONSE; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
module-domain/src/test/java/com/depromeet/mock/greeting/FakeGreetingCacheManager.java
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 |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.depromeet.mock.greeting; | ||
|
||
import com.depromeet.greeting.domain.Greeting; | ||
import com.depromeet.greeting.port.out.GreetingCachePort; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class FakeGreetingCacheManager implements GreetingCachePort { | ||
private static final String GREETING_KEY = "greeting"; | ||
private Map<String, String> data = new HashMap<>(); | ||
|
||
@Override | ||
public Greeting saveGreeting(Greeting greeting) { | ||
if (greeting.getMessage() != null) { | ||
data.put(GREETING_KEY, greeting.getMessage()); | ||
} | ||
return greeting; | ||
} | ||
|
||
@Override | ||
public Greeting getGreeting() { | ||
return new Greeting(data.get(GREETING_KEY)); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
module-domain/src/test/java/com/depromeet/service/greeting/GreetingServiceTest.java
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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package com.depromeet.service.greeting; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
import com.depromeet.greeting.domain.Greeting; | ||
import com.depromeet.greeting.port.out.AIPort; | ||
import com.depromeet.greeting.port.out.GreetingCachePort; | ||
import com.depromeet.greeting.service.GreetingService; | ||
import com.depromeet.mock.greeting.FakeAIManager; | ||
import com.depromeet.mock.greeting.FakeGreetingCacheManager; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class GreetingServiceTest { | ||
private AIPort aiPort; | ||
private GreetingCachePort greetingCachePort; | ||
private GreetingService greetingService; | ||
|
||
@BeforeEach | ||
void init() { | ||
aiPort = new FakeAIManager(); | ||
greetingCachePort = new FakeGreetingCacheManager(); | ||
greetingService = new GreetingService(aiPort, greetingCachePort); | ||
} | ||
|
||
@Test | ||
public void 인삿말을_조회합니다() throws Exception { | ||
// when | ||
Greeting greeting = greetingService.getGreeting(); | ||
|
||
// then | ||
assertThat(greeting.getMessage()).isEqualTo("Hello, World!"); | ||
} | ||
} |
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
25 changes: 25 additions & 0 deletions
25
module-presentation/src/test/java/com/depromeet/greeting/api/GreetingControllerTest.java
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 |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package com.depromeet.greeting.api; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | ||
|
||
import com.depromeet.config.ControllerTestConfig; | ||
import com.depromeet.config.mock.WithCustomMockMember; | ||
import com.depromeet.greeting.facade.GreetingFacade; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
|
||
@WebMvcTest(GreetingController.class) | ||
public class GreetingControllerTest extends ControllerTestConfig { | ||
@MockBean GreetingFacade greetingFacade; | ||
|
||
@Test | ||
@WithCustomMockMember | ||
public void 인삿말을_조회합니다() throws Exception { | ||
mockMvc.perform(get("/greeting")) | ||
.andExpect(status().isOk()) | ||
.andExpect(jsonPath("$.code").value("GREETING_1")) | ||
.andExpect(jsonPath("$.message").value("인삿말 조회에 성공하였습니다")); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
API 테스트에 페이크를 적절히 사용하신 것 배워 가겠습니다 !!! 멋진 코드