Jean-Francois Leveque

Premiers tests de PublisherServiceSpring.

1 +package org.legrog.web.publisher;
2 +
3 +import org.junit.Test;
4 +import org.junit.jupiter.api.BeforeEach;
5 +import org.junit.jupiter.api.DisplayName;
6 +import org.junit.jupiter.api.extension.ExtendWith;
7 +import org.junit.platform.runner.JUnitPlatform;
8 +import org.junit.runner.RunWith;
9 +import org.legrog.entities.Publisher;
10 +import org.legrog.entities.PublisherRepository;
11 +import org.legrog.entities.PublisherVersion;
12 +import org.legrog.entities.PublisherVersionRepository;
13 +import org.legrog.test.MockitoExtension;
14 +import org.legrog.web.xyz.SharedService;
15 +import org.mockito.Mock;
16 +
17 +import static org.assertj.core.api.Assertions.assertThat;
18 +import static org.mockito.Mockito.*;
19 +
20 +/**
21 + * Classe testant PublisherServiceSpring.
22 + */
23 +@RunWith(JUnitPlatform.class)
24 +@ExtendWith(MockitoExtension.class)
25 +@DisplayName("Couche service de gestion d'éditeur")
26 +public class PublisherServiceSpringTest {
27 +
28 + PublisherServiceSpring publisherServiceSpring;
29 + PublisherVersion publisherVersion;
30 + PublisherVersion publisherVersion1;
31 + Publisher publisher;
32 + PublisherRepository publisherRepository;
33 + PublisherVersionRepository publisherVersionRepository;
34 +
35 + @BeforeEach
36 + public void setUp(@Mock PublisherRepository publisherRepository,
37 + @Mock PublisherVersionRepository publisherVersionRepository,
38 + @Mock SharedService sharedService) throws Exception {
39 + publisherServiceSpring = new PublisherServiceSpring(publisherRepository,
40 + publisherVersionRepository, sharedService);
41 + publisherVersion = new PublisherVersion();
42 + publisherVersion1 = new PublisherVersion();
43 + this.publisherRepository = publisherRepository;
44 + }
45 +
46 + @DisplayName("Test ajout nouvel éditeur")
47 + @Test
48 + public void testAddNewPublisher() {
49 + publisherServiceSpring.addNewPublisher(publisherVersion);
50 + publisher = publisherVersion.getPublisher();
51 + assertThat(publisher.getVersions()).containsExactly(publisherVersion);
52 + assertThat(publisherVersion.getPublisher()).isEqualTo(publisher);
53 + verify(publisherRepository).save(publisher);
54 + verify(publisherVersionRepository).save(publisherVersion);
55 + }
56 +
57 + @DisplayName("Test ajout nouvelle version éditeur")
58 + @Test
59 + public void testAddVersionToPublisher() {
60 + publisherServiceSpring.addNewPublisher(publisherVersion);
61 + publisher = publisherVersion.getPublisher();
62 + publisherServiceSpring.addVersionToPublisher(publisher, publisherVersion1);
63 + assertThat(publisherVersion1.getPublisher()).isEqualTo(publisher);
64 + assertThat(publisher.getVersions()).contains(publisherVersion, publisherVersion1);
65 + verify(publisherRepository).save(publisher);
66 + verify(publisherVersionRepository).save(publisherVersion1);
67 + }
68 +}