반응형
Recent Posts
Recent Comments
관리 메뉴

개발잡부

[test] keywords Service TEST Code 본문

JAVA/test code

[test] keywords Service TEST Code

닉의네임 2022. 4. 23. 17:33
반응형
package com.bbongdoo.doo.keyword;

import com.bbongdoo.doo.domain.Keywords;
import com.bbongdoo.doo.domain.KeywordsRepository;
import com.bbongdoo.doo.service.KeywordsService;
import org.assertj.core.api.Assertions;
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.transaction.annotation.Transactional;

import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

@SpringBootTest
@Transactional
public class KeywordServiceTest {

    @Autowired
    private KeywordsService keywordsService;

    @Autowired
    private KeywordsRepository keywordsRepository;

    private int count = 10;
    List<Keywords> keywords;
    List<String> names;

    @BeforeEach
    void setUp() {
        keywords = LongStream.range(1, count + 1)
                .mapToObj(number -> new Keywords("에르디아" + number, "Y"))
                .collect(Collectors.toList());
        names = keywords.stream()
                .map(Keywords::getKeyword)
                .collect(Collectors.toList());

        System.out.println("---------------insert---------------");
        keywordsRepository.saveAll(keywords);
    }

    @Test
    void findAllTest() {
        System.out.println("---------------findAll---------------");
        List<Keywords> keywords = keywordsService.get();

        Assertions.assertThat(keywords.size()).isEqualTo(count);
    }

    @Test
    void findAllByUseTest() {
        System.out.println("---------------findAllByUse---------------");
        List<Keywords> keywordsByUse = keywordsService.getKeywordsByUse("Y");
        Assertions.assertThat(keywordsByUse.size()).isEqualTo(count);
    }

    @Test
    void findAllByKeywordTest() {
        System.out.println("---------------findAllByKeyword---------------");
        List<Keywords> keywordsByKeyword = keywordsService.getKeywordsByKeyword("에르디아1");
        Assertions.assertThat(keywordsByKeyword.size()).isGreaterThan(0);
    }

}
반응형

'JAVA > test code' 카테고리의 다른 글

[TEST]ReflectionTestUtils  (0) 2023.03.14
Comments