Skip to content

Commit

Permalink
test: added vocabulary service tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Dankoy committed Oct 4, 2023
1 parent 42e5b8c commit 21be336
Showing 1 changed file with 103 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
package ru.dankoy.korvotoanki.core.service.vocabulary;

import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.times;

import java.util.List;
import java.util.stream.Stream;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import ru.dankoy.korvotoanki.core.dao.vocabulary.VocabularyDao;
import ru.dankoy.korvotoanki.core.dao.vocabulary.VocabularyDaoJdbc;
import ru.dankoy.korvotoanki.core.domain.Title;
import ru.dankoy.korvotoanki.core.domain.Vocabulary;


@DisplayName("Test TitleServiceJdbc ")
@SpringBootTest(classes = {VocabularyServiceJdbc.class, VocabularyDaoJdbc.class})
class VocabularyServiceJdbcTest {

@MockBean
private VocabularyDao vocabularyDao;

@Autowired
private VocabularyService vocabularyService;


@DisplayName("getAll not empty")
@Test
void getAll() {

List<Vocabulary> correct = correctVocabularies();

given(vocabularyDao.getAll()).willReturn(correct);

var actual = vocabularyService.getAll();

assertThat(actual).isNotEmpty().hasSize(correct.size()).isEqualTo(correct);

Mockito.verify(vocabularyDao, times(1)).getAll();

}


@DisplayName("getByTitle not empty")
@Test
void getByTitle() {

var title = new Title(0L, "title", 1L);

List<Vocabulary> correct = correctVocabularies();

given(vocabularyDao.getByTitle(title)).willReturn(correct);

var actual = vocabularyService.getByTitle(title);

assertThat(actual).isNotEmpty().hasSize(correct.size()).isEqualTo(correct);

Mockito.verify(vocabularyDao, times(1)).getByTitle(title);

}


@DisplayName("count non zero")
@Test
void count() {

List<Vocabulary> correct = correctVocabularies();

given(vocabularyDao.count()).willReturn((long) correct.size());

var actual = vocabularyService.count();

assertThat(actual).isEqualTo(correct.size());

Mockito.verify(vocabularyDao, times(1)).count();


}


private List<Vocabulary> correctVocabularies() {

var title = new Title(1L, "Title1", 1L);

return Stream.of(
new Vocabulary("contemplating", title, 1695239837, 1695239837, 1695240137, 0,
"combined forces.” He hoped to the gods it didn’t come to that.\n"
+ "She fell silent, ",
" a gratifying slaughter. Maybe even the final battle that would confirm her mastery. Most of all",
0),
new Vocabulary("word", title, 1695239837, 1695239837, 1695240137, 0,
null,
null,
0)
).toList();

}
}

0 comments on commit 21be336

Please sign in to comment.