-
Notifications
You must be signed in to change notification settings - Fork 13
민경준 1주차 과제 #3
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
Open
nihaojohn0609
wants to merge
1
commit into
doit-web-study:main
Choose a base branch
from
nihaojohn0609:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
민경준 1주차 과제 #3
Changes from all commits
Commits
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
This file contains hidden or 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 hidden or 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 hidden or 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 doit.jpastudy2.repository; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class Personal { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "age") | ||
private int age; | ||
|
||
@Column(name = "address") | ||
private String address; | ||
|
||
@Column(name = "employee_id") | ||
private Long id; | ||
|
||
@Column(name = "salary") | ||
private int salary; | ||
} |
108 changes: 0 additions & 108 deletions
108
src/test/java/doit/jpastudy2/repository/CategoryRepositoryTest.java
This file was deleted.
Oops, something went wrong.
107 changes: 107 additions & 0 deletions
107
src/test/java/doit/jpastudy2/repository/EmployeeRepositoryTest.java
This file contains hidden or 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,107 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.DisplayName; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import java.util.List; | ||
|
||
@Transactional // 테스트 케이스에 이 어노테이션이 있으면, 테스트가 끝나면 롤백을 해준다. ( 데이터베이스 초기화 ) | ||
@SpringBootTest // 스프링 컨테이너를 이용한 테스트 | ||
class EmployeeRepositoryTest { | ||
|
||
@Autowired // 스프링이 관리하는 빈을 주입받는다. | ||
private EmployeeRepository employeeRepository; | ||
|
||
@DisplayName("save 테스트") | ||
@Test | ||
void test() { | ||
// Given | ||
Employee employee1 = Employee.builder() | ||
.firstName("민") | ||
.lastName("경준") | ||
.build(); | ||
|
||
Employee employee2 = Employee.builder() | ||
.firstName("김") | ||
.lastName("주성") | ||
.build(); | ||
|
||
// When | ||
employeeRepository.save(employee1); | ||
employeeRepository.save(employee2); | ||
|
||
// Then | ||
List<Employee> categories = employeeRepository.findAll(); | ||
Assertions.assertThat(categories).hasSize(2); | ||
Assertions.assertThat(categories.get(0).getFirstName()).isEqualTo("김"); | ||
Assertions.assertThat(categories.get(0).getLastName()).isEqualTo("주성"); | ||
} | ||
|
||
@DisplayName("firstName을 이용한 조회") | ||
@Test | ||
void findByDescription() { | ||
// Given | ||
Employee employee1 = Employee.builder() | ||
.firstName("민") | ||
.lastName("경준") | ||
.build(); | ||
|
||
Employee employee2 = Employee.builder() | ||
.firstName("김") | ||
.lastName("주성") | ||
.build(); | ||
|
||
employeeRepository.save(employee1); | ||
employeeRepository.save(employee2); | ||
|
||
// When | ||
Employee result1 = employeeRepository.findByFirstName("민"); | ||
Employee result2 = employeeRepository.findByFirstName("김"); | ||
|
||
// Then | ||
Assertions.assertThat(result1).isNull(); | ||
Assertions.assertThat(result2).isNotNull(); | ||
Assertions.assertThat(result2.getFirstName()).isEqualTo("김"); | ||
} | ||
|
||
@DisplayName("firstName과 lastName을 이용한 조회") | ||
@Test | ||
void findByTypeAndDescription() { | ||
// Given | ||
Employee employee1 = Employee.builder() | ||
.firstName("민") | ||
.lastName("경준") | ||
.build(); | ||
|
||
Employee employee2 = Employee.builder() | ||
.firstName("김") | ||
.lastName("주성") | ||
.build(); | ||
|
||
Employee employee3 = Employee.builder() | ||
.firstName("강") | ||
.lastName("범서") | ||
.build(); | ||
|
||
Employee employee4 = Employee.builder() | ||
.firstName("조") | ||
.lastName("상래") | ||
.build(); | ||
|
||
employeeRepository.saveAll(List.of(employee1, employee2, employee3, employee4)); | ||
|
||
// When | ||
Employee result1 = employeeRepository.findAllByFirstNameAndLastName("민", "경준"); | ||
Employee result2 = employeeRepository.findAllByFirstNameAndLastName("강", "범서"); // null | ||
Employee result3 = employeeRepository.findAllByFirstNameAndLastName("조", "상래"); | ||
|
||
// Then | ||
Assertions.assertThat(result1.getFirstName()).isEqualTo("민"); | ||
Assertions.assertThat(result2).isNull(); | ||
Assertions.assertThat(result3.getLastName()).isEqualTo("범서"); | ||
Comment on lines
+103
to
+105
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertj 메소드 사용해서 점검해주신 부분 너무 좋습니다! |
||
} | ||
} |
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.
여기 빌더 안에 email 필드가 빠진 이유가 궁금합니다!
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.
Email 필드 누락인 것 같습니다. 오류 지적 감사합니다!