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

File VfsResourceReferenceSerializerTest.java

 

Code metrics

0
12
3
1
95
56
3
0.25
4
3
1

Classes

Class Line # Actions
VfsResourceReferenceSerializerTest 47 12 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 org.xwiki.vfs.internal;
21   
22    import java.net.URI;
23    import java.util.Arrays;
24   
25    import javax.inject.Provider;
26   
27    import org.junit.Before;
28    import org.junit.Rule;
29    import org.junit.Test;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.component.util.DefaultParameterizedType;
32    import org.xwiki.resource.ResourceReferenceSerializer;
33    import org.xwiki.test.mockito.MockitoComponentMockingRule;
34    import org.xwiki.url.ExtendedURL;
35    import org.xwiki.url.URLNormalizer;
36    import org.xwiki.vfs.VfsResourceReference;
37   
38    import static org.junit.Assert.assertEquals;
39    import static org.mockito.Mockito.when;
40   
41    /**
42    * Unit tests for {@link VfsResourceReferenceSerializer}.
43    *
44    * @version $Id: 713266964d5b04311242ac98346ce7b86b952145 $
45    * @since 7.4M2
46    */
 
47    public class VfsResourceReferenceSerializerTest
48    {
49    @Rule
50    public MockitoComponentMockingRule<VfsResourceReferenceSerializer> mocker =
51    new MockitoComponentMockingRule<>(VfsResourceReferenceSerializer.class);
52   
 
53  2 toggle @Before
54    public void setUp() throws Exception
55    {
56  2 Provider<ComponentManager> componentManagerProvider = this.mocker.registerMockComponent(
57    new DefaultParameterizedType(null, Provider.class, ComponentManager.class), "context");
58  2 when(componentManagerProvider.get()).thenReturn(this.mocker);
59    }
60   
 
61  1 toggle @Test
62    public void serializeWhenNoSpecificSchemeSerializer() throws Exception
63    {
64  1 VfsResourceReference reference = new VfsResourceReference(
65    URI.create("somescheme:wiki:space.page@attachment"), "path1/path2/test.txt");
66   
67  1 ExtendedURL extendedURL = new ExtendedURL(Arrays.asList(
68    "vfs", "somescheme:wiki:space.page@attachment", "path1", "path2", "test.txt"));
69   
70  1 URLNormalizer<ExtendedURL> normalizer = this.mocker.getInstance(
71    new DefaultParameterizedType(null, URLNormalizer.class, ExtendedURL.class), "contextpath");
72  1 when(normalizer.normalize(extendedURL)).thenReturn(extendedURL);
73   
74  1 assertEquals("/vfs/somescheme%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt",
75    this.mocker.getComponentUnderTest().serialize(reference).toString());
76    }
77   
 
78  1 toggle @Test
79    public void serializeWhenSpecificSchemeSerializer() throws Exception
80    {
81  1 VfsResourceReference reference = new VfsResourceReference(
82    URI.create("attach:attachment"), "path1/path2/test.txt");
83   
84  1 ExtendedURL extendedURL = new ExtendedURL(Arrays.asList(
85    "vfs", "attach:wiki:space.page@attachment", "path1", "path2", "test.txt"));
86   
87  1 ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.registerMockComponent(
88    new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class,
89    ExtendedURL.class), "attach");
90  1 when(serializer.serialize(reference)).thenReturn(extendedURL);
91   
92  1 assertEquals("/vfs/attach%3Awiki%3Aspace.page%40attachment/path1/path2/test.txt",
93    this.mocker.getComponentUnderTest().serialize(reference).toString());
94    }
95    }