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

File DefaultVfsManagerTest.java

 

Code metrics

0
11
2
1
83
48
3
0.27
5.5
2
1.5

Classes

Class Line # Actions
DefaultVfsManagerTest 44 11 0% 3 1
0.923076992.3%
 

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 org.junit.Rule;
26    import org.junit.Test;
27    import org.xwiki.component.util.DefaultParameterizedType;
28    import org.xwiki.resource.ResourceReferenceSerializer;
29    import org.xwiki.resource.SerializeResourceReferenceException;
30    import org.xwiki.test.mockito.MockitoComponentMockingRule;
31    import org.xwiki.url.ExtendedURL;
32    import org.xwiki.vfs.VfsException;
33    import org.xwiki.vfs.VfsResourceReference;
34   
35    import static org.junit.Assert.*;
36    import static org.mockito.Mockito.when;
37   
38    /**
39    * Unit tests for {@link DefaultVfsManager}.
40    *
41    * @version $Id: c163b2ad1677aa22eb5e52a1309a95382986d86f $
42    * @since 7.4M2
43    */
 
44    public class DefaultVfsManagerTest
45    {
46    @Rule
47    public MockitoComponentMockingRule<DefaultVfsManager> mocker =
48    new MockitoComponentMockingRule<>(DefaultVfsManager.class);
49   
 
50  1 toggle @Test
51    public void getURL() throws Exception
52    {
53  1 VfsResourceReference reference = new VfsResourceReference(
54    URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
55   
56  1 ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.getInstance(
57    new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class,
58    ExtendedURL.class));
59  1 when(serializer.serialize(reference)).thenReturn(new ExtendedURL(Arrays.asList("generated", "url")));
60   
61  1 assertEquals("/generated/url", this.mocker.getComponentUnderTest().getURL(reference));
62    }
63   
 
64  1 toggle @Test
65    public void getURLerror() throws Exception
66    {
67  1 VfsResourceReference reference = new VfsResourceReference(
68    URI.create("attach:xwiki:space.page@attachment"), "path1/path2/test.txt");
69   
70  1 ResourceReferenceSerializer<VfsResourceReference, ExtendedURL> serializer = this.mocker.getInstance(
71    new DefaultParameterizedType(null, ResourceReferenceSerializer.class, VfsResourceReference.class,
72    ExtendedURL.class));
73  1 when(serializer.serialize(reference)).thenThrow(new SerializeResourceReferenceException("error"));
74   
75  1 try {
76  1 this.mocker.getComponentUnderTest().getURL(reference);
77  0 fail("Should have thrown an exception");
78    } catch (VfsException expected) {
79  1 assertEquals("Failed to compute URL for [uri = [attach:xwiki:space.page@attachment], "
80    + "path = [path1/path2/test.txt], parameters = []]", expected.getMessage());
81    }
82    }
83    }