1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package com.xpn.xwiki.store

File XWikiHibernateRecycleBinStoreTest.java

 

Code metrics

0
17
3
1
98
55
3
0.18
5.67
3
1

Classes

Class Line # Actions
XWikiHibernateRecycleBinStoreTest 48 17 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 2 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 com.xpn.xwiki.store;
21   
22    import java.util.Arrays;
23    import java.util.List;
24   
25    import org.hamcrest.object.HasToString;
26    import org.hibernate.Criteria;
27    import org.hibernate.criterion.Order;
28    import org.hibernate.criterion.SimpleExpression;
29    import org.junit.Rule;
30    import org.junit.Test;
31    import org.xwiki.test.mockito.MockitoComponentMockingRule;
32   
33    import com.xpn.xwiki.doc.XWikiDeletedDocument;
34    import com.xpn.xwiki.doc.XWikiDocument;
35   
36    import static org.hamcrest.core.IsEqual.equalTo;
37    import static org.junit.Assert.assertArrayEquals;
38    import static org.mockito.Mockito.mock;
39    import static org.mockito.Mockito.verify;
40    import static org.mockito.Mockito.when;
41    import static org.mockito.hamcrest.MockitoHamcrest.argThat;
42   
43    /**
44    * Unit tests for {@link XWikiHibernateRecycleBinStore}.
45    *
46    * @version $Id: 708ddf476335e281bdccb3e13aec77a2d5a88f73 $
47    */
 
48    public class XWikiHibernateRecycleBinStoreTest extends AbstractXWikiHibernateStoreTest<XWikiRecycleBinStoreInterface>
49    {
50    /**
51    * A special component manager that mocks automatically all dependencies of the component under test.
52    */
53    @Rule
54    public MockitoComponentMockingRule<XWikiRecycleBinStoreInterface> mocker =
55    new MockitoComponentMockingRule<XWikiRecycleBinStoreInterface>(XWikiHibernateRecycleBinStore.class);
56   
 
57  6 toggle @Override
58    protected MockitoComponentMockingRule<XWikiRecycleBinStoreInterface> getMocker()
59    {
60  6 return mocker;
61    }
62   
 
63  1 toggle @Test
64    public void getAllDeletedDocuments() throws Exception
65    {
66  1 XWikiDocument document = mock(XWikiDocument.class);
67  1 when(document.getFullName()).thenReturn("Space.Page");
68  1 when(document.getLanguage()).thenReturn("ro");
69   
70  1 List<XWikiDeletedDocument> deletedVersions =
71    Arrays.asList(mock(XWikiDeletedDocument.class, "v1"), mock(XWikiDeletedDocument.class, "v2"));
72   
73  1 Criteria criteria = mock(Criteria.class);
74  1 when(criteria.list()).thenReturn(deletedVersions);
75  1 when(session.createCriteria(XWikiDeletedDocument.class)).thenReturn(criteria);
76   
77  1 assertArrayEquals(deletedVersions.toArray(new XWikiDeletedDocument[2]), mocker.getComponentUnderTest()
78    .getAllDeletedDocuments(document, context, true));
79   
80    // Too bad the restrictions don't implement equals..
81  1 verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("fullName=Space.Page"))));
82  1 verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("language=ro"))));
83  1 verify(criteria).addOrder(argThat(new HasToString<Order>(equalTo("date desc"))));
84    }
85   
 
86  1 toggle @Test
87    public void getAllDeletedDocumentsWhenLanguageIsEmpty() throws Exception
88    {
89  1 Criteria criteria = mock(Criteria.class);
90  1 when(session.createCriteria(XWikiDeletedDocument.class)).thenReturn(criteria);
91   
92  1 mocker.getComponentUnderTest().getAllDeletedDocuments(mock(XWikiDocument.class), context, true);
93   
94    // Too bad the restrictions don't implement equals..
95  1 verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("fullName=null"))));
96  1 verify(criteria).add(argThat(new HasToString<SimpleExpression>(equalTo("language= or language is null"))));
97    }
98    }