1
+ package org .orcid .core .manager .v3 ;
2
+
3
+ import org .junit .Before ;
4
+ import org .junit .Test ;
5
+ import org .mockito .Mock ;
6
+ import org .mockito .MockitoAnnotations ;
7
+ import org .orcid .core .manager .v3 .impl .ProfileInterstitialFlagManagerImpl ;
8
+ import org .orcid .persistence .dao .ProfileInterstitialFlagDao ;
9
+ import org .orcid .persistence .jpa .entities .ProfileInterstitialFlagEntity ;
10
+ import org .orcid .test .TargetProxyHelper ;
11
+
12
+ import java .util .List ;
13
+
14
+ import static org .junit .Assert .assertEquals ;
15
+ import static org .mockito .ArgumentMatchers .eq ;
16
+ import static org .mockito .Mockito .*;
17
+
18
+ public class ProfileInterstitialFlagManagerTest {
19
+ @ Mock
20
+ private ProfileInterstitialFlagDao profileInterstitialFlagDao ;
21
+
22
+ @ Mock
23
+ private ProfileInterstitialFlagDao profileInterstitialFlagDaoReadOnly ;
24
+
25
+ ProfileInterstitialFlagManager pifm = new ProfileInterstitialFlagManagerImpl ();
26
+
27
+
28
+ private static final String ORCID = "0000-0000-0000-0001" ;
29
+ private static final String ORCID_TWO = "0000-0000-0000-0002" ;
30
+ private static final String INTERSTITIAL_FLAG = "DOMAIN_INTERSTITIAL" ;
31
+ private static final String INTERSTITIAL_FLAG_TWO = "AFFILIATION_INTERSTITIAL" ;
32
+
33
+
34
+ @ Before
35
+ public void before () {
36
+ MockitoAnnotations .initMocks (this );
37
+ TargetProxyHelper .injectIntoProxy (pifm , "profileInterstitialFlagDao" , profileInterstitialFlagDao );
38
+ TargetProxyHelper .injectIntoProxy (pifm , "profileInterstitialFlagDaoReadOnly" , profileInterstitialFlagDaoReadOnly );
39
+
40
+ ProfileInterstitialFlagEntity pif1 = new ProfileInterstitialFlagEntity ();
41
+ ProfileInterstitialFlagEntity pif2 = new ProfileInterstitialFlagEntity ();
42
+
43
+ pif1 .setInterstitialName (INTERSTITIAL_FLAG );
44
+ pif1 .setOrcid (ORCID );
45
+
46
+ pif2 .setInterstitialName (INTERSTITIAL_FLAG_TWO );
47
+ pif2 .setOrcid (ORCID );
48
+
49
+ when (profileInterstitialFlagDaoReadOnly .findByOrcid (eq (ORCID ))).thenReturn (List .of (pif1 , pif2 ));
50
+ when (profileInterstitialFlagDaoReadOnly .findByOrcid (eq (ORCID_TWO ))).thenReturn (List .of (pif2 ));
51
+ }
52
+
53
+ @ Test (expected = IllegalArgumentException .class )
54
+ public void addFlag_nullOrcid () {
55
+ pifm .addInterstitialFlag (null , INTERSTITIAL_FLAG );
56
+ }
57
+
58
+ @ Test (expected = IllegalArgumentException .class )
59
+ public void addFlag_nullInterstitialName () {
60
+ pifm .addInterstitialFlag (ORCID , null );
61
+ }
62
+
63
+ @ Test
64
+ public void addFlag_success () {
65
+ pifm .addInterstitialFlag (ORCID , INTERSTITIAL_FLAG );
66
+ verify (profileInterstitialFlagDao , times (1 )).addInterstitialFlag (eq (ORCID ), eq (INTERSTITIAL_FLAG ));
67
+ }
68
+
69
+ @ Test
70
+ public void findByOrcid () {
71
+ List <String > flags = pifm .findByOrcid (ORCID );
72
+ assertEquals (flags .size (), 2 );
73
+ assertEquals (flags .get (0 ), INTERSTITIAL_FLAG );
74
+ assertEquals (flags .get (1 ), INTERSTITIAL_FLAG_TWO );
75
+
76
+ List <String > flags2 = pifm .findByOrcid (ORCID_TWO );
77
+ assertEquals (flags2 .size (), 1 );
78
+ assertEquals (flags2 .get (0 ), INTERSTITIAL_FLAG_TWO );
79
+ }
80
+ }
0 commit comments