1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.wysiwyg.server.wiki

File EntityReferenceConverterTest.java

 

Code metrics

0
14
1
1
78
43
1
0.07
14
1
1

Classes

Class Line # Actions
EntityReferenceConverterTest 42 14 0% 1 0
1.0100%
 

Contributing tests

This file is covered by 1 test. .

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.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    * Unit tests for {@link EntityReferenceConverter}.
39    *
40    * @version $Id: 3a71455c2138bd9611d60c45450d8cf7a2568836 $
41    */
 
42    public class EntityReferenceConverterTest
43    {
44    @Rule
45    public MockitoComponentMockingRule<EntityReferenceConverter> mocker = new MockitoComponentMockingRule<>(
46    EntityReferenceConverter.class);
47   
 
48  1 toggle @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    }