Skip to content
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

3주차 과제 - Spring 테스트 작성하기 #83

Merged
merged 27 commits into from
Aug 21, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
d3341a1
생성자 추가 , equals , hashCode 추가
jdalma Aug 15, 2022
77d34df
테스트 코드 추가
jdalma Aug 15, 2022
9fb83c8
Task equals메소드 수정
jdalma Aug 16, 2022
b357afb
out 폴더 무시
jdalma Aug 16, 2022
30e07c6
TaskController 계층형 테스트 코드 추가
jdalma Aug 16, 2022
45263d4
toString 메소드 추가
jdalma Aug 16, 2022
4caf49c
import 패키지 * 자동 제거
jdalma Aug 16, 2022
5c8484e
TaskControllerWebTest 계층 테스트 코드 작성
jdalma Aug 16, 2022
8aebc01
Update app/src/test/java/com/codesoom/assignment/controllers/TaskCont…
jdalma Aug 17, 2022
3503251
TaskControllerNestedTest 준비영역과 실행영역을 구분
jdalma Aug 17, 2022
3089b94
TaskControllerWebTest 테스트 코드 작성
jdalma Aug 17, 2022
9815368
Update app/src/test/java/com/codesoom/assignment/controllers/TaskCont…
jdalma Aug 18, 2022
7d25cc2
DEFAULT_SIZE 적용
jdalma Aug 18, 2022
7fd1735
Revert "DEFAULT_SIZE 적용"
jdalma Aug 18, 2022
8e03669
Merge remote-tracking branch 'origin/HEAD'
jdalma Aug 18, 2022
23c6e66
DEFAULT_SIZE 적용
jdalma Aug 18, 2022
d7cdfba
clearTasks 메소드 추가
jdalma Aug 18, 2022
9c7d9e6
TaskControllerNestedTest 주석 수정 및 준비 단계 확인
jdalma Aug 18, 2022
4a9d718
MockMVC 테스트 Context단계 수정
jdalma Aug 18, 2022
b86f1b5
clearTasks 메소드 id도 초기화하게 수정
jdalma Aug 18, 2022
8138d60
TaskServiceTest 테스트 코드 추가
jdalma Aug 18, 2022
f4ae790
Task 모델 유닛 테스트 추가
jdalma Aug 18, 2022
067bf9b
mock MVC 테스트 준비 단계 수정
jdalma Aug 19, 2022
a8f92e7
TaskController mock을 사용하지 않은 MVC 테스트 코드 추가
jdalma Aug 19, 2022
c12316e
Update app/src/test/java/com/codesoom/assignment/controllers/TaskCont…
jdalma Aug 21, 2022
ad0b279
Context를 Describe로 수정
jdalma Aug 21, 2022
28f14e5
verify 추가
jdalma Aug 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ Thumbs.db
Thumbs.db:encryptable
ehthumbs.db
ehthumbs_vista.db
/app/out/
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ public Task deleteTask(Long id) {
return task;
}

public void clearTasks(){
newId = 0L;
tasks = new ArrayList<>();
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ArrayList를 사용하게 된 김에 DynamicArray 자료구조에 대해 학습해보는 것도 좋을 것 같습니다.

}

private Long generateId() {
newId += 1;
return newId;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,17 @@
import com.codesoom.assignment.application.TaskService;
import com.codesoom.assignment.models.Task;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

Expand Down
34 changes: 34 additions & 0 deletions app/src/main/java/com/codesoom/assignment/models/Task.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,20 @@
package com.codesoom.assignment.models;

import java.util.Objects;

public class Task {
private Long id;

private String title;

public Task() {
}

public Task(Long id, String title) {
this.id = id;
this.title = title;
}

public Long getId() {
return id;
}
Expand All @@ -20,4 +30,28 @@ public String getTitle() {
public void setTitle(String title) {
this.title = title;
}

@Override
public boolean equals(Object o) {
if (this == o)
return true;
if (o == null || this.getClass() != o.getClass())
return false;
Task task = (Task) o;
return Objects.equals(this.id, task.getId()) && this.title.equals(task.getTitle());
}
Comment on lines +35 to +42
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

좋습니다! 다만 if 문은 한 줄짜리라도 꼭 중괄호를 생략하지 않는 습관을 들이는 것이 좋습니다. 비싸지 않으면서도 치명적인 실수를 방어해주는 좋은 습관이죠.

이와 관련된 유명하고 재미있는 버그 이야기가 있습니다. Apple의 SSL/TLS 프로토콜에서 발견된 끔찍한 실수입니다. if 중괄호가 습관화되어 있었다면 하지 않았을 실수죠.
https://embeddedgurus.com/barr-code/2014/03/apples-gotofail-ssl-security-bug-was-easily-preventable/

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

이런 일이 있었군요 ㅎㅎ 감사합니다 !!
수정하겠습니다


@Override
public int hashCode() {
return Objects.hash(id, title);
}

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("Task{");
sb.append("id=").append(id);
sb.append(", title='").append(title).append('\'');
sb.append('}');
return sb.toString();
Comment on lines +51 to +55
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

String.format을 사용해서 표현하는 건 어떨까요? 다음과 같이 표현할 수 있을거에요

return String.format("{ id = %s, title = %s }", id, title);

더 좋은건 Template literal이지만 자바에서는 지원하질 않네요 ㅠ 만약 이런게 지원하는 코틀린을 사용했다면 다음과 같이 사용할 수 있을거에요

return "{ id = $id, title = $title }"

}
}