Skip to content

Commit

Permalink
#53 test: canSupportRoundType 메소드 테스트
Browse files Browse the repository at this point in the history
  • Loading branch information
dbwp031 committed Oct 16, 2023
1 parent 8e90070 commit 74880c2
Showing 1 changed file with 47 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,32 @@
import com.example.ourworldcup.aws.s3.FileService;
import com.example.ourworldcup.controller.worldcup.dto.WorldcupRequestDto;
import com.example.ourworldcup.domain.Worldcup;
import com.example.ourworldcup.domain.constant.RoundType;
import com.example.ourworldcup.domain.userAccount.UserAccount;
import com.example.ourworldcup.fixtures.WorldcupFixtures;
import com.example.ourworldcup.repository.WorldcupRepository;
import com.example.ourworldcup.service.worldcup.WorldcupServiceImpl;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import java.util.stream.Stream;

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

@DisplayName("비즈니스 로직 - Worldcup")
@ExtendWith(MockitoExtension.class)
class WorldcupServiceImplTest {
@InjectMocks private WorldcupServiceImpl sut; // system under test
@Mock private WorldcupRepository worldcupRepository;
@InjectMocks
private WorldcupServiceImpl sut; // system under test
@Mock
private WorldcupRepository worldcupRepository;
@Mock
private FileService fileService;

Expand Down Expand Up @@ -49,4 +58,40 @@ void givenWorldcupCreateRequestDto_whenCreateWorldcup_thenReturnCorrectlyCreated
.hasFieldOrPropertyWithValue("content", content)
.hasFieldOrPropertyWithValue("password", password);
}

// @DisplayName("월드컵과 라운드 타입을 제공하면, 해당 라운드 타입이 월드컵에서 지원가능한지 참/거짓 값을 반환한다.")
// @Test
// void givenWorldcupAndRoundType_whenCheckRoundType_thenReturnBooleanWhetherWorldcupSupportsRoundType() {
// // Given
//
// // When
//
// // Then
// }
@DisplayName("월드컵 아이템 개수에 따라, round type이 가능한지에 대한 참/거짓 값을 반환한다.")
@MethodSource
@ParameterizedTest(name = "[{index}] item count: {0}, round type: {1} => {2} ")
void validRoundType_basedOnNumberOfWorldcupItems(Long itemCount, RoundType roundType, Boolean expected) {
// given
Worldcup worldcup = WorldcupFixtures.createDefaultWorldcupWithItemsOf(itemCount);

// when
Boolean canSupport = sut.canSupportRoundType(worldcup, roundType);

// then
assertThat(canSupport).isEqualTo(expected);
}

static Stream<Arguments> validRoundType_basedOnNumberOfWorldcupItems() {
return Stream.of(
Arguments.arguments(0L, RoundType.ROUND2, false),
Arguments.arguments(1L, RoundType.ROUND2, false),
Arguments.arguments(2L, RoundType.ROUND2, true),
Arguments.arguments(2L, RoundType.ROUND4, false),
Arguments.arguments(3L, RoundType.ROUND4, false),
Arguments.arguments(7L, RoundType.ROUND4, true),
Arguments.arguments(7L, RoundType.ROUND8, false),
Arguments.arguments(8L, RoundType.ROUND8, true)
);
}
}

0 comments on commit 74880c2

Please sign in to comment.