summaryrefslogtreecommitdiff
path: root/src/test/java/dev/dnpm/ConsentManagerTest.java
blob: 96d21e5a73ab77b02e9f684a6533f2cadce9f763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package dev.dnpm;

import dev.dnpm.analyzer.ConsentManager;
import dev.dnpm.services.consent.ConsentManagerServiceFactory;
import dev.dnpm.services.consent.MrConsentManagerService;
import de.itc.onkostar.api.IOnkostarApi;
import de.itc.onkostar.api.Procedure;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.*;

@ExtendWith(MockitoExtension.class)
class ConsentManagerTest {

    private IOnkostarApi onkostarApi;

    private ConsentManagerServiceFactory consentManagerServiceFactory;

    private ConsentManager consentManager;

    @BeforeEach
    void setup(
            @Mock IOnkostarApi onkostarApi,
            @Mock ConsentManagerServiceFactory consentManagerServiceFactory
    ) {
        this.onkostarApi = onkostarApi;
        this.consentManagerServiceFactory = consentManagerServiceFactory;
        this.consentManager = new ConsentManager(onkostarApi, consentManagerServiceFactory);
    }

    @Test
    void shouldRunServiceMethodsOnAnalyzeCalled() {
        var consentManagerServiceMock = mock(MrConsentManagerService.class);

        when(consentManagerServiceMock.canApply(any(Procedure.class))).thenReturn(true);

        when(this.consentManagerServiceFactory.currentUsableInstance())
                .thenReturn(consentManagerServiceMock);

        this.consentManager.analyze(new Procedure(onkostarApi), null);

        verify(consentManagerServiceMock, times(1)).applyConsent(any(Procedure.class));
    }

    @Test
    void shouldNotRunServiceMethodsIfProcedureCannotBeAppliesForForm() {
        var consentManagerServiceMock = mock(MrConsentManagerService.class);

        when(consentManagerServiceMock.canApply(any(Procedure.class))).thenReturn(false);

        when(this.consentManagerServiceFactory.currentUsableInstance())
                .thenReturn(consentManagerServiceMock);

        this.consentManager.analyze(new Procedure(onkostarApi), null);

        verify(consentManagerServiceMock, times(0)).applyConsent(any(Procedure.class));
    }

}