-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a437869
commit d31fcf6
Showing
4 changed files
with
127 additions
and
33 deletions.
There are no files selected for viewing
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
28 changes: 0 additions & 28 deletions
28
토비의 스프링/vol1/src/main/java/tobyspring/vol1/chapter_1/user/dao/UserDaoTest.java
This file was deleted.
Oops, something went wrong.
8 changes: 8 additions & 0 deletions
8
토비의 스프링/vol1/src/main/java/tobyspring/vol1/chapter_1/user/domain/User.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 |
---|---|---|
@@ -1,12 +1,20 @@ | ||
package tobyspring.vol1.chapter_1.user.domain; | ||
|
||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.Setter; | ||
|
||
@Getter | ||
@Setter | ||
@NoArgsConstructor | ||
public class User { | ||
private String id; | ||
private String name; | ||
private String password; | ||
|
||
public User(String id, String name, String password) { | ||
this.id = id; | ||
this.name = name; | ||
this.password = password; | ||
} | ||
} |
82 changes: 82 additions & 0 deletions
82
토비의 스프링/vol1/src/test/java/tobyspring/vol1/chapter_2/UserDaoTest.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,82 @@ | ||
package tobyspring.vol1.chapter_2; | ||
|
||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.context.annotation.AnnotationConfigApplicationContext; | ||
import org.springframework.dao.EmptyResultDataAccessException; | ||
import tobyspring.vol1.chapter_1.user.dao.DaoFactory; | ||
import tobyspring.vol1.chapter_1.user.dao.UserDao; | ||
import tobyspring.vol1.chapter_1.user.domain.User; | ||
|
||
import java.sql.SQLException; | ||
|
||
import static org.assertj.core.api.Assertions.*; | ||
|
||
@SpringBootTest | ||
public class UserDaoTest { | ||
|
||
@Autowired | ||
ApplicationContext ac; | ||
|
||
UserDao userDao; | ||
User user; | ||
User user1; | ||
User user2; | ||
|
||
@BeforeEach | ||
void beforeEach() throws SQLException { | ||
userDao = ac.getBean(UserDao.class); | ||
userDao.deleteAll(); | ||
user = new User("id1", "subin", "1234"); | ||
user1 = new User("id2", "yebin", "2234"); | ||
user2 = new User("id3", "bean", "3234"); | ||
|
||
System.out.println("ac = " + ac); //동일한 주소가 출력됨. | ||
System.out.println("this = " + this); //다른 주소가 출력됨. 테스므 메서드 마다 테스트 클래스 인스턴스를 만들어 실행하기 때문이다. | ||
} | ||
|
||
|
||
@Test | ||
void count() throws SQLException, ClassNotFoundException { | ||
|
||
userDao.add(user); | ||
assertThat(userDao.getCount()).isEqualTo(1); | ||
|
||
userDao.add(user1); | ||
assertThat(userDao.getCount()).isEqualTo(2); | ||
|
||
userDao.add(user2); | ||
assertThat(userDao.getCount()).isEqualTo(3); | ||
} | ||
|
||
|
||
@Test | ||
void addAndGet() throws SQLException, ClassNotFoundException { | ||
|
||
userDao.add(user); | ||
userDao.add(user1); | ||
|
||
assertThat(userDao.getCount()).isEqualTo(2); | ||
|
||
User getUser = userDao.get("id1"); | ||
|
||
assertThat(getUser.getName()).isEqualTo("subin"); | ||
assertThat(getUser.getPassword()).isEqualTo("1234"); | ||
|
||
User getUser2 = userDao.get("id2"); | ||
|
||
assertThat(getUser2.getName()).isEqualTo("yebin"); | ||
assertThat(getUser2.getPassword()).isEqualTo("2234"); | ||
|
||
} | ||
|
||
@Test | ||
void getUserFailure(){ | ||
assertThatThrownBy(()->{ | ||
userDao.get("hello"); | ||
}).isInstanceOf(EmptyResultDataAccessException.class); | ||
} | ||
} |