Blame view

grog-webapp/src/test/java/org/legrog/web/xyz/ReindexViewTest.java 2.31 KB
1 2
package org.legrog.web.xyz;

3 4 5 6 7 8 9
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
10
import org.legrog.entities.IndexingException;
11 12 13 14 15 16 17 18 19
import org.legrog.test.MockitoExtension;
import org.legrog.web.account.AccountService;
import org.legrog.web.publisher.PublisherService;
import org.mockito.Mock;
import org.mockito.Mockito;

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

20 21 22
/**
 * Classe testing ReindexView
 */
23 24 25
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Reindexes data")
26
public class ReindexViewTest {
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43
    private ReindexView reindexView;
    private PublisherService publisherService;
    private AccountService accountService;

    @BeforeEach
    public void setUp(@Mock PublisherService publisherService, @Mock AccountService accountService) {
        this.publisherService = publisherService;
        this.accountService = accountService;
        this.reindexView = new ReindexView(publisherService, accountService);
    }

    @Nested
    @DisplayName("reindexAll method")
    class ReindexAllTests {

        @DisplayName("when called, should call for reindexing of publishers and accounts")
        @Test
44
        public void reindexAllTest(@Mock PublisherService publisherService, @Mock AccountService accountService) throws IndexingException {
45 46 47 48 49 50 51
            reindexView.reindexAll();
            Mockito.verify(publisherService).reindexAllPublishers();
            Mockito.verify(accountService).reindexAllAccounts();
        }

        @DisplayName("when called, should set its indexed numbers to values returned by reindexers")
        @Test
52
        public void setReturnIntegers(@Mock PublisherService publisherService, @Mock AccountService accountService) throws IndexingException {
53 54 55 56 57 58 59 60 61 62
            when(publisherService.reindexAllPublishers()).thenReturn(1);
            when(accountService.reindexAllAccounts()).thenReturn(2);
            reindexView.reindexAll();
            assertThat(reindexView.getIndexedPublishersNumber()).isEqualTo(1);
            assertThat(reindexView.getIndexedAccountsNumber()).isEqualTo(2);
        }

    }


63
}