Skip to content

Commit

Permalink
feat: MemberRepository Test 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
baebae02 committed Apr 8, 2024
1 parent c1795eb commit d7bc228
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
8 changes: 6 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,12 @@ dependencies {
// implementation "org.flywaydb:flyway-core"
// implementation "org.springframework.boot:spring-boot-starter"

// lombok

// testcontainers
testImplementation "org.testcontainers:testcontainers:1.17.2"
testImplementation "org.testcontainers:junit-jupiter:1.17.2"
testImplementation "org.testcontainers:postgresql:1.17.6"


}

tasks.named('test') {
Expand Down
9 changes: 5 additions & 4 deletions src/test/java/com/uspray/uspray/UsprayApplicationTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.context.SpringBootTest;

//@SpringBootTest
@SpringBootTest
//@Testcontainers
class UsprayApplicationTests {

@Test
void contextLoads() {
}
@Test
void contextLoads() {
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.uspray.uspray.repository;

import static org.assertj.core.api.Assertions.assertThat;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

public class MemberRepositoryTest extends RepositoryTest {

@Test
@DisplayName("회원 아이디로 조회 시 존재하지 않는 아이디일 경우 예외를 던진다.")
void existsByUserId() {
// Given
String userId = "leesunshin";
String notExistUserId = "unknown";

// When
boolean existsByUserId = memberRepository.existsByUserId(userId);
boolean notExistsByUserId = memberRepository.existsByUserId(notExistUserId);

// Then
assertThat(existsByUserId).isTrue();
assertThat(notExistsByUserId).isFalse();
}

}
32 changes: 32 additions & 0 deletions src/test/java/com/uspray/uspray/repository/RepositoryTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.uspray.uspray.repository;

import com.uspray.uspray.domain.Member;
import com.uspray.uspray.infrastructure.CategoryRepository;
import com.uspray.uspray.infrastructure.MemberRepository;
import org.junit.jupiter.api.BeforeEach;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.transaction.annotation.Transactional;

//@DataJpaTest
@Transactional
@SpringBootTest
public abstract class RepositoryTest {

@Autowired
protected MemberRepository memberRepository;

@Autowired
protected CategoryRepository categoryRepository;

@BeforeEach
void userSetup() {
Member member = memberRepository.save(Member.builder()
.userId("leesunshin")
.password("test")
.name("이순신")
.phone("01011111111")
.build());
}

}

0 comments on commit d7bc228

Please sign in to comment.