1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.model.internal.reference

File EntityReferenceFactoryTest.java

 

Code metrics

0
17
3
1
81
45
3
0.18
5.67
3
1

Classes

Class Line # Actions
EntityReferenceFactoryTest 39 17 0% 3 0
1.0100%
 

Contributing tests

This file is covered by 3 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.model.internal.reference;
21   
22    import org.junit.jupiter.api.Test;
23    import org.xwiki.model.reference.EntityReference;
24    import org.xwiki.model.reference.PageReference;
25    import org.xwiki.test.junit5.mockito.ComponentTest;
26    import org.xwiki.test.junit5.mockito.InjectMockComponents;
27   
28    import static org.junit.jupiter.api.Assertions.assertEquals;
29    import static org.junit.jupiter.api.Assertions.assertNotSame;
30    import static org.junit.jupiter.api.Assertions.assertNull;
31    import static org.junit.jupiter.api.Assertions.assertSame;
32   
33    /**
34    * Validate {@link EntityReferenceFactory}.
35    *
36    * @version $Id: 32d9cc047ddeec1d8b5bae72d8b72301865471c8 $
37    */
38    @ComponentTest
 
39    public class EntityReferenceFactoryTest
40    {
41    @InjectMockComponents
42    private EntityReferenceFactory factory;
43   
 
44  1 toggle @Test
45    public void getReferenceWhenNull()
46    {
47  1 assertNull(this.factory.getReference(null));
48    }
49   
 
50  1 toggle @Test
51    public void getReference()
52    {
53  1 PageReference page = new PageReference("wiki", "parent", "page");
54  1 PageReference pageClone = new PageReference("wiki", "parent", "page");
55   
56  1 assertSame(page, this.factory.getReference(page));
57  1 assertSame(page, this.factory.getReference(pageClone));
58   
59    // Make sure the parent is cached too
60  1 assertSame(page.getParent(), this.factory.getReference(pageClone.getParent()));
61   
62  1 PageReference page2 = new PageReference("wiki", "parent", "page2");
63   
64  1 PageReference page2Cached = this.factory.getReference(page2);
65  1 assertEquals(page2, page2Cached);
66  1 assertNotSame(page, page2Cached);
67  1 assertSame(page.getParent(), page2Cached.getParent());
68    }
69   
 
70  1 toggle @Test
71    public void getReferenceWhenExistingIsLowerType()
72    {
73  1 PageReference page = new PageReference("wiki", "parent", "page");
74  1 EntityReference entity = new EntityReference(page);
75   
76  1 assertSame(entity, this.factory.getReference(entity));
77  1 assertSame(page, this.factory.getReference(page));
78  1 assertEquals(entity, this.factory.getReference(entity));
79  1 assertNotSame(entity, this.factory.getReference(entity));
80    }
81    }