| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
| 39 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (24) |
Complexity: 7 |
Complexity Density: 0.47 |
|
| 40 |
|
public class DefaultBlogVisibilityUpdaterTest |
| 41 |
|
{ |
| 42 |
|
@Rule |
| 43 |
|
public MockitoComponentMockingRule<DefaultBlogVisibilityUpdater> mocker = |
| 44 |
|
new MockitoComponentMockingRule<>(DefaultBlogVisibilityUpdater.class); |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 3 |
Complexity Density: 0.38 |
|
| 46 |
3 |
private void test(boolean isPublished, boolean isHidden, boolean hiddenExpected) throws Exception... |
| 47 |
|
{ |
| 48 |
|
|
| 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 |
|
|
| 57 |
3 |
mocker.getComponentUnderTest().synchronizeHiddenMetadata(document); |
| 58 |
|
|
| 59 |
|
|
| 60 |
3 |
verify(document).setHidden(hiddenExpected); |
| 61 |
|
} |
| 62 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 63 |
1 |
@Test... |
| 64 |
|
public void testNonPublishedNotHidden() throws Exception |
| 65 |
|
{ |
| 66 |
1 |
test(false, false, true); |
| 67 |
|
} |
| 68 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 69 |
1 |
@Test... |
| 70 |
|
public void testPublishedNotHidden() throws Exception |
| 71 |
|
{ |
| 72 |
1 |
test(true, false, false); |
| 73 |
|
} |
| 74 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
1PASS
|
|
| 75 |
1 |
@Test... |
| 76 |
|
public void testPublishedAndHidden() throws Exception |
| 77 |
|
{ |
| 78 |
1 |
test(true, true, true); |
| 79 |
|
} |
| 80 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 81 |
1 |
@Test... |
| 82 |
|
public void testWhenNoObject() throws Exception |
| 83 |
|
{ |
| 84 |
|
|
| 85 |
1 |
XWikiDocument document = mock(XWikiDocument.class); |
| 86 |
1 |
when(document.getDocumentReference()).thenReturn(new DocumentReference("chocolate", "Blog", "HelloWorld")); |
| 87 |
|
|
| 88 |
|
|
| 89 |
1 |
mocker.getComponentUnderTest().synchronizeHiddenMetadata(document); |
| 90 |
|
|
| 91 |
|
|
| 92 |
1 |
verify(document, never()).setHidden(anyBoolean()); |
| 93 |
|
} |
| 94 |
|
} |