Jean-Francois Leveque

Couverture supposée suffisante de ListPublisherActionsView.

package org.legrog.web.publisher;
import org.junit.Before;
import org.junit.Test;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Nested;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.platform.runner.JUnitPlatform;
import org.junit.runner.RunWith;
import org.legrog.entities.Publisher;
import org.legrog.entities.PublisherAction;
import org.legrog.test.MockitoExtension;
import org.mockito.Mock;
import org.mockito.Mockito;
import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Classe testant ListPublisherActionsView.
*/
@RunWith(JUnitPlatform.class)
@ExtendWith(MockitoExtension.class)
@DisplayName("Visualisation d'actions sur éditeur")
public class ListPublisherActionsViewTest {
ListPublisherActionsView listPublisherActionsView;
@Nested
@DisplayName("setView method")
public class testSetView {
boolean filtered;
@BeforeEach
public void setUp(@Mock PublisherService publisherServiceMock){
filtered = false;
listPublisherActionsView = new ListPublisherActionsView(publisherServiceMock) {
@Override
public void filterOnID() {
filtered = true;
}
};
}
@Test
@DisplayName("should show all")
public void showAll(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(null);
listPublisherActionsView.setViewAll(false);
listPublisherActionsView.setView();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isTrue();
assertThat(filtered).isFalse();
}
@Test
@DisplayName("should show filtered")
public void showFiltered(@Mock PublisherService publisherServiceMock) {
listPublisherActionsView.setPublisherId(1);
listPublisherActionsView.setViewAll(true);
listPublisherActionsView.setView();
Mockito.verify(publisherServiceMock).getAllPublisherActions();
assertThat(listPublisherActionsView.isViewAll()).isFalse();
assertThat(filtered).isTrue();
}
}
@Test
@DisplayName("filterId should filter")
public void testFilter(@Mock PublisherService publisherServiceMock) {
List<PublisherAction> publisherActions = new ArrayList<PublisherAction>();
Publisher publisher = new Publisher();
Publisher publisher1 = new Publisher();
PublisherAction publisherAction = new PublisherAction();
PublisherAction publisherAction1 = new PublisherAction();
publisher.setPublisherId(0);
publisher1.setPublisherId(1);
publisherAction.setPublisher(publisher);
publisherAction1.setPublisher(publisher1);
publisherActions.add(publisherAction);
publisherActions.add(publisherAction1);
listPublisherActionsView = new ListPublisherActionsView();
listPublisherActionsView.setPublisherActions(publisherActions);
listPublisherActionsView.setPublisherId(1);
listPublisherActionsView.filterOnID();
assertThat(listPublisherActionsView.getPublisherActions()).containsExactly(publisherAction1);
}
}