-
Notifications
You must be signed in to change notification settings - Fork 13
최예린 1주차 과제 #8
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
cyerinn
wants to merge
1
commit into
doit-web-study:main
Choose a base branch
from
cyerinn: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주차 과제 #8
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
|
||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@Getter | ||
public class PrizeWinner { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
private Long id; | ||
|
||
private String item; | ||
|
||
private String name; | ||
|
||
private String email; | ||
|
||
@Builder | ||
public PrizeWinner(String item, String name, String email) { | ||
this.item = item; | ||
this.name = name; | ||
this.email = email; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/java/doit/jpastudy2/repository/PrizeWinnerRepository.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,8 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PrizeWinnerRepository extends JpaRepository<PrizeWinner, Long> { | ||
|
||
PrizeWinner findByNameAndItem(String name, String item); | ||
} |
91 changes: 91 additions & 0 deletions
91
src/test/java/doit/jpastudy2/repository/PrizeWinnerRepositoryTest.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,91 @@ | ||
package doit.jpastudy2.repository; | ||
|
||
import jakarta.transaction.Transactional; | ||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
|
||
import java.util.List; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
@Transactional | ||
@SpringBootTest | ||
class PrizeWinnerRepositoryTest { | ||
|
||
@Autowired | ||
private PrizeWinnerRepository prizeWinnerRepository; | ||
|
||
@Test | ||
void saveTest(){ | ||
PrizeWinner prizeWinner1 = PrizeWinner.builder() | ||
.item("100만원") | ||
.name("홍길동") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner2 = PrizeWinner.builder() | ||
.item("50만원") | ||
.name("김머머") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner3 = PrizeWinner.builder() | ||
.item("30만원") | ||
.name("박사무엘") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner4 = PrizeWinner.builder() | ||
.item("10만원") | ||
.name("고길동") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
prizeWinnerRepository.save(prizeWinner1); | ||
prizeWinnerRepository.save(prizeWinner2); | ||
prizeWinnerRepository.save(prizeWinner3); | ||
prizeWinnerRepository.save(prizeWinner4); | ||
|
||
List<PrizeWinner> all = prizeWinnerRepository.findAll(); | ||
Assertions.assertThat(all.get(0).getItem()).isEqualTo("100만원"); | ||
Assertions.assertThat(all.get(2).getName()).isEqualTo("박사무엘"); | ||
} | ||
|
||
@Test | ||
void findByNameAndItem(){ | ||
|
||
PrizeWinner prizeWinner1 = PrizeWinner.builder() | ||
.item("100만원") | ||
.name("홍길동") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner2 = PrizeWinner.builder() | ||
.item("50만원") | ||
.name("김머머") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner3 = PrizeWinner.builder() | ||
.item("30만원") | ||
.name("박사무엘") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
PrizeWinner prizeWinner4 = PrizeWinner.builder() | ||
.item("10만원") | ||
.name("고길동") | ||
.email("[email protected]") | ||
.build(); | ||
|
||
prizeWinnerRepository.saveAll(List.of(prizeWinner1, prizeWinner2, prizeWinner3, prizeWinner4)); | ||
|
||
PrizeWinner findWinner1 = prizeWinnerRepository.findByNameAndItem("고길동","10만원"); | ||
PrizeWinner findWinner2 = prizeWinnerRepository.findByNameAndItem("김머머","50만원"); | ||
|
||
Assertions.assertThat(findWinner1.getName()).isEqualTo("고길동"); | ||
Assertions.assertThat(findWinner2.getEmail()).isEqualTo("[email protected]"); | ||
} | ||
} |
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.
깔끔하게 잘 해내신 것 같습니다.
아래처럼 존재하지 않는 경우도 테스트케이스에 넣으면 좋을것 같습니다.
수고하셨습니다!!