| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package org.xwiki.wysiwyg.server.wiki; |
| 21 |
|
|
| 22 |
|
import java.util.Arrays; |
| 23 |
|
|
| 24 |
|
import org.junit.Rule; |
| 25 |
|
import org.junit.Test; |
| 26 |
|
import org.xwiki.gwt.wysiwyg.client.wiki.WikiPageReference; |
| 27 |
|
import org.xwiki.model.reference.AttachmentReference; |
| 28 |
|
import org.xwiki.model.reference.DocumentReference; |
| 29 |
|
import org.xwiki.model.reference.EntityReference; |
| 30 |
|
import org.xwiki.model.reference.EntityReferenceSerializer; |
| 31 |
|
import org.xwiki.model.reference.SpaceReferenceResolver; |
| 32 |
|
import org.xwiki.test.mockito.MockitoComponentMockingRule; |
| 33 |
|
|
| 34 |
|
import static org.junit.Assert.*; |
| 35 |
|
import static org.mockito.Mockito.*; |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
@link |
| 39 |
|
|
| 40 |
|
@version |
| 41 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (15) |
Complexity: 1 |
Complexity Density: 0.07 |
|
| 42 |
|
public class EntityReferenceConverterTest |
| 43 |
|
{ |
| 44 |
|
@Rule |
| 45 |
|
public MockitoComponentMockingRule<EntityReferenceConverter> mocker = new MockitoComponentMockingRule<>( |
| 46 |
|
EntityReferenceConverter.class); |
| 47 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (14) |
Complexity: 1 |
Complexity Density: 0.07 |
1PASS
|
|
| 48 |
1 |
@Test... |
| 49 |
|
public void convert() throws Exception |
| 50 |
|
{ |
| 51 |
1 |
DocumentReference documentReference = new DocumentReference("dev", Arrays.asList("One", "Two"), "Product"); |
| 52 |
1 |
AttachmentReference serverAttachmentReference = new AttachmentReference("logo.png", documentReference); |
| 53 |
|
|
| 54 |
1 |
WikiPageReference wikiPageReference = new WikiPageReference("dev", "One.Two", "Product"); |
| 55 |
1 |
org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference clientAttachmentReference = |
| 56 |
|
new org.xwiki.gwt.wysiwyg.client.wiki.AttachmentReference("logo.png", wikiPageReference); |
| 57 |
|
|
| 58 |
1 |
EntityReferenceSerializer<String> localEntityReferenceSerializer = |
| 59 |
|
this.mocker.getInstance(EntityReferenceSerializer.TYPE_STRING, "local"); |
| 60 |
1 |
when(localEntityReferenceSerializer.serialize(documentReference.getLastSpaceReference())).thenReturn("One.Two"); |
| 61 |
|
|
| 62 |
1 |
SpaceReferenceResolver<String> spaceResolver = this.mocker.getInstance(SpaceReferenceResolver.TYPE_STRING); |
| 63 |
1 |
when(spaceResolver.resolve("One.Two", documentReference.getWikiReference())).thenReturn( |
| 64 |
|
documentReference.getLastSpaceReference()); |
| 65 |
|
|
| 66 |
1 |
assertEquals(clientAttachmentReference, this.mocker.getComponentUnderTest().convert(serverAttachmentReference)); |
| 67 |
1 |
assertEquals(serverAttachmentReference, this.mocker.getComponentUnderTest().convert(clientAttachmentReference)); |
| 68 |
|
|
| 69 |
1 |
assertEquals(serverAttachmentReference, |
| 70 |
|
this.mocker.getComponentUnderTest().convert(clientAttachmentReference.getEntityReference())); |
| 71 |
1 |
assertEquals(clientAttachmentReference.getEntityReference(), |
| 72 |
|
this.mocker.getComponentUnderTest().convert((EntityReference) serverAttachmentReference)); |
| 73 |
|
|
| 74 |
1 |
assertNull(this.mocker.getComponentUnderTest().convert((EntityReference) null)); |
| 75 |
1 |
assertNull(this.mocker.getComponentUnderTest() |
| 76 |
|
.convert((org.xwiki.gwt.wysiwyg.client.wiki.EntityReference) null)); |
| 77 |
|
} |
| 78 |
|
} |