1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.refactoring.job

File XClassBreakingQuestionTest.java

 

Code metrics

0
41
2
1
110
65
2
0.05
20.5
2
1

Classes

Class Line # Actions
XClassBreakingQuestionTest 43 41 0% 2 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.refactoring.job;
21   
22    import java.util.HashMap;
23    import java.util.HashSet;
24    import java.util.Map;
25    import java.util.Set;
26   
27    import org.junit.jupiter.api.Test;
28    import org.xwiki.model.reference.DocumentReference;
29    import org.xwiki.model.reference.EntityReference;
30    import org.xwiki.model.reference.ObjectReference;
31    import org.xwiki.refactoring.job.question.EntitySelection;
32   
33    import static org.junit.jupiter.api.Assertions.assertEquals;
34    import static org.junit.jupiter.api.Assertions.assertFalse;
35    import static org.junit.jupiter.api.Assertions.assertTrue;
36   
37    /**
38    * Validate the behaviour of {@link XClassBreakingQuestion}
39    *
40    * @since 10.10RC1
41    * @version $Id: c72e1fc27f14dafe3609243e58778f33d2e5c748 $
42    */
 
43    public class XClassBreakingQuestionTest
44    {
 
45  1 toggle @Test
46    public void markImpactedObject()
47    {
48  1 DocumentReference document1 = new DocumentReference("wiki1", "space1", "document1");
49  1 DocumentReference document2 = new DocumentReference("wiki2", "space2", "document2");
50   
51  1 DocumentReference docObjDoc1 = new DocumentReference("wiki1", "space1", "documentObject1");
52  1 DocumentReference docObjDoc2 = new DocumentReference("wiki1", "space1", "documentObject2");
53  1 DocumentReference docObjDoc3 = new DocumentReference("wiki2", "space1", "documentObject3");
54   
55  1 EntitySelection selection1 = new EntitySelection(document1);
56  1 EntitySelection selection2 = new EntitySelection(document2);
57   
58  1 Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
59  1 concernedEntities.put(document1, selection1);
60  1 concernedEntities.put(document2, selection2);
61   
62  1 XClassBreakingQuestion question = new XClassBreakingQuestion(concernedEntities);
63   
64  1 assertTrue(question.getImpactedObjects().isEmpty());
65   
66  1 question.markImpactedObject(selection1, docObjDoc1);
67  1 question.markImpactedObject(selection1, docObjDoc2);
68  1 question.markImpactedObject(selection2, docObjDoc3);
69   
70  1 Map<EntityReference, Set<EntityReference>> expectedImpacted = new HashMap<>();
71  1 HashSet<EntityReference> impact1 = new HashSet<>();
72  1 impact1.add(docObjDoc1);
73  1 impact1.add(docObjDoc2);
74  1 expectedImpacted.put(document1, impact1);
75   
76  1 HashSet<EntityReference> impact2 = new HashSet<>();
77  1 impact2.add(docObjDoc3);
78  1 expectedImpacted.put(document2, impact2);
79   
80  1 assertEquals(expectedImpacted, question.getImpactedObjects());
81    }
82   
 
83  1 toggle @Test
84    public void selectAllFreePages()
85    {
86  1 DocumentReference document1 = new DocumentReference("wiki1", "space1", "document1");
87  1 DocumentReference document2 = new DocumentReference("wiki2", "space2", "document2");
88   
89  1 EntitySelection selection1 = new EntitySelection(document1);
90  1 selection1.setSelected(false);
91  1 EntitySelection selection2 = new EntitySelection(document2);
92  1 selection2.setSelected(false);
93  1 Map<EntityReference, EntitySelection> concernedEntities = new HashMap<>();
94  1 concernedEntities.put(document1, selection1);
95  1 concernedEntities.put(document2, selection2);
96   
97  1 XClassBreakingQuestion question = new XClassBreakingQuestion(concernedEntities);
98   
99  1 question.selectAllFreePages();
100   
101  1 assertFalse(selection1.isSelected());
102  1 assertFalse(selection2.isSelected());
103   
104  1 question.markAsFreePage(selection1);
105  1 question.selectAllFreePages();
106   
107  1 assertTrue(selection1.isSelected());
108  1 assertFalse(selection2.isSelected());
109    }
110    }