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

File DefaultBlogVisibilityUpdaterTest.java

 

Code metrics

4
15
5
1
94
53
7
0.47
3
5
1.4

Classes

Class Line # Actions
DefaultBlogVisibilityUpdaterTest 40 15 0% 7 0
1.0100%
 

Contributing tests

This file is covered by 4 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.blog.internal;
21   
22    import org.junit.Rule;
23    import org.junit.Test;
24    import org.xwiki.model.reference.DocumentReference;
25    import org.xwiki.test.mockito.MockitoComponentMockingRule;
26   
27    import com.xpn.xwiki.doc.XWikiDocument;
28    import com.xpn.xwiki.objects.BaseObject;
29   
30    import static org.mockito.ArgumentMatchers.anyBoolean;
31    import static org.mockito.ArgumentMatchers.eq;
32    import static org.mockito.Mockito.mock;
33    import static org.mockito.Mockito.never;
34    import static org.mockito.Mockito.verify;
35    import static org.mockito.Mockito.when;
36   
37    /**
38    * @version $Id: e8456168bcf2ed9c9390d3e522234d1c1d846a96 $
39    */
 
40    public class DefaultBlogVisibilityUpdaterTest
41    {
42    @Rule
43    public MockitoComponentMockingRule<DefaultBlogVisibilityUpdater> mocker =
44    new MockitoComponentMockingRule<>(DefaultBlogVisibilityUpdater.class);
45   
 
46  3 toggle private void test(boolean isPublished, boolean isHidden, boolean hiddenExpected) throws Exception
47    {
48    // Mock
49  3 XWikiDocument document = mock(XWikiDocument.class);
50  3 when(document.getDocumentReference()).thenReturn(new DocumentReference("chocolate", "Blog", "HelloWorld"));
51  3 BaseObject object = mock(BaseObject.class);
52  3 when(document.getXObject(eq(new DocumentReference("chocolate", "Blog", "BlogPostClass")))).thenReturn(object);
53  3 when(object.getIntValue("published")).thenReturn(isPublished ? 1 : 0);
54  3 when(object.getIntValue("hidden")).thenReturn(isHidden ? 1 : 0);
55   
56    // Test
57  3 mocker.getComponentUnderTest().synchronizeHiddenMetadata(document);
58   
59    // Verify
60  3 verify(document).setHidden(hiddenExpected);
61    }
62   
 
63  1 toggle @Test
64    public void testNonPublishedNotHidden() throws Exception
65    {
66  1 test(false, false, true);
67    }
68   
 
69  1 toggle @Test
70    public void testPublishedNotHidden() throws Exception
71    {
72  1 test(true, false, false);
73    }
74   
 
75  1 toggle @Test
76    public void testPublishedAndHidden() throws Exception
77    {
78  1 test(true, true, true);
79    }
80   
 
81  1 toggle @Test
82    public void testWhenNoObject() throws Exception
83    {
84    // Mock
85  1 XWikiDocument document = mock(XWikiDocument.class);
86  1 when(document.getDocumentReference()).thenReturn(new DocumentReference("chocolate", "Blog", "HelloWorld"));
87   
88    // Test
89  1 mocker.getComponentUnderTest().synchronizeHiddenMetadata(document);
90   
91    // Verify
92  1 verify(document, never()).setHidden(anyBoolean());
93    }
94    }