1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.platform.wiki.creationjob.internal.steps

File AddUsersStepTest.java

 

Code metrics

0
21
4
1
103
62
5
0.24
5.25
4
1.25

Classes

Class Line # Actions
AddUsersStepTest 44 21 0% 5 0
1.0100%
 

Contributing tests

This file is covered by 3 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.platform.wiki.creationjob.internal.steps;
21   
22    import java.util.ArrayList;
23    import java.util.List;
24   
25    import org.junit.Before;
26    import org.junit.Rule;
27    import org.junit.Test;
28    import org.xwiki.platform.wiki.creationjob.WikiCreationException;
29    import org.xwiki.platform.wiki.creationjob.WikiCreationRequest;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31    import org.xwiki.wiki.user.WikiUserManager;
32    import org.xwiki.wiki.user.WikiUserManagerException;
33   
34    import static org.junit.Assert.assertEquals;
35    import static org.junit.Assert.assertNotNull;
36    import static org.mockito.ArgumentMatchers.any;
37    import static org.mockito.ArgumentMatchers.anyCollection;
38    import static org.mockito.Mockito.doThrow;
39    import static org.mockito.Mockito.verify;
40   
41    /**
42    * @version $Id: a8f25064e903d01e3cac7d3502c8c2015361b535 $
43    */
 
44    public class AddUsersStepTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<AddUsersStep> mocker = new MockitoComponentMockingRule<>(AddUsersStep.class);
48   
49    private WikiUserManager wikiUserManager;
50   
 
51  3 toggle @Before
52    public void setUp() throws Exception
53    {
54  3 wikiUserManager = mocker.getInstance(WikiUserManager.class);
55    }
56   
 
57  1 toggle @Test
58    public void execute() throws Exception
59    {
60  1 WikiCreationRequest request = new WikiCreationRequest();
61  1 request.setWikiId("wikiId");
62  1 List<String> members = new ArrayList<>();
63  1 request.setMembers(members);
64   
65    // Test
66  1 mocker.getComponentUnderTest().execute(request);
67   
68    // Verify
69  1 verify(wikiUserManager).addMembers(members, "wikiId");
70    }
71   
 
72  1 toggle @Test
73    public void executeWhenException() throws Exception
74    {
75  1 WikiCreationRequest request = new WikiCreationRequest();
76  1 request.setWikiId("wikiId");
77  1 List<String> members = new ArrayList<>();
78  1 request.setMembers(members);
79   
80  1 Exception exception = new WikiUserManagerException("Execption in WikiUserManager.");
81  1 doThrow(exception).when(wikiUserManager).addMembers(anyCollection(), any());
82   
83    // Test
84  1 WikiCreationException caughtException = null;
85  1 try {
86  1 mocker.getComponentUnderTest().execute(request);
87    } catch (WikiCreationException e) {
88  1 caughtException = e;
89    }
90   
91    // Verify
92  1 assertNotNull(caughtException);
93  1 assertEquals("Failed to add members to the wiki [wikiId].", caughtException.getMessage());
94  1 assertEquals(exception, caughtException.getCause());
95   
96    }
97   
 
98  1 toggle @Test
99    public void getOrder() throws Exception
100    {
101  1 assertEquals(4000, mocker.getComponentUnderTest().getOrder());
102    }
103    }