1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wiki.user.script

File WikiUserManagerScriptServiceTest.java

 

Code metrics

0
401
71
1
1,246
767
71
0.18
5.65
71
1

Classes

Class Line # Actions
WikiUserManagerScriptServiceTest 69 401 0% 71 0
1.0100%
 

Contributing tests

This file is covered by 68 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.wiki.user.script;
21   
22    import java.util.ArrayList;
23    import java.util.Collection;
24   
25    import javax.inject.Provider;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.component.util.DefaultParameterizedType;
31    import org.xwiki.context.Execution;
32    import org.xwiki.context.ExecutionContext;
33    import org.xwiki.model.reference.DocumentReference;
34    import org.xwiki.model.reference.DocumentReferenceResolver;
35    import org.xwiki.model.reference.WikiReference;
36    import org.xwiki.security.authorization.AccessDeniedException;
37    import org.xwiki.security.authorization.AuthorizationManager;
38    import org.xwiki.security.authorization.Right;
39    import org.xwiki.test.mockito.MockitoComponentMockingRule;
40    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
41    import org.xwiki.wiki.user.MemberCandidacy;
42    import org.xwiki.wiki.user.MembershipType;
43    import org.xwiki.wiki.user.UserScope;
44    import org.xwiki.wiki.user.WikiUserManager;
45    import org.xwiki.wiki.user.WikiUserManagerException;
46   
47    import com.xpn.xwiki.XWikiContext;
48    import com.xpn.xwiki.doc.XWikiDocument;
49   
50    import static org.junit.Assert.assertEquals;
51    import static org.junit.Assert.assertFalse;
52    import static org.junit.Assert.assertNotNull;
53    import static org.junit.Assert.assertNull;
54    import static org.junit.Assert.assertTrue;
55    import static org.mockito.ArgumentMatchers.any;
56    import static org.mockito.ArgumentMatchers.eq;
57    import static org.mockito.Mockito.doThrow;
58    import static org.mockito.Mockito.mock;
59    import static org.mockito.Mockito.verify;
60    import static org.mockito.Mockito.verifyZeroInteractions;
61    import static org.mockito.Mockito.when;
62   
63    /**
64    * Unit tests for {@link org.xwiki.wiki.user.script.WikiUserManagerScriptService}
65    *
66    * @version $Id: b72b40a7ed358ccdc4d9f2d39c8d520fe0a9b0e9 $
67    * @since 5.4RC1
68    */
 
69    public class WikiUserManagerScriptServiceTest
70    {
71    @Rule
72    public MockitoComponentMockingRule<WikiUserManagerScriptService> mocker =
73    new MockitoComponentMockingRule(WikiUserManagerScriptService.class);
74   
75    private WikiUserManager wikiUserManager;
76   
77    private WikiDescriptorManager wikiDescriptorManager;
78   
79    private AuthorizationManager authorizationManager;
80   
81    private Provider<XWikiContext> xcontextProvider;
82   
83    private DocumentReferenceResolver<String> documentReferenceResolver;
84   
85    private Execution execution;
86   
87    private ExecutionContext executionContext;
88   
89    private XWikiContext xcontext;
90   
91    private XWikiDocument currentDoc;
92   
93    private DocumentReference userDocRef;
94   
 
95  68 toggle @Before
96    public void setUp() throws Exception
97    {
98    // Components mocks
99  68 wikiUserManager = mocker.getInstance(WikiUserManager.class);
100  68 wikiDescriptorManager = mocker.getInstance(WikiDescriptorManager.class);
101  68 authorizationManager = mocker.getInstance(AuthorizationManager.class);
102  68 xcontextProvider = mocker.registerMockComponent(XWikiContext.TYPE_PROVIDER);
103  68 documentReferenceResolver = mocker.getInstance(new DefaultParameterizedType(null,
104    DocumentReferenceResolver.class, String.class));
105  68 execution = mocker.getInstance(Execution.class);
106   
107    // Frequent uses
108  68 xcontext = mock(XWikiContext.class);
109  68 when(xcontextProvider.get()).thenReturn(xcontext);
110  68 when(wikiDescriptorManager.getMainWikiId()).thenReturn("mainWiki");
111  68 when(wikiDescriptorManager.getCurrentWikiId()).thenReturn("subwiki");
112   
113  68 executionContext = new ExecutionContext();
114  68 when(execution.getContext()).thenReturn(executionContext);
115   
116  68 currentDoc = mock(XWikiDocument.class);
117  68 when(xcontext.getDoc()).thenReturn(currentDoc);
118   
119  68 userDocRef = new DocumentReference("mainWiki", "XWiki", "User");
120  68 when(xcontext.getUserReference()).thenReturn(userDocRef);
121   
122  68 DocumentReference userReference = new DocumentReference("mainWiki", "XWiki", "User");
123  68 when(documentReferenceResolver.resolve("mainWiki:XWiki.User")).thenReturn(userReference);
124  68 DocumentReference otherUser = new DocumentReference("mainWiki", "XWiki", "OtherUser");
125  68 when(documentReferenceResolver.resolve("mainWiki:XWiki.OtherUser")).thenReturn(otherUser);
126    }
127   
128    /**
129    * Mocks the components to simulate that a non admin user have saved the current script.
130    *
131    * @return the exception expected when the current script has the not the admin right
132    */
 
133  8 toggle private Exception currentScriptHasNotAdminRight() throws AccessDeniedException
134    {
135  8 DocumentReference authorDocRef = new DocumentReference("mainWiki", "XWiki", "NonAdmin");
136  8 when(currentDoc.getAuthorReference()).thenReturn(authorDocRef);
137   
138  8 DocumentReference currentDocRef = new DocumentReference("subwiki", "Space", "PageToTest");
139  8 when(currentDoc.getDocumentReference()).thenReturn(currentDocRef);
140   
141  8 Exception exception = new AccessDeniedException(Right.ADMIN, authorDocRef, currentDocRef);
142  8 doThrow(exception).when(authorizationManager).checkAccess(Right.ADMIN, authorDocRef, currentDocRef);
143   
144  8 return exception;
145    }
146   
147    /**
148    * Mocks the components to simulate that the current user is not an admin.
149    *
150    * @return the exception expected when the current user has the not the admin right
151    */
 
152  18 toggle private Exception currentUserHasNotAdminRight() throws AccessDeniedException
153    {
154  18 WikiReference wiki = new WikiReference("subwiki");
155  18 Exception exception = new AccessDeniedException(Right.ADMIN, userDocRef, wiki);
156   
157  18 doThrow(exception).when(authorizationManager).checkAccess(eq(Right.ADMIN), eq(userDocRef), eq(wiki));
158   
159  18 return exception;
160    }
161   
 
162  1 toggle @Test
163    public void getUserScope() throws Exception
164    {
165  1 when(wikiUserManager.getUserScope("subwiki")).thenReturn(UserScope.GLOBAL_ONLY);
166  1 UserScope result = mocker.getComponentUnderTest().getUserScope();
167  1 assertEquals(UserScope.GLOBAL_ONLY, result);
168    }
169   
 
170  1 toggle @Test
171    public void getUserScopeWithError() throws Exception
172    {
173    // Mocks
174  1 Exception expectedException = new WikiUserManagerException("Error in getUserScope");
175  1 when(wikiUserManager.getUserScope("test")).thenThrow(expectedException);
176   
177    // Test
178  1 UserScope result = mocker.getComponentUnderTest().getUserScope("test");
179   
180    // Asserts
181  1 assertNull(result);
182  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
183    }
184   
 
185  1 toggle @Test
186    public void setUserScope() throws Exception
187    {
188    // Test
189  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
190   
191    // Asserts
192  1 assertEquals(true, result);
193  1 verify(wikiUserManager).setUserScope(eq("subwiki"), eq(UserScope.LOCAL_ONLY));
194    }
195   
 
196  1 toggle @Test
197    public void setUserScopeWhenScriptHasNoRight() throws Exception
198    {
199    // Mocks
200  1 Exception expectedException = currentScriptHasNotAdminRight();
201   
202    // Test
203  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
204   
205    // Asserts
206  1 assertFalse(result);
207  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
208  1 verifyZeroInteractions(wikiUserManager);
209    }
210   
 
211  1 toggle @Test
212    public void setUserScopeWhenUserHasNoRight() throws Exception
213    {
214    // Mocks
215  1 Exception expectedException = currentUserHasNotAdminRight();
216   
217    // Test
218  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
219   
220    // Asserts
221  1 assertFalse(result);
222  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
223  1 verifyZeroInteractions(wikiUserManager);
224    }
225   
 
226  1 toggle @Test
227    public void setUserScopeWhenWrongValue() throws Exception
228    {
229    // Test
230  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "wrong value");
231   
232    // Asserts
233  1 assertFalse(result);
234  1 assertTrue(mocker.getComponentUnderTest().getLastError() instanceof IllegalArgumentException);
235  1 verifyZeroInteractions(wikiUserManager);
236    }
237   
 
238  1 toggle @Test
239    public void setUserScopeError() throws Exception
240    {
241    // Mocks
242  1 WikiUserManagerException expectedException = new WikiUserManagerException("error in setUserScope");
243  1 doThrow(expectedException).when(wikiUserManager).setUserScope(any(), any(UserScope.class));
244   
245    // Test
246  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
247   
248    // Asserts
249  1 assertFalse(result);
250  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
251    }
252   
 
253  1 toggle @Test
254    public void getMembershipType() throws Exception
255    {
256    // Mocks
257  1 when(wikiUserManager.getMembershipType("subwiki")).thenReturn(MembershipType.INVITE);
258   
259    // Test
260  1 MembershipType result = mocker.getComponentUnderTest().getMembershipType();
261   
262    // Asserts
263  1 assertEquals(MembershipType.INVITE, result);
264    }
265   
 
266  1 toggle @Test
267    public void getMembershipTypeWithError() throws Exception
268    {
269    // Mocks
270  1 Exception expectedException = new WikiUserManagerException("Error in getMembershipType");
271  1 when(wikiUserManager.getMembershipType("test")).thenThrow(expectedException);
272   
273    // Test
274  1 MembershipType result = mocker.getComponentUnderTest().getMembershipType("test");
275   
276    // Asserts
277  1 assertNull(result);
278  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
279    }
280   
 
281  1 toggle @Test
282    public void setMembershipType() throws Exception
283    {
284    // Test
285  1 boolean result = mocker.getComponentUnderTest().setUserScope("subwiki", "LOCAL_ONLY");
286   
287    // Asserts
288  1 assertTrue(result);
289    }
290   
 
291  1 toggle @Test
292    public void setMembershipTypeWhenScriptHasNoRight() throws Exception
293    {
294    // Mocks
295  1 Exception expectedException = currentScriptHasNotAdminRight();
296   
297    // Test
298  1 boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE");
299   
300    // Asserts
301  1 assertFalse(result);
302  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
303  1 verifyZeroInteractions(wikiUserManager);
304    }
305   
 
306  1 toggle @Test
307    public void setMembershipTypeWhenUserHasNoRight() throws Exception
308    {
309    // Mocks
310  1 Exception expectedExtension = currentUserHasNotAdminRight();
311   
312    // Test
313  1 boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE");
314   
315    // Asserts
316  1 assertFalse(result);
317  1 assertEquals(expectedExtension, mocker.getComponentUnderTest().getLastError());
318  1 verifyZeroInteractions(wikiUserManager);
319    }
320   
 
321  1 toggle @Test
322    public void setMembershipTypeWrongValue() throws Exception
323    {
324    // Test
325  1 boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "wrong value");
326   
327    // Asserts
328  1 assertEquals(false, result);
329  1 assertTrue(mocker.getComponentUnderTest().getLastError() instanceof IllegalArgumentException);
330  1 verifyZeroInteractions(wikiUserManager);
331    }
332   
 
333  1 toggle @Test
334    public void setMembershipTypeError() throws Exception
335    {
336    // Mocks
337  1 WikiUserManagerException expectedException = new WikiUserManagerException("error in setMembershipType");
338  1 doThrow(expectedException).when(wikiUserManager).setMembershipType(any(), any(MembershipType.class));
339   
340    // Test
341  1 boolean result = mocker.getComponentUnderTest().setMembershipType("subwiki", "INVITE");
342   
343    // Asserts
344  1 assertEquals(false, result);
345  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
346    }
347   
 
348  1 toggle @Test
349    public void getMembers() throws Exception
350    {
351    // Mocks
352  1 Collection<String> members = new ArrayList<String>();
353  1 when(wikiUserManager.getMembers("subwiki")).thenReturn(members);
354   
355    // Test
356  1 Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki");
357   
358    // Asserts
359  1 assertEquals(members, result);
360    }
361   
 
362  1 toggle @Test
363    public void getMembersError() throws Exception
364    {
365    // Mocks
366  1 Exception expectedException = new WikiUserManagerException("error in getMembers");
367  1 when(wikiUserManager.getMembers("subwiki")).thenThrow(expectedException);
368   
369    // Test
370  1 Collection<String> result = mocker.getComponentUnderTest().getMembers("subwiki");
371   
372    // Asserts
373  1 assertNull(result);
374  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
375    }
376   
 
377  1 toggle @Test
378    public void isMember() throws Exception
379    {
380    // Mocks
381  1 when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki")).thenReturn(true);
382  1 when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki2")).thenReturn(false);
383   
384    // Test
385  1 boolean result1 = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki");
386  1 boolean result2 = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki2");
387   
388    // Asserts
389  1 assertTrue(result1);
390  1 assertFalse(result2);
391    }
392   
 
393  1 toggle @Test
394    public void isMemberError() throws Exception
395    {
396    // Mocks
397  1 Exception expectedException = new WikiUserManagerException("error in isMember");
398  1 when(wikiUserManager.isMember("mainWiki:XWiki.User", "subwiki")).thenThrow(expectedException);
399   
400    // Test
401  1 Boolean result = mocker.getComponentUnderTest().isMember("mainWiki:XWiki.User", "subwiki");
402   
403    // Asserts
404  1 assertNull(result);
405  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
406    }
407   
 
408  1 toggle @Test
409    public void addMember() throws Exception
410    {
411    // Test
412  1 boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki");
413   
414    // Asserts
415  1 assertTrue(result);
416  1 verify(wikiUserManager).addMember("xwiki:XWiki.UserA", "subwiki");
417    }
418   
 
419  1 toggle @Test
420    public void addMemberWhenScriptHasNoRight() throws Exception
421    {
422    // Mocks
423  1 Exception expectedException = currentScriptHasNotAdminRight();
424   
425    // Test
426  1 boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki");
427   
428    // Asserts
429  1 assertEquals(false, result);
430  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
431  1 verifyZeroInteractions(wikiUserManager);
432    }
433   
 
434  1 toggle @Test
435    public void addMemberWhenUserHasNoRight() throws Exception
436    {
437    // Mocks
438  1 Exception expectedException = currentUserHasNotAdminRight();
439   
440    // Test
441  1 boolean result = mocker.getComponentUnderTest().addMember("xwiki:XWiki.UserA", "subwiki");
442   
443    // Asserts
444  1 assertFalse(result);
445  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
446  1 verifyZeroInteractions(wikiUserManager);
447    }
448   
 
449  1 toggle @Test
450    public void addMembers() throws Exception
451    {
452    // Test
453  1 Collection<String> userIds = new ArrayList<String>();
454  1 boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki");
455   
456    // Asserts
457  1 assertTrue(result);
458  1 verify(wikiUserManager).addMembers(userIds, "subwiki");
459    }
460   
 
461  1 toggle @Test
462    public void addMembersWhenScriptHasNoRight() throws Exception
463    {
464    // Mock
465  1 Exception expectedExtension = currentScriptHasNotAdminRight();
466   
467    // Test
468  1 Collection<String> userIds = new ArrayList<String>();
469  1 boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki");
470   
471    // Asserts
472  1 assertFalse(result);
473  1 assertEquals(expectedExtension, mocker.getComponentUnderTest().getLastError());
474  1 verifyZeroInteractions(wikiUserManager);
475    }
476   
 
477  1 toggle @Test
478    public void addMembersWhenUserHasNoRight() throws Exception
479    {
480    // Mock
481  1 Exception expectedException = currentUserHasNotAdminRight();
482   
483    // Test
484  1 Collection<String> userIds = new ArrayList<String>();
485  1 boolean result = mocker.getComponentUnderTest().addMembers(userIds, "subwiki");
486   
487    // Asserts
488  1 assertFalse(result);
489  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
490  1 verifyZeroInteractions(wikiUserManager);
491    }
492   
 
493  1 toggle @Test
494    public void removeMember() throws Exception
495    {
496    // Test
497  1 boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki");
498   
499    // Asserts
500  1 assertTrue(result);
501  1 verify(wikiUserManager).removeMember("xwiki:XWiki.UserA", "subwiki");
502    }
503   
 
504  1 toggle @Test
505    public void removeMemberWhenScriptHasNoRight() throws Exception
506    {
507    // Mocks
508  1 Exception expectedException = currentScriptHasNotAdminRight();
509   
510    // Test
511  1 boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki");
512   
513    // Asserts
514  1 assertFalse(result);
515  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
516  1 verifyZeroInteractions(wikiUserManager);
517    }
518   
 
519  1 toggle @Test
520    public void removeMemberWhenUserHasNoRight() throws Exception
521    {
522    // Mocks
523  1 Exception expectedException = currentUserHasNotAdminRight();
524   
525    // Test
526  1 boolean result = mocker.getComponentUnderTest().removeMember("xwiki:XWiki.UserA", "subwiki");
527   
528    // Asserts
529  1 assertEquals(false, result);
530  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
531  1 verifyZeroInteractions(wikiUserManager);
532    }
533   
 
534  1 toggle @Test
535    public void getCandidacyAsAdmin() throws Exception
536    {
537    // Mocks
538  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
539    MemberCandidacy.CandidateType.REQUEST);
540  1 candidacy.setId(12);
541  1 candidacy.setAdminPrivateComment("private message");
542  1 when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
543  1 when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef),
544    eq(new WikiReference("subwiki")))).thenReturn(true);
545   
546    // Test
547  1 MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
548   
549    // Asserts
550  1 assertEquals(candidacy, result);
551  1 assertEquals("private message", result.getAdminPrivateComment());
552    }
553   
 
554  1 toggle @Test
555    public void getCandidacyAsUserConcerned() throws Exception
556    {
557    // Mocks
558   
559    // Here, the candidate is the current user
560  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
561    MemberCandidacy.CandidateType.REQUEST);
562  1 candidacy.setId(12);
563  1 candidacy.setAdminPrivateComment("some private message that I should not be able to see");
564   
565  1 when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
566   
567    // Test
568  1 MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
569   
570    // Asserts
571  1 assertEquals(candidacy, result);
572    // Verify that the private message has been removed from the candidacy
573  1 assertNull(candidacy.getAdminPrivateComment());
574    }
575   
 
576  1 toggle @Test
577    public void getCandidacyWhenNoRight() throws Exception
578    {
579    // Mocks
580   
581    // The current user is not the candidate
582  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
583    MemberCandidacy.CandidateType.REQUEST);
584  1 candidacy.setId(12);
585  1 when(wikiUserManager.getCandidacy("subwiki", candidacy.getId())).thenReturn(candidacy);
586   
587    // The current user does not have ADMIN right
588  1 when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef),
589    eq(new WikiReference("subwiki")))).thenReturn(false);
590   
591    // Test
592  1 MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 12);
593   
594    // Asserts
595  1 assertNull(result);
596  1 Exception exception = mocker.getComponentUnderTest().getLastError();
597  1 assertTrue(exception instanceof WikiUserManagerScriptServiceException);
598  1 assertEquals("You are not allowed to see this candidacy.", exception.getMessage());
599    }
600   
 
601  1 toggle @Test
602    public void getCandidacyWhenError() throws Exception
603    {
604    // Mocks
605  1 Exception exception = new WikiUserManagerException("error in getCandidacy");
606  1 when(wikiUserManager.getCandidacy("subwiki", 42)).thenThrow(exception);
607   
608    // Test
609  1 MemberCandidacy result = mocker.getComponentUnderTest().getCandidacy("subwiki", 42);
610   
611    // Asserts
612  1 assertNull(result);
613  1 assertEquals(exception, mocker.getComponentUnderTest().getLastError());
614    }
615   
 
616  1 toggle @Test
617    public void getAllInvitations() throws Exception
618    {
619  1 ArrayList<MemberCandidacy> candidacies = new ArrayList<MemberCandidacy>();
620    // the first candidacy concerns the current user
621  1 candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
622    MemberCandidacy.CandidateType.INVITATION));
623    // not the second
624  1 candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
625    MemberCandidacy.CandidateType.INVITATION));
626  1 candidacies.get(0).setAdminPrivateComment("private message");
627   
628    // We do not have admin rights
629  1 when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef),
630    eq(new WikiReference("subwiki")))).thenReturn(false);
631   
632  1 when(wikiUserManager.getAllInvitations("subwiki")).thenReturn(candidacies);
633   
634    // Test
635  1 Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllInvitations("subwiki");
636   
637    // the result must have been filtered
638  1 assertEquals(1, result.size());
639  1 assertTrue(result.contains(candidacies.get(0)));
640  1 assertFalse(result.contains(candidacies.get(1)));
641    // The private message from the candidacy must be removed
642  1 assertNull(((MemberCandidacy)result.toArray()[0]).getAdminPrivateComment());
643    }
644   
 
645  1 toggle @Test
646    public void getAllInvitationsError() throws Exception
647    {
648    // Mocks
649  1 Exception expectedException = new WikiUserManagerException("error in getAllInvitations()");
650  1 when(wikiUserManager.getAllInvitations("subwiki")).thenThrow(expectedException);
651   
652    // Test
653  1 Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllInvitations("subwiki");
654   
655    // Asserts
656  1 assertNull(result);
657  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
658    }
659   
 
660  1 toggle @Test
661    public void getAllRequests() throws Exception
662    {
663  1 ArrayList<MemberCandidacy> candidacies = new ArrayList<MemberCandidacy>();
664    // the first candidacy concerns the current user
665  1 candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
666    MemberCandidacy.CandidateType.REQUEST));
667    // not the second
668  1 candidacies.add(new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
669    MemberCandidacy.CandidateType.REQUEST));
670  1 candidacies.get(0).setAdminPrivateComment("private message");
671   
672    // We do not have admin rights
673  1 when(authorizationManager.hasAccess(eq(Right.ADMIN), eq(userDocRef),
674    eq(new WikiReference("subwiki")))).thenReturn(false);
675   
676  1 when(wikiUserManager.getAllRequests("subwiki")).thenReturn(candidacies);
677   
678    // Test
679  1 Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("subwiki");
680   
681    // the result must have been filtered
682  1 assertEquals(1, result.size());
683  1 assertTrue(result.contains(candidacies.get(0)));
684  1 assertFalse(result.contains(candidacies.get(1)));
685    // The private message from the candidacy must be removed
686  1 assertNull(((MemberCandidacy)result.toArray()[0]).getAdminPrivateComment());
687    }
688   
 
689  1 toggle @Test
690    public void getAllRequestError() throws Exception
691    {
692    // Mocks
693  1 Exception expectedException = new WikiUserManagerException("error in getAllRequests()");
694  1 when(wikiUserManager.getAllRequests("subwiki")).thenThrow(expectedException);
695   
696    // Test
697  1 Collection<MemberCandidacy> result = mocker.getComponentUnderTest().getAllRequests("subwiki");
698   
699    // Asserts
700  1 assertNull(result);
701  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
702    }
703   
 
704  1 toggle @Test
705    public void join() throws Exception
706    {
707    // Test
708  1 String userId = "mainWiki:XWiki.User";
709  1 String wikiId = "wikiId";
710  1 boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId);
711   
712    // Asserts
713  1 assertTrue(result);
714  1 verify(wikiUserManager).join(userId, wikiId);
715    }
716   
 
717  1 toggle @Test
718    public void joinWhenUserIsNotCurrentUser() throws Exception
719    {
720    // Test
721  1 String userId = "mainWiki:XWiki.OtherUser";
722  1 String wikiId = "wikiId";
723  1 boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId);
724   
725    // Asserts
726  1 assertFalse(result);
727  1 assertEquals("User [mainWiki:XWiki.User] cannot call $services.wiki.user.join() with an other userId.",
728    this.mocker.getComponentUnderTest().getLastError().getMessage());
729  1 verifyZeroInteractions(wikiUserManager);
730    }
731   
 
732  1 toggle @Test
733    public void joinWhenError() throws Exception
734    {
735  1 String userId = "mainWiki:XWiki.User";
736  1 String wikiId = "wikiId";
737   
738    // Mocks
739  1 WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#join()");
740  1 doThrow(expectedException).when(wikiUserManager).join(userId, wikiId);
741   
742    // Test
743  1 boolean result = this.mocker.getComponentUnderTest().join(userId, wikiId);
744   
745    // Asserts
746  1 assertFalse(result);
747  1 assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError());
748    }
749   
 
750  1 toggle @Test
751    public void leave() throws Exception
752    {
753  1 String userId = "mainWiki:XWiki.User";
754  1 String wikiId = "wikiId";
755   
756    // Test
757  1 boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId);
758   
759    // Asserts
760  1 assertTrue(result);
761  1 verify(wikiUserManager).leave(userId, wikiId);
762    }
763   
 
764  1 toggle @Test
765    public void leaveWhenUserIsNotCurrentUser() throws Exception
766    {
767  1 String userId = "mainWiki:XWiki.OtherUser";
768  1 String wikiId = "wikiId";
769   
770    // Test
771  1 boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId);
772   
773    // Asserts
774  1 assertFalse(result);
775  1 assertEquals("User [mainWiki:XWiki.User] cannot call $services.wiki.user.leave() with an other userId.",
776    this.mocker.getComponentUnderTest().getLastError().getMessage());
777  1 verifyZeroInteractions(wikiUserManager);
778    }
779   
 
780  1 toggle @Test
781    public void leaveWhenError() throws Exception
782    {
783  1 String userId = "mainWiki:XWiki.User";
784  1 String wikiId = "wikiId";
785   
786    // Mocks
787  1 WikiUserManagerException expectedException = new WikiUserManagerException("error in wikiUserManager#leave()");
788  1 doThrow(expectedException).when(wikiUserManager).leave(userId, wikiId);
789   
790    // Test
791  1 boolean result = this.mocker.getComponentUnderTest().leave(userId, wikiId);
792   
793    // Asserts
794  1 assertFalse(result);
795  1 assertEquals(expectedException, this.mocker.getComponentUnderTest().getLastError());
796    }
797   
 
798  1 toggle @Test
799    public void hasPendingInvitation() throws Exception
800    {
801  1 String wikiId = "subwiki";
802   
803    // First test
804  1 when(wikiUserManager.hasPendingInvitation(userDocRef, wikiId)).thenReturn(true);
805  1 assertTrue(mocker.getComponentUnderTest().hasPendingInvitation(userDocRef, wikiId));
806   
807    // Second test
808  1 when(wikiUserManager.hasPendingInvitation(userDocRef, wikiId)).thenReturn(false);
809  1 assertFalse(mocker.getComponentUnderTest().hasPendingInvitation(userDocRef, wikiId));
810    }
811   
 
812  1 toggle @Test
813    public void hasPendingInvitationWhenError() throws Exception
814    {
815  1 String wikiId = "subwiki";
816   
817    // Mocks
818  1 DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User");
819  1 Exception expectedException = new WikiUserManagerException("exception");
820  1 doThrow(expectedException).when(wikiUserManager).hasPendingInvitation(userToTest, wikiId);
821   
822    // Test
823  1 Boolean result = mocker.getComponentUnderTest().hasPendingInvitation(userToTest, wikiId);
824   
825    // Asserts
826  1 assertNull(result);
827  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
828    }
829   
 
830  1 toggle @Test
831    public void hasPendingInvitationWhenPageHasNoRight() throws Exception
832    {
833  1 String wikiId = "subwiki";
834  1 DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User");
835   
836    // Mocks
837  1 Exception expectedException = currentScriptHasNotAdminRight();
838   
839    // Test
840  1 Boolean result = mocker.getComponentUnderTest().hasPendingInvitation(userToTest, wikiId);
841   
842    // Asserts
843  1 assertNull(result);
844  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
845  1 verifyZeroInteractions(wikiUserManager);
846    }
847   
 
848  1 toggle @Test
849    public void hasPendingRequest() throws Exception
850    {
851  1 String wikiId = "subwiki";
852   
853    // First test
854  1 when(wikiUserManager.hasPendingRequest(userDocRef, wikiId)).thenReturn(true);
855  1 assertTrue(mocker.getComponentUnderTest().hasPendingRequest(userDocRef, wikiId));
856   
857    // Second test
858  1 when(wikiUserManager.hasPendingRequest(userDocRef, wikiId)).thenReturn(false);
859  1 assertFalse(mocker.getComponentUnderTest().hasPendingRequest(userDocRef, wikiId));
860    }
861   
 
862  1 toggle @Test
863    public void hasPendingRequestWhenError() throws Exception
864    {
865  1 String wikiId = "subwiki";
866  1 DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User");
867   
868    // Mocks
869  1 Exception expectedException = new WikiUserManagerException("exception");
870  1 doThrow(expectedException).when(wikiUserManager).hasPendingRequest(userToTest, wikiId);
871   
872    // Test
873  1 Boolean result = mocker.getComponentUnderTest().hasPendingRequest(userToTest, wikiId);
874   
875    // Asserts
876  1 assertNull(result);
877  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
878   
879    }
880   
 
881  1 toggle @Test
882    public void hasPendingRequestWhenScriptHasNoRight() throws Exception
883    {
884  1 String wikiId = "subwiki";
885  1 DocumentReference userToTest = new DocumentReference("mainWiki", "XWiki", "User");
886   
887    // Mocks
888  1 Exception expectedException = currentScriptHasNotAdminRight();
889   
890    // Test
891  1 Boolean result = mocker.getComponentUnderTest().hasPendingRequest(userToTest, wikiId);
892   
893    // Asserts
894  1 assertNull(result);
895  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
896  1 verifyZeroInteractions(wikiUserManager);
897    }
898   
 
899  1 toggle @Test
900    public void acceptRequest() throws Exception
901    {
902  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
903    MemberCandidacy.CandidateType.INVITATION);
904   
905    // Test
906  1 Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment");
907   
908    // Asserts
909  1 assertTrue(result);
910  1 assertNull(mocker.getComponentUnderTest().getLastError());
911  1 verify(wikiUserManager).acceptRequest(candidacy, "message", "comment");
912    }
913   
 
914  1 toggle @Test
915    public void acceptRequestWhenUserHasNoAdminRight() throws Exception
916    {
917  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
918    MemberCandidacy.CandidateType.INVITATION);
919   
920    // Mocks
921  1 Exception expecyedException = currentUserHasNotAdminRight();
922   
923    // Test
924  1 Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment");
925   
926    // Asserts
927  1 assertFalse(result);
928  1 assertEquals(expecyedException, mocker.getComponentUnderTest().getLastError());
929  1 verifyZeroInteractions(wikiUserManager);
930    }
931   
 
932  1 toggle @Test
933    public void acceptRequestWhenNoAdminRightButConcerned() throws Exception
934    {
935  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
936    MemberCandidacy.CandidateType.INVITATION);
937   
938    // Mocks
939  1 currentUserHasNotAdminRight();
940   
941    // Test
942  1 Boolean result = mocker.getComponentUnderTest().acceptRequest(candidacy, "message", "comment");
943   
944    // Asserts
945  1 assertTrue(result);
946  1 assertNull(mocker.getComponentUnderTest().getLastError());
947  1 verify(wikiUserManager).acceptRequest(candidacy, "message", "comment");
948    }
949   
 
950  1 toggle @Test
951    public void askToJoin() throws Exception
952    {
953    // Mocks
954  1 MemberCandidacy candidacy = new MemberCandidacy();
955  1 when(wikiUserManager.askToJoin("mainWiki:XWiki.User", "subwiki", "please!")).thenReturn(candidacy);
956   
957    // Test
958  1 MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User", "subwiki", "please!");
959   
960    // Asserts
961  1 assertEquals(candidacy, result);
962  1 assertNull(mocker.getComponentUnderTest().getLastError());
963    }
964   
 
965  1 toggle @Test
966    public void askToJoinWhenScriptHasNoRight() throws Exception
967    {
968    // Mocks
969  1 Exception expectedException = currentScriptHasNotAdminRight();
970   
971    // Test
972  1 MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User", "subwiki", "please!");
973   
974    // Asserts
975  1 assertNull(result);
976  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
977  1 verifyZeroInteractions(wikiUserManager);
978    }
979   
 
980  1 toggle @Test
981    public void askToJoinWhenUsertHasNoRight() throws Exception
982    {
983    // Mocks
984  1 Exception expectedException = currentUserHasNotAdminRight();
985   
986    // Test
987  1 MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.OtherUser",
988    "subwiki", "please!");
989   
990    // Asserts
991  1 assertNull(result);
992  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
993  1 verifyZeroInteractions(wikiUserManager);
994    }
995   
 
996  1 toggle @Test
997    public void askToJoinWhenUserHasNoRightButConcerned() throws Exception
998    {
999    // Mocks
1000  1 currentUserHasNotAdminRight();
1001  1 MemberCandidacy candidacy = new MemberCandidacy();
1002  1 when(wikiUserManager.askToJoin("mainWiki:XWiki.User", "subwiki", "please!")).thenReturn(candidacy);
1003   
1004    // Test
1005  1 MemberCandidacy result = mocker.getComponentUnderTest().askToJoin("mainWiki:XWiki.User",
1006    "subwiki", "please!");
1007   
1008    // Asserts
1009  1 assertEquals(candidacy, result);
1010  1 assertNull(mocker.getComponentUnderTest().getLastError());
1011    }
1012   
 
1013  1 toggle @Test
1014    public void refuseRequest() throws Exception
1015    {
1016  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1017    MemberCandidacy.CandidateType.INVITATION);
1018   
1019    // Test
1020  1 Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment");
1021   
1022    // Asserts
1023  1 assertTrue(result);
1024  1 assertNull(mocker.getComponentUnderTest().getLastError());
1025  1 verify(wikiUserManager).refuseRequest(candidacy, "message", "comment");
1026    }
1027   
 
1028  1 toggle @Test
1029    public void refuseRequestWhenUserHasNoAdminRight() throws Exception
1030    {
1031  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
1032    MemberCandidacy.CandidateType.INVITATION);
1033   
1034    // Mocks
1035  1 Exception expectedException = currentUserHasNotAdminRight();
1036   
1037    // Test
1038  1 Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment");
1039   
1040    // Asserts
1041  1 assertFalse(result);
1042  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
1043  1 verifyZeroInteractions(wikiUserManager);
1044    }
1045   
 
1046  1 toggle @Test
1047    public void refuseRequestWhenUserHasNoAdminRightButConcerned() throws Exception
1048    {
1049  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1050    MemberCandidacy.CandidateType.INVITATION);
1051   
1052    // Mocks
1053  1 currentUserHasNotAdminRight();
1054   
1055    // Test
1056  1 Boolean result = mocker.getComponentUnderTest().refuseRequest(candidacy, "message", "comment");
1057   
1058    // Asserts
1059  1 assertTrue(result);
1060  1 assertNull(mocker.getComponentUnderTest().getLastError());
1061  1 verify(wikiUserManager).refuseRequest(candidacy, "message", "comment");
1062    }
1063   
 
1064  1 toggle @Test
1065    public void cancelCandidacy() throws Exception
1066    {
1067  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1068    MemberCandidacy.CandidateType.INVITATION);
1069   
1070    // Test
1071  1 Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy);
1072   
1073    // Asserts
1074  1 assertTrue(result);
1075  1 assertNull(mocker.getComponentUnderTest().getLastError());
1076  1 verify(wikiUserManager).cancelCandidacy(candidacy);
1077   
1078    }
1079   
 
1080  1 toggle @Test
1081    public void cancelCandidacyWhenUserHasNoAdminRight() throws Exception
1082    {
1083  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
1084    MemberCandidacy.CandidateType.INVITATION);
1085   
1086    // Mocks
1087  1 Exception expectedException = currentUserHasNotAdminRight();
1088   
1089    // Test
1090  1 Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy);
1091   
1092    // Asserts
1093  1 assertFalse(result);
1094  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
1095  1 verifyZeroInteractions(wikiUserManager);
1096    }
1097   
 
1098  1 toggle @Test
1099    public void cancelCandidacyWhenUserHasNoAdminRightButConcerned() throws Exception
1100    {
1101  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1102    MemberCandidacy.CandidateType.INVITATION);
1103   
1104    // Mocks
1105  1 currentUserHasNotAdminRight();
1106   
1107    // Test
1108  1 Boolean result = mocker.getComponentUnderTest().cancelCandidacy(candidacy);
1109   
1110    // Asserts
1111  1 assertTrue(result);
1112  1 assertNull(mocker.getComponentUnderTest().getLastError());
1113  1 verify(wikiUserManager).cancelCandidacy(candidacy);
1114    }
1115   
 
1116  1 toggle @Test
1117    public void invite() throws Exception
1118    {
1119    // Mocks
1120  1 when(wikiUserManager.invite(any(), any(), any())).thenReturn(new MemberCandidacy());
1121   
1122    // Test
1123  1 MemberCandidacy result = mocker.getComponentUnderTest().invite("someUser", "subwiki", "someMessage");
1124   
1125    // Asserts
1126  1 assertNotNull(result);
1127    }
1128   
 
1129  1 toggle @Test
1130    public void inviteWhenUserHasNoAdminRight() throws Exception
1131    {
1132    // Mocks
1133  1 Exception expectedException = currentUserHasNotAdminRight();
1134   
1135    // Test
1136  1 MemberCandidacy result = mocker.getComponentUnderTest().invite("someUser", "subwiki", "someMessage");
1137   
1138    // Asserts
1139  1 assertNull(result);
1140  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
1141  1 verifyZeroInteractions(wikiUserManager);
1142    }
1143   
 
1144  1 toggle @Test
1145    public void acceptInvitation() throws Exception
1146    {
1147  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1148    MemberCandidacy.CandidateType.INVITATION);
1149   
1150    // Test
1151  1 Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks");
1152   
1153    // Asserts
1154  1 assertTrue(result);
1155  1 assertNull(mocker.getComponentUnderTest().getLastError());
1156  1 verify(wikiUserManager).acceptInvitation(candidacy, "thanks");
1157    }
1158   
 
1159  1 toggle @Test
1160    public void acceptInvitationWhenUserHasNoAdminRight() throws Exception
1161    {
1162  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
1163    MemberCandidacy.CandidateType.INVITATION);
1164   
1165    // Mocks
1166  1 Exception exception = currentUserHasNotAdminRight();
1167   
1168    // Test
1169  1 Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks");
1170   
1171    // Asserts
1172  1 assertFalse(result);
1173  1 assertEquals(exception, mocker.getComponentUnderTest().getLastError());
1174  1 verifyZeroInteractions(wikiUserManager);
1175    }
1176   
 
1177  1 toggle @Test
1178    public void acceptInvitationWhenUserHasNoAdminRightButConcerned() throws Exception
1179    {
1180  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1181    MemberCandidacy.CandidateType.INVITATION);
1182   
1183    // Mocks
1184  1 currentUserHasNotAdminRight();
1185   
1186    // Test
1187  1 Boolean result = mocker.getComponentUnderTest().acceptInvitation(candidacy, "thanks");
1188   
1189    // Asserts
1190  1 assertTrue(result);
1191  1 assertNull(mocker.getComponentUnderTest().getLastError());
1192  1 verify(wikiUserManager).acceptInvitation(candidacy, "thanks");
1193    }
1194   
 
1195  1 toggle @Test
1196    public void refuseInvitation() throws Exception
1197    {
1198  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1199    MemberCandidacy.CandidateType.INVITATION);
1200   
1201    // Test
1202  1 Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
1203   
1204    // Asserts
1205  1 assertTrue(result);
1206  1 assertNull(mocker.getComponentUnderTest().getLastError());
1207  1 verify(wikiUserManager).refuseInvitation(candidacy, "no thanks");
1208   
1209    }
1210   
 
1211  1 toggle @Test
1212    public void refuseInvitationWhenUserHasNoAdminRight() throws Exception
1213    {
1214  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.OtherUser",
1215    MemberCandidacy.CandidateType.INVITATION);
1216   
1217    // Mocks
1218  1 Exception expectedException = currentUserHasNotAdminRight();
1219   
1220    // Test
1221  1 Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
1222   
1223    // Asserts
1224  1 assertFalse(result);
1225  1 assertEquals(expectedException, mocker.getComponentUnderTest().getLastError());
1226  1 verifyZeroInteractions(wikiUserManager);
1227    }
1228   
 
1229  1 toggle @Test
1230    public void refuseInvitationWhenUserHasNoAdminRightButConcerned() throws Exception
1231    {
1232  1 MemberCandidacy candidacy = new MemberCandidacy("subwiki", "mainWiki:XWiki.User",
1233    MemberCandidacy.CandidateType.INVITATION);
1234   
1235    // Mocks
1236  1 currentUserHasNotAdminRight();
1237   
1238    // Test
1239  1 Boolean result = mocker.getComponentUnderTest().refuseInvitation(candidacy, "no thanks");
1240   
1241    // Asserts
1242  1 assertTrue(result);
1243  1 assertNull(mocker.getComponentUnderTest().getLastError());
1244  1 verify(wikiUserManager).refuseInvitation(candidacy, "no thanks");
1245    }
1246    }