Skip to content

Commit

Permalink
[TEST] Maker List 조회 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
Chan531 committed Jul 22, 2024
1 parent b2b2c40 commit a6d7540
Show file tree
Hide file tree
Showing 3 changed files with 143 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/main/java/com/soptie/server/maker/entity/Maker.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,14 @@
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Entity
@Getter
@NoArgsConstructor(access = PROTECTED)
@AllArgsConstructor
public class Maker {

@Id
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package com.soptie.server.maker.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.doReturn;

import java.util.List;

import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import com.soptie.server.maker.adapter.MakerFinder;
import com.soptie.server.maker.entity.Maker;
import com.soptie.server.maker.service.dto.MakerListAcquireServiceResponse;
import com.soptie.server.support.fixture.MakerFixture;

@ExtendWith(MockitoExtension.class)
class MakerServiceTest {

@InjectMocks
private MakerService makerService;

@Mock
private MakerFinder makerFinder;

@Test
@DisplayName("[성공] 모든 메이커 테마를 조회한다.")
void acquireAllTheme() {
// given
long makerId1 = 1L;
long makerId2 = 2L;
long themeId1 = 1L;
long themeId2 = 2L;
String name = "maker";
String job = "job";
String profileImageUrl = "profileImageUrl";
String description = "description";
String content = "content";
List<String> tags = List.of("#tag1", "#tag2", "#tag3");
Maker maker1 = MakerFixture.maker()
.id(makerId1)
.name(name)
.job(job)
.profileImageUrl(profileImageUrl)
.description(description)
.content(content)
.themeId(themeId1)
.tags(tags)
.build();

Maker maker2 = MakerFixture.maker()
.id(makerId2)
.name(name)
.job(job)
.profileImageUrl(profileImageUrl)
.description(description)
.content(content)
.themeId(themeId2)
.tags(tags)
.build();

doReturn(List.of(maker1, maker2)).when(makerFinder).findAll();

// when
MakerListAcquireServiceResponse result = makerService.acquireAll();

// then
assertThat(result.makers().size()).isEqualTo(2);
}
}
68 changes: 68 additions & 0 deletions src/test/java/com/soptie/server/support/fixture/MakerFixture.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.soptie.server.support.fixture;

import java.util.List;

import com.soptie.server.maker.entity.Maker;

public class MakerFixture {

private Long id;
private String name;
private String job;
private String profileImageUrl;
private String description;
private String content;
private Long themeId;
private List<String> tags;

private MakerFixture() {
}

public static MakerFixture maker() {
return new MakerFixture();
}

public MakerFixture id(Long id) {
this.id = id;
return this;
}

public MakerFixture name(String name) {
this.name = name;
return this;
}

public MakerFixture job(String job) {
this.job = job;
return this;
}

public MakerFixture profileImageUrl(String profileImageUrl) {
this.profileImageUrl = profileImageUrl;
return this;
}

public MakerFixture description(String description) {
this.description = description;
return this;
}

public MakerFixture content(String content) {
this.content = content;
return this;
}

public MakerFixture themeId(Long themeId) {
this.themeId = themeId;
return this;
}

public MakerFixture tags(List<String> tags) {
this.tags = tags;
return this;
}

public Maker build() {
return new Maker(id, name, job, profileImageUrl, description, content, themeId, tags);
}
}

0 comments on commit a6d7540

Please sign in to comment.