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

File CreateWikiStepTest.java

 

Code metrics

0
24
4
1
107
63
5
0.21
6
4
1.25

Classes

Class Line # Actions
CreateWikiStepTest 41 24 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 org.junit.Before;
23    import org.junit.Rule;
24    import org.junit.Test;
25    import org.xwiki.platform.wiki.creationjob.WikiCreationException;
26    import org.xwiki.platform.wiki.creationjob.WikiCreationRequest;
27    import org.xwiki.test.mockito.MockitoComponentMockingRule;
28    import org.xwiki.wiki.manager.WikiManager;
29    import org.xwiki.wiki.manager.WikiManagerException;
30   
31    import static org.junit.Assert.assertEquals;
32    import static org.junit.Assert.assertNotNull;
33    import static org.mockito.ArgumentMatchers.any;
34    import static org.mockito.ArgumentMatchers.anyBoolean;
35    import static org.mockito.Mockito.doThrow;
36    import static org.mockito.Mockito.verify;
37   
38    /**
39    * @version $Id: 585df160ed4e9ceb8272852769b22c80415254df $
40    */
 
41    public class CreateWikiStepTest
42    {
43    @Rule
44    public MockitoComponentMockingRule<CreateWikiStep> mocker = new MockitoComponentMockingRule<>(CreateWikiStep.class);
45   
46    private WikiManager wikiManager;
47   
 
48  3 toggle @Before
49    public void setUp() throws Exception
50    {
51  3 wikiManager = mocker.getInstance(WikiManager.class);
52    }
53   
 
54  1 toggle @Test
55    public void execute() throws Exception
56    {
57  1 WikiCreationRequest request = new WikiCreationRequest();
58  1 request.setWikiId("wikiId");
59  1 request.setAlias("wikiAlias");
60  1 request.setFailOnExist(true);
61   
62    // Test
63  1 mocker.getComponentUnderTest().execute(request);
64   
65    // Verify
66  1 verify(wikiManager).create("wikiId", "wikiAlias", true);
67   
68    // Test 2
69  1 request.setFailOnExist(false);
70  1 mocker.getComponentUnderTest().execute(request);
71   
72    // Verify
73  1 verify(wikiManager).create("wikiId", "wikiAlias", false);
74    }
75   
 
76  1 toggle @Test
77    public void executeWhenException() throws Exception
78    {
79  1 WikiCreationRequest request = new WikiCreationRequest();
80  1 request.setWikiId("wikiId");
81  1 request.setAlias("wikiAlias");
82  1 request.setFailOnExist(true);
83   
84  1 Exception exception = new WikiManagerException("Execption in WikiManager.");
85  1 doThrow(exception).when(wikiManager).create(any(), any(), anyBoolean());
86   
87    // Test
88  1 WikiCreationException caughtException = null;
89  1 try {
90  1 mocker.getComponentUnderTest().execute(request);
91    } catch (WikiCreationException e) {
92  1 caughtException = e;
93    }
94   
95    // Verify
96  1 assertNotNull(caughtException);
97  1 assertEquals("Failed to create the wiki [wikiId].", caughtException.getMessage());
98  1 assertEquals(exception, caughtException.getCause());
99   
100    }
101   
 
102  1 toggle @Test
103    public void getOrder() throws Exception
104    {
105  1 assertEquals(1000, mocker.getComponentUnderTest().getOrder());
106    }
107    }