| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 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 |
|
@link |
| 40 |
|
|
| 41 |
|
@version |
| 42 |
|
@since |
| 43 |
|
|
| |
|
| 92.3% |
Uncovered Elements: 1 (13) |
Complexity: 3 |
Complexity Density: 0.27 |
|
| 44 |
|
public class DefaultVfsManagerTest |
| 45 |
|
{ |
| 46 |
|
@Rule |
| 47 |
|
public MockitoComponentMockingRule<DefaultVfsManager> mocker = |
| 48 |
|
new MockitoComponentMockingRule<>(DefaultVfsManager.class); |
| 49 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 50 |
1 |
@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 |
|
|
| |
|
| 85.7% |
Uncovered Elements: 1 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
1PASS
|
|
| 64 |
1 |
@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 |
|
} |