| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
|
| 17 |
|
|
| 18 |
|
|
| 19 |
|
|
| 20 |
|
package com.xpn.xwiki.objects; |
| 21 |
|
|
| 22 |
|
import org.junit.Assert; |
| 23 |
|
import org.junit.Before; |
| 24 |
|
import org.junit.Rule; |
| 25 |
|
import org.junit.Test; |
| 26 |
|
import org.xwiki.model.EntityType; |
| 27 |
|
import org.xwiki.model.reference.DocumentReference; |
| 28 |
|
import org.xwiki.model.reference.EntityReference; |
| 29 |
|
|
| 30 |
|
import com.xpn.xwiki.test.MockitoOldcoreRule; |
| 31 |
|
import com.xpn.xwiki.test.reference.ReferenceComponentList; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
@link |
| 35 |
|
|
| 36 |
|
@version |
| 37 |
|
|
| 38 |
|
@ReferenceComponentList |
| |
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 5 |
Complexity Density: 0.19 |
|
| 39 |
|
public class BaseObjectReferenceTest |
| 40 |
|
{ |
| 41 |
|
@Rule |
| 42 |
|
public MockitoOldcoreRule oldcore = new MockitoOldcoreRule(); |
| 43 |
|
|
| 44 |
|
private DocumentReference document; |
| 45 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 46 |
4 |
@Before... |
| 47 |
|
public void before() throws Exception |
| 48 |
|
{ |
| 49 |
4 |
this.document = new DocumentReference("wiki", "space", "page"); |
| 50 |
|
} |
| 51 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 52 |
1 |
@Test... |
| 53 |
|
public void testSerialize() throws Exception |
| 54 |
|
{ |
| 55 |
1 |
BaseObjectReference reference = |
| 56 |
|
new BaseObjectReference(new DocumentReference("wiki", "space", "class"), 42, this.document); |
| 57 |
|
|
| 58 |
1 |
Assert.assertEquals("wiki:space.class[42]", reference.getName()); |
| 59 |
|
|
| 60 |
1 |
reference = new BaseObjectReference(new DocumentReference("wiki", "space", "class"), null, this.document); |
| 61 |
|
|
| 62 |
1 |
Assert.assertEquals("wiki:space.class", reference.getName()); |
| 63 |
|
} |
| 64 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (4) |
Complexity: 1 |
Complexity Density: 0.25 |
1PASS
|
|
| 65 |
1 |
@Test... |
| 66 |
|
public void testSerializeEscape() throws Exception |
| 67 |
|
{ |
| 68 |
1 |
BaseObjectReference reference = |
| 69 |
|
new BaseObjectReference(new DocumentReference("wiki", "space", "class[42]"), null, this.document); |
| 70 |
|
|
| 71 |
1 |
Assert.assertEquals("wiki:space.class\\[42]", reference.getName()); |
| 72 |
|
|
| 73 |
1 |
reference = |
| 74 |
|
new BaseObjectReference(new DocumentReference("wiki", "space", "class\\\\[42]"), null, this.document); |
| 75 |
|
|
| 76 |
1 |
Assert.assertEquals("wiki:space.class\\\\\\\\\\[42]", reference.getName()); |
| 77 |
|
} |
| 78 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (6) |
Complexity: 1 |
Complexity Density: 0.17 |
1PASS
|
|
| 79 |
1 |
@Test... |
| 80 |
|
public void testUnserialize() throws Exception |
| 81 |
|
{ |
| 82 |
1 |
BaseObjectReference reference = |
| 83 |
|
new BaseObjectReference(new EntityReference("wiki:space.class[42]", EntityType.OBJECT, this.document)); |
| 84 |
|
|
| 85 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class"), reference.getXClassReference()); |
| 86 |
1 |
Assert.assertEquals(42, (int) reference.getObjectNumber()); |
| 87 |
|
|
| 88 |
1 |
reference = new BaseObjectReference(new EntityReference("wiki:space.class", EntityType.OBJECT, this.document)); |
| 89 |
|
|
| 90 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class"), reference.getXClassReference()); |
| 91 |
1 |
Assert.assertNull(reference.getObjectNumber()); |
| 92 |
|
} |
| 93 |
|
|
| |
|
| 100% |
Uncovered Elements: 0 (12) |
Complexity: 1 |
Complexity Density: 0.08 |
1PASS
|
|
| 94 |
1 |
@Test... |
| 95 |
|
public void testUnserializeEscape() throws Exception |
| 96 |
|
{ |
| 97 |
1 |
BaseObjectReference reference = |
| 98 |
|
new BaseObjectReference(new EntityReference("wiki:space.class\\[42]", EntityType.OBJECT, this.document)); |
| 99 |
|
|
| 100 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class[42]"), reference.getXClassReference()); |
| 101 |
1 |
Assert.assertNull(reference.getObjectNumber()); |
| 102 |
|
|
| 103 |
1 |
reference = |
| 104 |
|
new BaseObjectReference(new EntityReference("wiki:space.class\\\\[42]", EntityType.OBJECT, this.document)); |
| 105 |
|
|
| 106 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class\\"), reference.getXClassReference()); |
| 107 |
1 |
Assert.assertEquals(42, (int) reference.getObjectNumber()); |
| 108 |
|
|
| 109 |
1 |
reference = |
| 110 |
|
new BaseObjectReference(new EntityReference("wiki:space.class\\\\\\[42]", EntityType.OBJECT, this.document)); |
| 111 |
|
|
| 112 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class\\[42]"), reference.getXClassReference()); |
| 113 |
1 |
Assert.assertNull(reference.getObjectNumber()); |
| 114 |
|
|
| 115 |
1 |
reference = |
| 116 |
|
new BaseObjectReference(new EntityReference("wiki:space.class[word]", EntityType.OBJECT, this.document)); |
| 117 |
|
|
| 118 |
1 |
Assert.assertEquals(new DocumentReference("wiki", "space", "class[word]"), reference.getXClassReference()); |
| 119 |
1 |
Assert.assertNull(reference.getObjectNumber()); |
| 120 |
|
} |
| 121 |
|
} |