1515import com .getcapacitor .JSArray ;
1616import com .getcapacitor .JSObject ;
1717import com .getcapacitor .PluginCall ;
18- import com .microsoft .identity .client .IAccount ;
19- import com .microsoft .identity .client .IAuthenticationResult ;
20- import com .microsoft .identity .client .ISingleAccountPublicClientApplication ;
18+ import com .microsoft .identity .client .*;
2119import com .microsoft .identity .client .exception .MsalException ;
2220import java .io .File ;
2321import java .util .List ;
@@ -59,38 +57,38 @@ class MsAuthPluginTest {
5957 void setUp () throws MsalException , InterruptedException {
6058 reset (mockedContext , mockedActivity , publicClientApplicationFactoryMock , singleAccountPublicClientApplication );
6159
62- when (publicClientApplicationFactoryMock .createSingleAccountPublicClientApplication (any (Context .class ), any (File .class )))
63- .thenReturn (singleAccountPublicClientApplication );
60+ when (publicClientApplicationFactoryMock .createSingleAccountPublicClientApplication (any (Context .class ), any (File .class ))).thenReturn (
61+ singleAccountPublicClientApplication
62+ );
6463
65- plugin =
66- new MsAuthPlugin (publicClientApplicationFactoryMock ) {
67- final Context applicationContext = mock (Context .class );
64+ plugin = new MsAuthPlugin (publicClientApplicationFactoryMock ) {
65+ final Context applicationContext = mock (Context .class );
6866
69- @ Override
70- public Context getContext () {
71- when (mockedContext .getApplicationContext ()).thenReturn (applicationContext );
67+ @ Override
68+ public Context getContext () {
69+ when (mockedContext .getApplicationContext ()).thenReturn (applicationContext );
7270
73- return mockedContext ;
74- }
71+ return mockedContext ;
72+ }
7573
76- @ Override
77- public AppCompatActivity getActivity () {
78- lenient ().when (applicationContext .getPackageName ()).thenReturn ("nl.recognize.project-x" );
79- lenient ().when (mockedActivity .getApplicationContext ()).thenReturn (applicationContext );
74+ @ Override
75+ public AppCompatActivity getActivity () {
76+ lenient ().when (applicationContext .getPackageName ()).thenReturn ("nl.recognize.project-x" );
77+ lenient ().when (mockedActivity .getApplicationContext ()).thenReturn (applicationContext );
8078
81- return mockedActivity ;
82- }
79+ return mockedActivity ;
80+ }
8381
84- @ Override
85- protected String getLogTag () {
86- return "LogTag" ;
87- }
82+ @ Override
83+ protected String getLogTag () {
84+ return "LogTag" ;
85+ }
8886
89- @ Override
90- protected String getAuthorityUrl (ISingleAccountPublicClientApplication context ) {
91- return AUTHORITY_URL ;
92- }
93- };
87+ @ Override
88+ protected String getAuthorityUrl (ISingleAccountPublicClientApplication context ) {
89+ return AUTHORITY_URL ;
90+ }
91+ };
9492 }
9593
9694 @ Test
@@ -103,14 +101,16 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
103101 ID_TOKEN ,
104102 new String [] { "mocked-scope" , "openid" , "profile" }
105103 );
104+ ICurrentAccountResult currentAccountResult = new CurrentAccountResult (result .getAccount (), null , true );
105+ when (singleAccountPublicClientApplication .getCurrentAccount ()).thenReturn (currentAccountResult );
106+
106107 when (
107108 singleAccountPublicClientApplication .acquireTokenSilent (
108109 argThat (
109110 parameters -> parameters .getScopes ().equals (List .of ("mocked-scope" )) && parameters .getAuthority ().equals (AUTHORITY_URL )
110111 )
111112 )
112- )
113- .thenReturn (result );
113+ ).thenReturn (result );
114114
115115 ArgumentCaptor <JSObject > jsObjectCaptor = ArgumentCaptor .forClass (JSObject .class );
116116 doNothing ().when (pluginCallMock ).resolve (jsObjectCaptor .capture ());
@@ -123,31 +123,31 @@ void loginExpectAcquireTokenSilent() throws JSONException, MsalException, Interr
123123 assertEquals ("access-token" , resolve .getString ("accessToken" ));
124124 assertEquals (ID_TOKEN , resolve .getString ("idToken" ));
125125
126- verify (singleAccountPublicClientApplication )
127- .acquireTokenSilent (argThat (parameters -> parameters .getAuthority ().equals (AUTHORITY_URL )));
126+ verify (singleAccountPublicClientApplication ).acquireTokenSilent (
127+ argThat (parameters -> parameters .getAuthority ().equals (AUTHORITY_URL ))
128+ );
128129 }
129130
130131 private void initializePluginCallMockWithDefaults (PluginCall pluginCallMock ) throws JSONException {
131132 when (pluginCallMock .getArray ("scopes" )).thenReturn (new JSArray (new String [] { "mocked-scope" }));
132- when (pluginCallMock .getString (any ()))
133- .thenAnswer (
134- (Answer <String >) invocation -> {
135- switch (invocation .getArgument (0 ).toString ()) {
136- case "clientId" :
137- return CLIENT_ID ;
138- case "domainHint" :
139- return DOMAIN_HINT ;
140- case "tenant" :
141- return TENANT ;
142- case "keyHash" :
143- return KEY_HASH ;
144- case "authorityUrl" :
145- return AUTHORITY_URL ;
146- }
147-
148- return null ;
133+ when (pluginCallMock .getString (any ())).thenAnswer (
134+ (Answer <String >) invocation -> {
135+ switch (invocation .getArgument (0 ).toString ()) {
136+ case "clientId" :
137+ return CLIENT_ID ;
138+ case "domainHint" :
139+ return DOMAIN_HINT ;
140+ case "tenant" :
141+ return TENANT ;
142+ case "keyHash" :
143+ return KEY_HASH ;
144+ case "authorityUrl" :
145+ return AUTHORITY_URL ;
149146 }
150- );
147+
148+ return null ;
149+ }
150+ );
151151 when (pluginCallMock .getString ("authorityType" , AuthorityType .AAD .name ())).thenReturn ("AAD" );
152152 }
153153
0 commit comments